Skip to content

Commit

Permalink
add regression test for unput bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zaach committed Mar 31, 2014
1 parent a057d41 commit 02e6fd0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/regexplexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1000,3 +1000,22 @@ exports["test lexer reject() exception when not in backtracking mode"] = functio
});
};

exports["test yytext state after unput"] = function() {
var dict = {
rules: [
["cat4", "this.unput('4'); return 'CAT';" ],
["4", "return 'NUMBER';" ],
["$", "return 'EOF';"]
]
};

var input = "cat4";

var lexer = new RegExpLexer(dict);
lexer.setInput(input);
assert.equal(lexer.lex(), "CAT");
/*the yytext should be 'cat' since we unput '4' from 'cat4' */
assert.equal(lexer.yytext, "cat");
assert.equal(lexer.lex(), "NUMBER");
assert.equal(lexer.lex(), "EOF");
};

0 comments on commit 02e6fd0

Please sign in to comment.