Package com.alibaba.fastjson.parser

Examples of com.alibaba.fastjson.parser.JSONScanner


        }
        buf.append('"');

        String text = buf.toString();

        JSONScanner lexer = new JSONScanner(text.toCharArray(), text.length());
        lexer.nextToken();

        Assert.assertEquals(0, lexer.pos());

        lexer.stringVal();
    }
View Full Code Here


        }
        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));

    }
View Full Code Here

        // JSON.toJSONString(stringVal));

    }

    public void test_empty() throws Exception {
        JSONScanner lexer = new JSONScanner("".toCharArray(), 0);
        lexer.nextToken();
        Assert.assertEquals(JSONToken.EOF, lexer.token());
    }
View Full Code Here

        lexer.nextToken();
        Assert.assertEquals(JSONToken.EOF, lexer.token());
    }

    public void test_isWhitespace() throws Exception {
        new JSONScanner("".toCharArray(), 0);
        Assert.assertTrue(JSONScanner.isWhitespace(' '));
        Assert.assertTrue(JSONScanner.isWhitespace('\b'));
        Assert.assertTrue(JSONScanner.isWhitespace('\f'));
        Assert.assertTrue(JSONScanner.isWhitespace('\n'));
        Assert.assertTrue(JSONScanner.isWhitespace('\r'));
View Full Code Here

        Assert.assertTrue(JSONScanner.isWhitespace('\t'));
        Assert.assertFalse(JSONScanner.isWhitespace('k'));
    }

    public void test_error() throws Exception {
        JSONScanner lexer = new JSONScanner("k");
        lexer.nextToken();
        Assert.assertEquals(JSONToken.ERROR, lexer.token());
    }
View Full Code Here

    }

    public void test_error1() throws Exception {
        Exception error = null;
        try {
            JSONScanner lexer = new JSONScanner("\"\\k\"");
            lexer.nextToken();
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
View Full Code Here

        Assert.assertNotNull(error);
    }

    public void f_test_ident() throws Exception {
        {
            JSONScanner lexer = new JSONScanner("ttue");
            lexer.nextToken();
            Assert.assertEquals(JSONToken.IDENTIFIER, lexer.token());
        }
        {
            JSONScanner lexer = new JSONScanner("tree");
            lexer.nextToken();
            Assert.assertEquals(JSONToken.IDENTIFIER, lexer.token());
        }
        {
            JSONScanner lexer = new JSONScanner("truu");
            lexer.nextToken();
            Assert.assertEquals(JSONToken.IDENTIFIER, lexer.token());
        }
        {
            JSONScanner lexer = new JSONScanner("fflse");
            lexer.nextToken();
            Assert.assertEquals(JSONToken.IDENTIFIER, lexer.token());
        }
        {
            JSONScanner lexer = new JSONScanner("nalse");
            lexer.nextToken();
            Assert.assertEquals(JSONToken.IDENTIFIER, lexer.token());
        }
        {
            JSONScanner lexer = new JSONScanner("faase");
            lexer.nextToken();
            Assert.assertEquals(JSONToken.IDENTIFIER, lexer.token());
        }
        {
            JSONScanner lexer = new JSONScanner("falle");
            lexer.nextToken();
            Assert.assertEquals(JSONToken.IDENTIFIER, lexer.token());
        }
        {
            JSONScanner lexer = new JSONScanner("falss");
            lexer.nextToken();
            Assert.assertEquals(JSONToken.IDENTIFIER, lexer.token());
        }
        {
            JSONScanner lexer = new JSONScanner("nnll");
            lexer.nextToken();
            Assert.assertEquals(JSONToken.IDENTIFIER, lexer.token());
        }
        {
            JSONScanner lexer = new JSONScanner("nuul");
            lexer.nextToken();
            Assert.assertEquals(JSONToken.IDENTIFIER, lexer.token());
        }
        {
            JSONScanner lexer = new JSONScanner("nulk");
            lexer.nextToken();
            Assert.assertEquals(JSONToken.IDENTIFIER, lexer.token());
        }
        {
            StringBuilder buf = new StringBuilder();
            buf.append('n');
            for (char ch = 'A'; ch <= 'Z'; ++ch) {
                buf.append(ch);
            }
            for (char ch = 'a'; ch <= 'z'; ++ch) {
                buf.append(ch);
            }
            JSONScanner lexer = new JSONScanner(buf.toString());
            lexer.nextToken();
            Assert.assertEquals(JSONToken.IDENTIFIER, lexer.token());
        }
    }
View Full Code Here

        }
    }

    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());
    }
View Full Code Here

        JSONObject obj = JSON.parseObject(text);
        Assert.assertEquals(0, obj.size());
    }

    public void test_1() throws Exception {
        JSONScanner lexer = new JSONScanner("  ");
        lexer.nextToken();
        Assert.assertTrue(lexer.isEOF());
    }
View Full Code Here

        Assert.assertEquals(new BigInteger(text), lexer.integerValue());
    }

    public void test_big_integer_2() throws Exception {
        String text = Long.MIN_VALUE + "1234";
        JSONScanner lexer = new JSONScanner(text);
        lexer.nextToken();
        Assert.assertEquals(new BigInteger(text), lexer.integerValue());
    }
View Full Code Here

TOP

Related Classes of com.alibaba.fastjson.parser.JSONScanner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.