@Test public void testTokenParsingTokensWithUnquotedBlanks() throws Exception { final String s = " stuff and \tsome\tmore stuff ;"; final CharArrayBuffer raw = createBuffer(s); final ParserCursor cursor = new ParserCursor(0, s.length()); final String result = parser.parseToken(raw, cursor, TokenParser.INIT_BITSET(';')); Assert.assertEquals("stuff and some more stuff", result); }
@Test public void testTokenParsingEscapedQuotes() throws Exception { final String s = "stuff\"\\\"more\\\"\"stuff;"; final CharArrayBuffer raw = createBuffer(s); final ParserCursor cursor = new ParserCursor(0, s.length()); final String result = parser.parseValue(raw, cursor, TokenParser.INIT_BITSET(';')); Assert.assertEquals("stuff\"more\"stuff", result); }
@Test public void testTokenParsingSlashOutsideQuotes() throws Exception { final String s = "stuff\\; more stuff;"; final CharArrayBuffer raw = createBuffer(s); final ParserCursor cursor = new ParserCursor(0, s.length()); final String result = parser.parseValue(raw, cursor, TokenParser.INIT_BITSET(';')); Assert.assertEquals("stuff\\", result); } }
@Test public void testTokenParsingMixedValuesAndQuotedValues2() throws Exception { final String s = "stuff\"more\"stuff;"; final CharArrayBuffer raw = createBuffer(s); final ParserCursor cursor = new ParserCursor(0, s.length()); final String result = parser.parseValue(raw, cursor, TokenParser.INIT_BITSET(';')); Assert.assertEquals("stuffmorestuff", result); }
@Test public void testTokenParsingMixedValuesAndQuotedValues() throws Exception { final String s = " stuff and \" some more \" \"stuff ;"; final CharArrayBuffer raw = createBuffer(s); final ParserCursor cursor = new ParserCursor(0, s.length()); final String result = parser.parseValue(raw, cursor, TokenParser.INIT_BITSET(';')); Assert.assertEquals("stuff and some more stuff ;", result); }
@Test public void testTokenParsingEscapedDelimiter() throws Exception { final String s = "stuff\"\\\"more\\\";\"stuff;"; final CharArrayBuffer raw = createBuffer(s); final ParserCursor cursor = new ParserCursor(0, s.length()); final String result = parser.parseValue(raw, cursor, TokenParser.INIT_BITSET(';')); Assert.assertEquals("stuff\"more\";stuff", result); }
@Test public void testTokenParsingEscapedSlash() throws Exception { final String s = "stuff\"\\\"more\\\";\\\\\"stuff;"; final CharArrayBuffer raw = createBuffer(s); final ParserCursor cursor = new ParserCursor(0, s.length()); final String result = parser.parseValue(raw, cursor, TokenParser.INIT_BITSET(';')); Assert.assertEquals("stuff\"more\";\\stuff", result); }
@Test public void testTokenParsingWithQuotedPairs() throws Exception { final String s = "raw: \"\\\"some\\stuff\\\\\""; final CharArrayBuffer raw = createBuffer(s); final ParserCursor cursor = new ParserCursor(0, s.length()); parser.skipWhiteSpace(raw, cursor); Assert.assertFalse(cursor.atEnd()); Assert.assertEquals(0, cursor.getPos()); final StringBuilder strbuf1 = new StringBuilder(); parser.copyContent(raw, cursor, TokenParser.INIT_BITSET(':'), strbuf1); Assert.assertFalse(cursor.atEnd()); Assert.assertEquals("raw", strbuf1.toString()); Assert.assertEquals(':', raw.charAt(cursor.getPos())); cursor.updatePos(cursor.getPos() + 1); parser.skipWhiteSpace(raw, cursor); Assert.assertFalse(cursor.atEnd()); final StringBuilder strbuf2 = new StringBuilder(); parser.copyQuotedContent(raw, cursor, strbuf2); Assert.assertTrue(cursor.atEnd()); Assert.assertEquals("\"some\\stuff\\", strbuf2.toString()); }
@Test public void testBasicTokenParsing() throws Exception { final String s = " raw: \" some stuff \""; final CharArrayBuffer raw = createBuffer(s); final ParserCursor cursor = new ParserCursor(0, s.length()); parser.skipWhiteSpace(raw, cursor); Assert.assertFalse(cursor.atEnd()); Assert.assertEquals(3, cursor.getPos()); final StringBuilder strbuf1 = new StringBuilder(); parser.copyContent(raw, cursor, TokenParser.INIT_BITSET(':'), strbuf1); Assert.assertFalse(cursor.atEnd()); Assert.assertEquals(6, cursor.getPos()); Assert.assertEquals("raw", strbuf1.toString()); Assert.assertEquals(':', raw.charAt(cursor.getPos())); cursor.updatePos(cursor.getPos() + 1); parser.skipWhiteSpace(raw, cursor); Assert.assertFalse(cursor.atEnd()); Assert.assertEquals(8, cursor.getPos()); final StringBuilder strbuf2 = new StringBuilder(); parser.copyQuotedContent(raw, cursor, strbuf2); Assert.assertTrue(cursor.atEnd()); Assert.assertEquals(" some stuff ", strbuf2.toString()); parser.copyQuotedContent(raw, cursor, strbuf2); Assert.assertTrue(cursor.atEnd()); parser.skipWhiteSpace(raw, cursor); Assert.assertTrue(cursor.atEnd()); }