Search in sources :

Example 6 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class LexerTest 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.nextToken();
    Assert.assertEquals(0, lexer.pos());
    lexer.stringVal();
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner)

Example 7 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class LexerTest method test_big_integer_1.

public void test_big_integer_1() throws Exception {
    String text = Long.MAX_VALUE + "1234";
    JSONScanner lexer = new JSONScanner(text);
    lexer.nextToken();
    Assert.assertEquals(new BigInteger(text), lexer.integerValue());
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner) BigInteger(java.math.BigInteger)

Example 8 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class LexerTest method test_string4.

public void test_string4() throws Exception {
    StringBuilder buf = new StringBuilder();
    buf.append('"');
    for (int i = 0; i < 200; ++i) {
        buf.append("\\tabcdefghijklmn012345689ABCDEFG");
    }
    buf.append('"');
    String text = buf.toString();
    JSONScanner lexer = new JSONScanner(text.toCharArray(), text.length());
    lexer.nextToken();
    Assert.assertEquals(0, lexer.pos());
    lexer.stringVal();
// Assert.assertEquals("\"\\\\\\/\\b\\f\\n\\r\\t中\"",
// JSON.toJSONString(stringVal));
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner)

Example 9 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class LexerTest method test_error.

public void test_error() throws Exception {
    JSONScanner lexer = new JSONScanner("k");
    lexer.nextToken();
    Assert.assertEquals(JSONToken.ERROR, lexer.token());
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner)

Example 10 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class LexerTest 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.nextToken();
    Assert.assertEquals(0, lexer.pos());
    lexer.stringVal();
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner)

Aggregations

JSONScanner (com.alibaba.fastjson.parser.JSONScanner)179 JSONException (com.alibaba.fastjson.JSONException)37 SymbolTable (com.alibaba.fastjson.parser.SymbolTable)15 JSONReader (com.alibaba.fastjson.JSONReader)11 ParseException (java.text.ParseException)5 BigInteger (java.math.BigInteger)3 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 JSONLexer (com.alibaba.fastjson.parser.JSONLexer)2 JSONObject (com.alibaba.fastjson.JSONObject)1 AccessibleObject (java.lang.reflect.AccessibleObject)1 BigDecimal (java.math.BigDecimal)1 AccessControlException (java.security.AccessControlException)1 Calendar (java.util.Calendar)1