use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.
the class JSONScannerTest_scanSymbol method test_1.
public void test_1() throws Exception {
JSONScanner lexer = new JSONScanner("\"value\":\"aa\"},");
long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
Assert.assertEquals(fnv_hash("aa"), hashCode);
Assert.assertEquals(JSONScanner.END, lexer.matchStat());
Assert.assertEquals(JSONToken.COMMA, lexer.token());
}
use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.
the class JSONScannerTest_singQuoteString method test_string2.
public void test_string2() throws Exception {
StringBuilder buf = new StringBuilder();
buf.append('\'');
for (int i = 0; i < 200; ++i) {
buf.append("\\\\\\/\\b\\f\\n\\r\\t\\u" + Integer.toHexString('中'));
}
buf.append('\'');
String text = buf.toString();
JSONScanner lexer = new JSONScanner(text.toCharArray(), text.length());
lexer.config(Feature.AllowSingleQuotes, true);
lexer.nextToken();
Assert.assertEquals(0, lexer.pos());
String stringVal = lexer.stringVal();
// Assert.assertEquals("\"\\\\\\/\\b\\f\\n\\r\\t中\"",
// JSON.toJSONString(stringVal));
JSON.toJSONString(stringVal);
}
use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.
the class JSONScannerTest_singQuoteString method test_error_1.
public void test_error_1() throws Exception {
Exception error = null;
try {
JSONScanner lexer = new JSONScanner("'k\\k'");
lexer.config(Feature.AllowSingleQuotes, true);
lexer.nextToken();
Assert.assertEquals(JSONToken.ERROR, lexer.token());
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.
the class JSONScannerTest_singQuoteString method test_string3.
public void test_string3() throws Exception {
StringBuilder buf = new StringBuilder();
buf.append('\'');
for (int i = 0; i < 200; ++i) {
buf.append("abcdefghijklmn012345689ABCDEFG");
}
buf.append('\'');
String text = buf.toString();
JSONScanner lexer = new JSONScanner(text.toCharArray(), text.length());
lexer.config(Feature.AllowSingleQuotes, true);
lexer.nextToken();
Assert.assertEquals(0, lexer.pos());
String stringVal = lexer.stringVal();
// Assert.assertEquals("\"\\\\\\/\\b\\f\\n\\r\\t中\"",
// JSON.toJSONString(stringVal));
JSON.toJSONString(stringVal);
}
use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.
the class JSONScannerTest_symbol method test_12.
public void test_12() throws Exception {
SymbolTable symbolTable = new SymbolTable(512);
JSONScanner lexer = new JSONScanner("\"\\tabcdefghijklmnopqrstuvwxyz01234567890abcdefghijklmnopqrstuvwxyz01234567890abcdefghijklmnopqrstuvwxyz01234567890abcdefghijklmnopqrstuvwxyz01234567890\"");
String symbol = lexer.scanSymbol(symbolTable, '"');
Assert.assertTrue("\tabcdefghijklmnopqrstuvwxyz01234567890abcdefghijklmnopqrstuvwxyz01234567890abcdefghijklmnopqrstuvwxyz01234567890abcdefghijklmnopqrstuvwxyz01234567890" == symbol);
lexer.close();
}
Aggregations