use of com.oracle.truffle.api.strings.TruffleString in project graal by oracle.
the class TStringWriteByteTest method testAll.
@Test
public void testAll() throws Exception {
byte v = (byte) 0x81;
forAllStrings(true, (a, array, codeRange, isValid, encoding, codepoints, byteIndices) -> {
byte[] modified = Arrays.copyOf(array, array.length);
checkNotifyExternal(MutableTruffleString.fromByteArrayUncached(modified, 0, modified.length, encoding, false), encoding, () -> {
modified[0] = v;
});
PointerObject pointerObject = PointerObject.create(array);
checkNotifyExternal(MutableTruffleString.fromNativePointerUncached(pointerObject, 0, array.length, encoding, false), encoding, () -> {
pointerObject.writeByte(0, v);
});
if (a instanceof MutableTruffleString) {
TruffleString[] immutable = { a.asTruffleStringUncached(encoding), a.substringUncached(0, codepoints.length, encoding, true), a.substringByteIndexUncached(0, array.length, encoding, true), a.concatUncached(TruffleString.fromByteArrayUncached(new byte[0], 0, 0, encoding, false), encoding, true) };
node.execute((MutableTruffleString) a, 0, v, encoding);
assertBytesEqual(a, encoding, modified);
for (TruffleString b : immutable) {
assertBytesEqual(b, encoding, array);
}
} else {
MutableTruffleString[] mutable = { a.asMutableTruffleStringUncached(encoding), MutableTruffleString.SubstringNode.getUncached().execute(a, 0, codepoints.length, encoding), MutableTruffleString.SubstringByteIndexNode.getUncached().execute(a, 0, array.length, encoding), MutableTruffleString.ConcatNode.getUncached().execute(a, TruffleString.fromByteArrayUncached(new byte[0], 0, 0, encoding, false), encoding) };
for (MutableTruffleString b : mutable) {
node.execute(b, 0, v, encoding);
assertBytesEqual(b, encoding, modified);
}
assertBytesEqual(a, encoding, array);
}
});
}
use of com.oracle.truffle.api.strings.TruffleString in project graal by oracle.
the class TStringUTF8Tests method testCodePointLength1.
@Test
public void testCodePointLength1() {
byte[] arr = TStringTestUtil.byteArray(0xf4, 0x90, 0x80, 0x80, 0x7f, 0x7f);
TruffleString a = TruffleString.fromByteArrayUncached(arr, 0, arr.length, UTF_8, false);
a.toString();
Assert.assertEquals(6, a.codePointLengthUncached(UTF_8));
}
use of com.oracle.truffle.api.strings.TruffleString in project graal by oracle.
the class TStringUTF8Tests method testIndexOf4.
@Test
public void testIndexOf4() {
TruffleString a = TruffleString.fromJavaStringUncached("defghiabc", UTF_8);
TruffleString b = TruffleString.fromJavaStringUncached("def", UTF_8);
Assert.assertEquals(-1, a.lastIndexOfStringUncached(b, 9, 1, UTF_8));
}
use of com.oracle.truffle.api.strings.TruffleString in project graal by oracle.
the class TStringUTF8Tests method testIndexOf.
@Test
public void testIndexOf() {
TruffleString s1 = TruffleString.fromJavaStringUncached("aaa", UTF_8);
TruffleString s2 = TruffleString.fromJavaStringUncached("a", UTF_8);
Assert.assertEquals(-1, s1.byteIndexOfStringUncached(s2, 1, 1, UTF_8));
}
use of com.oracle.truffle.api.strings.TruffleString in project graal by oracle.
the class TStringSubstringByteIndexTest method testAll.
@Test
public void testAll() throws Exception {
forAllStrings(true, (a, array, codeRange, isValid, encoding, codepoints, byteIndices) -> {
int end = array.length;
for (int[] bounds : new int[][] { { 0, 0 }, { end, 0 }, { 0, 1 }, { 0, 2 }, { 1, 1 }, { 1, 2 }, { end - 1, 1 }, { end - 2, 2 }, { 0, end - 1 }, { 1, end - 1 }, { 1, end - 2 }, { 0, end } }) {
if (bounds[0] >= 0 && bounds[1] >= 0 && bounds[0] + bounds[1] <= codepoints.length) {
int fromByteIndex = bounds[0] == codepoints.length ? array.length : byteIndices[bounds[0]];
int byteLength = (bounds[0] + bounds[1] == codepoints.length ? array.length : byteIndices[bounds[0] + bounds[1]]) - fromByteIndex;
for (AbstractTruffleString b : new AbstractTruffleString[] { node.execute(a, fromByteIndex, byteLength, encoding, true), node.execute(a, fromByteIndex, byteLength, encoding, false), nodeMutable.execute(a, fromByteIndex, byteLength, encoding) }) {
assertBytesEqual(b, encoding, array, fromByteIndex, byteLength);
if (bounds[1] == codepoints.length && a instanceof TruffleString && b instanceof TruffleString) {
Assert.assertSame(a, b);
} else {
Assert.assertNotSame(a, b);
}
}
}
}
});
}
Aggregations