Search in sources :

Example 1 with MutableTruffleString

use of com.oracle.truffle.api.strings.MutableTruffleString in project graal by oracle.

the class TStringCornerCaseTests method testConcatMutable.

@Test
public void testConcatMutable() {
    TruffleString a = TruffleString.Encoding.UTF_8.getEmpty();
    MutableTruffleString b = MutableTruffleString.fromByteArrayUncached(new byte[0], 0, 0, TruffleString.Encoding.BYTES, false);
    Assert.assertTrue(a.concatUncached(b, TruffleString.Encoding.UTF_8, true).isEmpty());
}
Also used : TruffleString(com.oracle.truffle.api.strings.TruffleString) MutableTruffleString(com.oracle.truffle.api.strings.MutableTruffleString) MutableTruffleString(com.oracle.truffle.api.strings.MutableTruffleString) Test(org.junit.Test)

Example 2 with MutableTruffleString

use of com.oracle.truffle.api.strings.MutableTruffleString in project graal by oracle.

the class TStringSwitchEncodingTest method testAll.

@Test
public void testAll() throws Exception {
    EnumSet<TruffleString.Encoding> reducedEncodingSet = EnumSet.allOf(TruffleString.Encoding.class);
    reducedEncodingSet.removeIf(e -> e.name().startsWith("IBM") || e.name().startsWith("Windows") || e.name().startsWith("ISO_8859_"));
    forAllStrings(true, (a, array, codeRange, isValid, encoding, codepoints, byteIndices) -> {
        if (encoding == TruffleString.Encoding.UTF8_SoftBank || encoding == TruffleString.Encoding.CP51932) {
            // https://github.com/jruby/jcodings/issues/42
            return;
        }
        for (TruffleString.Encoding targetEncoding : reducedEncodingSet) {
            TruffleString b = node.execute(a, targetEncoding);
            MutableTruffleString bMutable = nodeMutable.execute(a, targetEncoding);
            if (a instanceof TruffleString && (encoding == targetEncoding || !isDebugStrictEncodingChecks() && codeRange == TruffleString.CodeRange.ASCII && isAsciiCompatible(targetEncoding))) {
                Assert.assertSame(a, b);
            }
            if (a instanceof MutableTruffleString && encoding == targetEncoding) {
                Assert.assertSame(a, bMutable);
            }
            if (isUTF(encoding) && isUTF(targetEncoding) && isValid) {
                assertCodePointsEqual(b, targetEncoding, codepoints);
            }
        }
    });
}
Also used : TruffleString(com.oracle.truffle.api.strings.TruffleString) MutableTruffleString(com.oracle.truffle.api.strings.MutableTruffleString) MutableTruffleString(com.oracle.truffle.api.strings.MutableTruffleString) Test(org.junit.Test)

Example 3 with MutableTruffleString

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

Example 4 with MutableTruffleString

use of com.oracle.truffle.api.strings.MutableTruffleString in project graal by oracle.

the class TStringAsMutableTruffleStringTest method testAll.

@Test
public void testAll() throws Exception {
    forAllStrings(true, (a, array, codeRange, isValid, encoding, codepoints, byteIndices) -> {
        MutableTruffleString b = node.execute(a, encoding);
        if (a instanceof MutableTruffleString) {
            Assert.assertSame(a, b);
        } else {
            b.writeByteUncached(0, (byte) 123, encoding);
            assertBytesEqual(a, encoding, array);
        }
    });
}
Also used : MutableTruffleString(com.oracle.truffle.api.strings.MutableTruffleString) Test(org.junit.Test)

Example 5 with MutableTruffleString

use of com.oracle.truffle.api.strings.MutableTruffleString in project graal by oracle.

the class TStringForceEncodingTest method testAll.

@Test
public void testAll() throws Exception {
    forAllStrings(true, (a, array, codeRange, isValid, encoding, codepoints, byteIndices) -> {
        for (TruffleString.Encoding targetEncoding : TruffleString.Encoding.values()) {
            if (targetEncoding == TruffleString.Encoding.UTF_32 && (array.length & 3) != 0 || targetEncoding == TruffleString.Encoding.UTF_16 && (array.length & 1) != 0) {
                expectIllegalArgumentException(() -> node.execute(a, encoding, targetEncoding));
                expectIllegalArgumentException(() -> nodeMutable.execute(a, encoding, targetEncoding));
            } else {
                TruffleString b = node.execute(a, encoding, targetEncoding);
                MutableTruffleString bMutable = nodeMutable.execute(a, encoding, targetEncoding);
                if (a instanceof MutableTruffleString && encoding == targetEncoding) {
                    Assert.assertSame(a, bMutable);
                }
                assertBytesEqual(b, targetEncoding, array);
                assertBytesEqual(bMutable, targetEncoding, array);
            }
        }
    });
}
Also used : TruffleString(com.oracle.truffle.api.strings.TruffleString) MutableTruffleString(com.oracle.truffle.api.strings.MutableTruffleString) MutableTruffleString(com.oracle.truffle.api.strings.MutableTruffleString) Test(org.junit.Test)

Aggregations

MutableTruffleString (com.oracle.truffle.api.strings.MutableTruffleString)7 Test (org.junit.Test)7 TruffleString (com.oracle.truffle.api.strings.TruffleString)6