Code example for PushbackReader

0
 
    private LexerTesterTool() { 
    } 
 
    public static Lexer createLexer(String input) {
        Lexer lex = new Lexer(new PushbackReader(new StringReader(input), input.length()));
        return lex;
    } 
 
    public static String getNextTokenClass(Lexer lex) throws Exception {
        String tclass = lex.next().getClass().getName();
        tclass = tclass.substring(tclass.lastIndexOf('.') + 1);
        return tclass;
    } 
 
    public static void testTokens(String input, String... tokens) throws Exception {
        Lexer lex = createLexer(input);
 
        for (String tok : tokens) {
            String tclass = getNextTokenClass(lex);
            assert tok.equals(tclass) : "Token types should match (" + tok + " != " + tclass + ")";