Search in sources :

Example 6 with Encoding

use of org.graalvm.shadowed.org.jcodings.Encoding 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)

Aggregations

Encoding (org.graalvm.shadowed.org.jcodings.Encoding)6 TruffleString (com.oracle.truffle.api.strings.TruffleString)5 AbstractTruffleString (com.oracle.truffle.api.strings.AbstractTruffleString)3 MutableTruffleString (com.oracle.truffle.api.strings.MutableTruffleString)3 Test (org.junit.Test)3 TruffleStringBuilder (com.oracle.truffle.api.strings.TruffleStringBuilder)1 TruffleStringIterator (com.oracle.truffle.api.strings.TruffleStringIterator)1 EncodingDB (org.graalvm.shadowed.org.jcodings.EncodingDB)1