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);
});
});
}
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);
});
});
}
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);
});
}
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);
}
}
});
}
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);
}
});
}
Aggregations