Search in sources :

Example 31 with TruffleString

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));
            }
        }
    });
}
Also used : MutableTruffleString(com.oracle.truffle.api.strings.MutableTruffleString) AbstractTruffleString(com.oracle.truffle.api.strings.AbstractTruffleString) TruffleString(com.oracle.truffle.api.strings.TruffleString) Encoding(org.graalvm.shadowed.org.jcodings.Encoding) Test(org.junit.Test)

Example 32 with TruffleString

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));
    }
}
Also used : TruffleString(com.oracle.truffle.api.strings.TruffleString)

Example 33 with TruffleString

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));
}
Also used : TruffleString(com.oracle.truffle.api.strings.TruffleString) Test(org.junit.Test)

Example 34 with TruffleString

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));
}
Also used : TruffleString(com.oracle.truffle.api.strings.TruffleString) Test(org.junit.Test)

Example 35 with TruffleString

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));
}
Also used : TruffleString(com.oracle.truffle.api.strings.TruffleString) Test(org.junit.Test)

Aggregations

TruffleString (com.oracle.truffle.api.strings.TruffleString)39 Test (org.junit.Test)26 MutableTruffleString (com.oracle.truffle.api.strings.MutableTruffleString)16 AbstractTruffleString (com.oracle.truffle.api.strings.AbstractTruffleString)9 RootCallTarget (com.oracle.truffle.api.RootCallTarget)3 SLExpressionNode (com.oracle.truffle.sl.nodes.SLExpressionNode)3 SLRootNode (com.oracle.truffle.sl.nodes.SLRootNode)3 Encoding (org.graalvm.shadowed.org.jcodings.Encoding)3 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)2 RootNode (com.oracle.truffle.api.nodes.RootNode)2 TruffleStringBuilder (com.oracle.truffle.api.strings.TruffleStringBuilder)2 TruffleStringIterator (com.oracle.truffle.api.strings.TruffleStringIterator)2 SLEvalRootNode (com.oracle.truffle.sl.nodes.SLEvalRootNode)2 SLStringLiteralNode (com.oracle.truffle.sl.nodes.expression.SLStringLiteralNode)2 BigInteger (java.math.BigInteger)2 CallTarget (com.oracle.truffle.api.CallTarget)1 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 Specialization (com.oracle.truffle.api.dsl.Specialization)1 Frame (com.oracle.truffle.api.frame.Frame)1 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)1