use of com.oracle.truffle.api.strings.TruffleString in project graal by oracle.
the class TStringConstructorTests method testFromLong.
@Test
public void testFromLong() throws Exception {
forAllEncodings((TruffleString.Encoding encoding) -> {
for (long l : 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 }) {
if (isAsciiCompatible(encoding)) {
TruffleString eager = fromLongUncached(l, encoding, false);
Assert.assertEquals(l, eager.parseLongUncached());
Assert.assertEquals(l, eager.parseDoubleUncached(), 0);
TruffleString lazy = fromLongUncached(l, encoding, true);
Assert.assertEquals(l, lazy.parseDoubleUncached(), 0);
if ((int) l == l) {
Assert.assertEquals(l, eager.parseIntUncached());
Assert.assertEquals(l, lazy.parseIntUncached());
}
} else {
expectUnsupportedOperationException(() -> fromLongUncached(l, encoding, false));
expectUnsupportedOperationException(() -> fromLongUncached(l, encoding, true));
}
}
});
}
use of com.oracle.truffle.api.strings.TruffleString in project graal by oracle.
the class TStringBasicTests method switchEncodingEquivalentCodePoint.
private static void switchEncodingEquivalentCodePoint(int codepoint, TruffleString.Encoding encodingA, TruffleString stringA, TruffleString.Encoding encodingB) throws Exception {
if (encodingA != TruffleString.Encoding.BYTES && encodingB != TruffleString.Encoding.BYTES) {
TruffleString stringB = stringA.switchEncodingUncached(encodingB);
Assert.assertEquals(codepoint, stringB.codePointAtIndexUncached(0, encodingB));
Assert.assertEquals(codepoint, stringB.switchEncodingUncached(encodingA).codePointAtIndexUncached(0, encodingA));
}
}
use of com.oracle.truffle.api.strings.TruffleString in project graal by oracle.
the class TStringUTF8Tests method testIndexOf6.
@Test
public void testIndexOf6() {
TruffleString ts1 = TruffleString.fromJavaStringUncached("<......\u043c...", UTF_8);
TruffleString ts2 = TruffleString.fromJavaStringUncached("<", UTF_8);
Assert.assertEquals(0, ts1.lastIndexOfStringUncached(ts2, ts1.codePointLengthUncached(UTF_8), 0, UTF_8));
}
use of com.oracle.truffle.api.strings.TruffleString in project graal by oracle.
the class TStringUTF8Tests method testIndexOf3.
@Test
public void testIndexOf3() {
TruffleString a = TruffleString.fromJavaStringUncached("aaa", UTF_8);
TruffleString b = TruffleString.fromJavaStringUncached("baa", UTF_8);
Assert.assertEquals(-1, a.lastIndexOfStringUncached(b, 3, 0, UTF_8));
}
use of com.oracle.truffle.api.strings.TruffleString in project graal by oracle.
the class TStringUTF8Tests method testIndexOf5.
@Test
public void testIndexOf5() {
TruffleString ts1 = TruffleString.fromJavaStringUncached("a\u00A3b\u00A3", UTF_8);
TruffleString ts2 = TruffleString.fromJavaStringUncached("a\u00A3", UTF_8);
Assert.assertEquals(-1, ts1.lastIndexOfStringUncached(ts2, 4, 1, UTF_8));
Assert.assertEquals(-1, ts1.lastByteIndexOfStringUncached(ts2, 6, 1, UTF_8));
}
Aggregations