Add tests for zero- and one-char literals

We optimize these cases in the emitter so we should better test them.
redux
David Majda 13 years ago
parent 1c11e4aaa3
commit 88c50a3e33

@ -186,12 +186,21 @@ test("rule references", function() {
});
test("literals", function() {
var parser = PEG.buildParser('start = "abcd"');
parses(parser, "abcd", "abcd");
doesNotParse(parser, "");
doesNotParse(parser, "abc");
doesNotParse(parser, "abcde");
doesNotParse(parser, "efgh");
var zeroCharParser = PEG.buildParser('start = ""');
parses(zeroCharParser, "", "");
doesNotParse(zeroCharParser, "a");
var oneCharParser = PEG.buildParser('start = "a"');
parses(oneCharParser, "a", "a");
doesNotParse(oneCharParser, "");
doesNotParse(oneCharParser, "b");
var multiCharParser = PEG.buildParser('start = "abcd"');
parses(multiCharParser, "abcd", "abcd");
doesNotParse(multiCharParser, "");
doesNotParse(multiCharParser, "abc");
doesNotParse(multiCharParser, "abcde");
doesNotParse(multiCharParser, "efgh");
/*
* Test that the parsing position moves forward after successful parsing of

Loading…
Cancel
Save