Search in sources :

Example 6 with TruffleStringBuilder

use of com.oracle.truffle.api.strings.TruffleStringBuilder in project graal by oracle.

the class TStringBuilderAppendStringTest method testAll.

@Test
public void testAll() throws Exception {
    forAllStrings(true, (a, arrayA, codeRangeA, isValidA, encodingA, codepointsA, byteIndicesA) -> {
        forAllStrings(new TruffleString.Encoding[] { encodingA }, true, (b, arrayB, codeRangeB, isValidB, encodingB, codepointsB, byteIndicesB) -> {
            TruffleStringBuilder sb = TruffleStringBuilder.create(encodingA);
            node.execute(sb, a);
            node.execute(sb, b);
            byte[] expected = TStringTestUtil.concat(arrayA, arrayB);
            assertBytesEqual(sb.toStringUncached(), encodingA, expected);
        });
    });
}
Also used : TruffleString(com.oracle.truffle.api.strings.TruffleString) TruffleStringBuilder(com.oracle.truffle.api.strings.TruffleStringBuilder) Test(org.junit.Test)

Example 7 with TruffleStringBuilder

use of com.oracle.truffle.api.strings.TruffleStringBuilder in project graal by oracle.

the class TStringBuilderAppendSubStringTest method testAll.

@Test
public void testAll() throws Exception {
    forAllStrings(true, (a, arrayA, codeRangeA, isValidA, encodingA, codepointsA, byteIndicesA) -> {
        forAllStrings(new TruffleString.Encoding[] { encodingA }, true, (b, arrayB, codeRangeB, isValidB, encodingB, codepointsB, byteIndicesB) -> {
            TruffleStringBuilder sb = TruffleStringBuilder.create(encodingA);
            node.execute(sb, a, 0, arrayA.length);
            int fromByteIndexB = codepointsB.length > 1 ? byteIndicesB[1] : 0;
            int byteLengthB = (codepointsB.length > 2 ? byteIndicesB[codepointsB.length - 1] : arrayB.length) - fromByteIndexB;
            assert byteLengthB > 0;
            node.execute(sb, b, fromByteIndexB, byteLengthB);
            byte[] expected = Arrays.copyOf(arrayA, arrayA.length + byteLengthB);
            System.arraycopy(arrayB, fromByteIndexB, expected, arrayA.length, byteLengthB);
            assertBytesEqual(sb.toStringUncached(), encodingA, expected);
        });
    });
}
Also used : TruffleString(com.oracle.truffle.api.strings.TruffleString) TruffleStringBuilder(com.oracle.truffle.api.strings.TruffleStringBuilder) Test(org.junit.Test)

Example 8 with TruffleStringBuilder

use of com.oracle.truffle.api.strings.TruffleStringBuilder in project graal by oracle.

the class TStringBuilderAppendCharUTF16Test method testAll.

@Test
public void testAll() throws Exception {
    forAllStrings(new TruffleString.Encoding[] { TruffleString.Encoding.UTF_16 }, true, (a, array, codeRange, isValid, encoding, codepoints, byteIndices) -> {
        TruffleStringBuilder sb = TruffleStringBuilder.create(encoding);
        for (int i = 0; i < array.length / 2; i++) {
            node.execute(sb, (char) TStringTestUtil.readValue(array, 1, i));
        }
        checkStringBuilderResult(array, codeRange, isValid, encoding, codepoints, sb);
    });
}
Also used : TruffleString(com.oracle.truffle.api.strings.TruffleString) TruffleStringBuilder(com.oracle.truffle.api.strings.TruffleStringBuilder) Test(org.junit.Test)

Example 9 with TruffleStringBuilder

use of com.oracle.truffle.api.strings.TruffleStringBuilder in project graal by oracle.

the class TStringBuilderAppendLongTest method testAll.

@Test
public void testAll() throws Exception {
    forAllEncodings(encoding -> {
        if (isAsciiCompatible(encoding)) {
            for (long n : new long[] { Long.MIN_VALUE, Long.MIN_VALUE + 1, ((long) Integer.MIN_VALUE) - 1, Integer.MIN_VALUE, Integer.MIN_VALUE + 1, Short.MIN_VALUE, -12345, -1, 0, 1, 12345, Short.MAX_VALUE, Integer.MAX_VALUE - 1, Integer.MAX_VALUE, ((long) Integer.MAX_VALUE) + 1, Long.MAX_VALUE - 1, Long.MAX_VALUE }) {
                String javaString = String.valueOf(n);
                int[] codepoints = TStringTestUtil.toIntArray(javaString);
                byte[] array = TStringTestUtil.asciiArray(encoding, javaString);
                TruffleStringBuilder sb = TruffleStringBuilder.create(encoding);
                node.execute(sb, n);
                checkStringBuilderResult(array, TruffleString.CodeRange.ASCII, true, encoding, codepoints, sb);
            }
        }
    });
}
Also used : TruffleStringBuilder(com.oracle.truffle.api.strings.TruffleStringBuilder) TruffleString(com.oracle.truffle.api.strings.TruffleString) Test(org.junit.Test)

Example 10 with TruffleStringBuilder

use of com.oracle.truffle.api.strings.TruffleStringBuilder in project graal by oracle.

the class TStringBuilderAppendCodePointTest method testAll.

@Test
public void testAll() throws Exception {
    forAllStrings(true, (a, array, codeRange, isValid, encoding, codepoints, byteIndices) -> {
        if (isValid) {
            TruffleStringBuilder sb = TruffleStringBuilder.create(encoding);
            for (int c : codepoints) {
                node.execute(sb, c);
            }
            checkStringBuilderResult(array, codeRange, true, encoding, codepoints, sb);
        }
    });
}
Also used : TruffleStringBuilder(com.oracle.truffle.api.strings.TruffleStringBuilder) Test(org.junit.Test)

Aggregations

TruffleStringBuilder (com.oracle.truffle.api.strings.TruffleStringBuilder)10 Test (org.junit.Test)9 TruffleString (com.oracle.truffle.api.strings.TruffleString)8 CallTarget (com.oracle.truffle.api.CallTarget)1 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 RootCallTarget (com.oracle.truffle.api.RootCallTarget)1 Frame (com.oracle.truffle.api.frame.Frame)1 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)1 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1 AbstractTruffleString (com.oracle.truffle.api.strings.AbstractTruffleString)1 MutableTruffleString (com.oracle.truffle.api.strings.MutableTruffleString)1 TruffleStringIterator (com.oracle.truffle.api.strings.TruffleStringIterator)1 SLEvalRootNode (com.oracle.truffle.sl.nodes.SLEvalRootNode)1 SLRootNode (com.oracle.truffle.sl.nodes.SLRootNode)1 Encoding (org.graalvm.shadowed.org.jcodings.Encoding)1