use of org.antlr.v4.misc.EscapeSequenceParsing.Result in project antlr4 by antlr.
the class TestUTF8CodePointDecoder method decodeLatinByteBufferWritesCodePoint.
@Test
public void decodeLatinByteBufferWritesCodePoint() throws Exception {
UTF8CodePointDecoder decoder = new UTF8CodePointDecoder(CodingErrorAction.REPLACE);
ByteBuffer utf8BytesIn = StandardCharsets.UTF_8.encode("X");
IntBuffer codePointsOut = IntBuffer.allocate(1);
IntBuffer result = decoder.decodeCodePointsFromBuffer(utf8BytesIn, codePointsOut, true);
result.flip();
assertEquals(1, result.remaining());
assertEquals('X', result.get(0));
}
use of org.antlr.v4.misc.EscapeSequenceParsing.Result in project antlr4 by antlr.
the class TestUTF8CodePointDecoder method decodingInvalidLeadInReplaceModeWritesSubstitutionCharacter.
@Test
public void decodingInvalidLeadInReplaceModeWritesSubstitutionCharacter() throws Exception {
UTF8CodePointDecoder decoder = new UTF8CodePointDecoder(CodingErrorAction.REPLACE);
ByteBuffer utf8BytesIn = ByteBuffer.wrap(new byte[] { (byte) 0xF8 });
IntBuffer codePointsOut = IntBuffer.allocate(1);
IntBuffer result = decoder.decodeCodePointsFromBuffer(utf8BytesIn, codePointsOut, true);
result.flip();
assertEquals(1, result.remaining());
assertEquals(0xFFFD, result.get(0));
}
use of org.antlr.v4.misc.EscapeSequenceParsing.Result in project antlr4 by antlr.
the class TestUTF8CodePointDecoder method decodeEmojiByteBufferWritesCodePoint.
@Test
public void decodeEmojiByteBufferWritesCodePoint() throws Exception {
UTF8CodePointDecoder decoder = new UTF8CodePointDecoder(CodingErrorAction.REPLACE);
ByteBuffer utf8BytesIn = StandardCharsets.UTF_8.encode(new StringBuilder().appendCodePoint(0x1F4A9).toString());
IntBuffer codePointsOut = IntBuffer.allocate(1);
IntBuffer result = decoder.decodeCodePointsFromBuffer(utf8BytesIn, codePointsOut, true);
result.flip();
assertEquals(1, result.remaining());
assertEquals(0x1F4A9, result.get(0));
}
use of org.antlr.v4.misc.EscapeSequenceParsing.Result in project antlr4 by antlr.
the class TestUTF8CodePointDecoder method decodeEmptyByteBufferWritesNothing.
@Test
public void decodeEmptyByteBufferWritesNothing() throws Exception {
UTF8CodePointDecoder decoder = new UTF8CodePointDecoder(CodingErrorAction.REPLACE);
ByteBuffer utf8BytesIn = ByteBuffer.allocate(0);
IntBuffer codePointsOut = IntBuffer.allocate(0);
IntBuffer result = decoder.decodeCodePointsFromBuffer(utf8BytesIn, codePointsOut, true);
result.flip();
assertEquals(0, result.remaining());
}
use of org.antlr.v4.misc.EscapeSequenceParsing.Result in project antlr4 by antlr.
the class TestTokenStreamRewriter method testCombineInserts.
@Test
public void testCombineInserts() throws Exception {
LexerGrammar g = new LexerGrammar("lexer grammar T;\n" + "A : 'a';\n" + "B : 'b';\n" + "C : 'c';\n");
String input = "abc";
LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
CommonTokenStream stream = new CommonTokenStream(lexEngine);
stream.fill();
TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
tokens.insertBefore(0, "x");
tokens.insertBefore(0, "y");
String result = tokens.getText();
String expecting = "yxabc";
assertEquals(expecting, result);
}
Aggregations