Java 类com.alibaba.fastjson.parser.SymbolTable 实例源码

项目:GitHub    文件:JSONScannerTest_symbol.java   
public void test_0() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"name\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("name".equals(symbol));
    lexer.close();
}
项目:GitHub    文件:JSONScannerTest_symbol.java   
public void test_1() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"nick name\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("nick name".equals(symbol));
    lexer.close();
}
项目:GitHub    文件:JSONScannerTest_symbol.java   
public void test_2() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"nick \\\"name\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("nick \"name" == symbol);
    lexer.close();
}
项目:GitHub    文件:JSONScannerTest_symbol.java   
public void test_3() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"nick \\\\name\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("nick \\name" == symbol);
    lexer.close();
}
项目:GitHub    文件:JSONScannerTest_symbol.java   
public void test_4() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"nick \\/name\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("nick /name" == symbol);
    lexer.close();
}
项目:GitHub    文件:JSONScannerTest_symbol.java   
public void test_5() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"nick \\bname\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("nick \bname" == symbol);
    lexer.close();
}
项目:GitHub    文件:JSONScannerTest_symbol.java   
public void test_6() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"nick \\f name\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("nick \f name" == symbol);
    lexer.close();
}
项目:GitHub    文件:JSONScannerTest_symbol.java   
public void test_7() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"nick \\F name\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("nick \f name" == symbol);
    lexer.close();
}
项目:GitHub    文件:JSONScannerTest_symbol.java   
public void test_8() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"nick \\n name\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("nick \n name" == symbol);
    lexer.close();
}
项目:GitHub    文件:JSONScannerTest_symbol.java   
public void test_9() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"nick \\r name\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("nick \r name" == symbol);
    lexer.close();
}
项目:GitHub    文件:JSONScannerTest_symbol.java   
public void test_10() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"nick \\t name\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("nick \t name" == symbol);
    lexer.close();
}
项目:GitHub    文件:JSONScannerTest_symbol.java   
public void test_11() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"nick \\u4e2d name\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("nick 中 name" == symbol);
    lexer.close();
}
项目:GitHub    文件:JSONScannerTest_symbol.java   
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();
}
项目:GitHub    文件:JSONScannerTest_symbol.java   
public void test_error() throws Exception {
    JSONException error = null;
    try {
        SymbolTable symbolTable = new SymbolTable(512);

        JSONScanner lexer = new JSONScanner("\"nick \\a name\"");
        lexer.scanSymbol(symbolTable, '"');
        lexer.close();
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:JSONScannerTest_symbol.java   
public void test_error_2() throws Exception {
    JSONException error = null;
    try {
        SymbolTable symbolTable = new SymbolTable(512);

        JSONScanner lexer = new JSONScanner("\"name");
        lexer.scanSymbol(symbolTable, '"');
        lexer.close();
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:OOMTest.java   
public void test_oom() throws Exception {

    for (int i = 0; i < 1000 * 1000; ++i) {
        String text = "{\"" + i + "\":0}";
        JSON.parse(text);
    }

    Field field = SymbolTable.class.getDeclaredField("symbols");
    field.setAccessible(true);
    Object[] symbols = (Object[]) field.get(ParserConfig.getGlobalInstance().symbolTable);
    Assert.assertEquals(4096, symbols.length);
}
项目:GitHub    文件:SymbolTableDupTest.java   
private void test2(char[] chars) {
    int hash = SymbolTable.hash(chars, 0, chars.length);
    if (dupHashCodes.contains(hash)) {
        List<String> list = dupList.get(hash);
        if (list == null) {
            list = new ArrayList<String>();
            dupList.put(hash, list);
        }
        list.add(new String(chars));
    }
}
项目:GitHub    文件:SymbolTableDupTest.java   
private void test(char[] chars) {
    int hash = SymbolTable.hash(chars, 0, chars.length);
    Integer count = map.get(hash);
    if (count != null) {
        dupHashCodes.add(hash);
        map.put(hash, count.intValue() + 1);
    } else {
        map.put(hash, 1);
    }
}
项目:GitHub    文件:SymbolTableDupTest.java   
private void test3(char[] chars) {
    int hash = SymbolTable.hash(chars, 0, chars.length);
    if (hash == VALUE) {
        System.out.println(new String(chars));
    }
}