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() { test("literals", function() {
var parser = PEG.buildParser('start = "abcd"'); var zeroCharParser = PEG.buildParser('start = ""');
parses(parser, "abcd", "abcd"); parses(zeroCharParser, "", "");
doesNotParse(parser, ""); doesNotParse(zeroCharParser, "a");
doesNotParse(parser, "abc");
doesNotParse(parser, "abcde"); var oneCharParser = PEG.buildParser('start = "a"');
doesNotParse(parser, "efgh"); 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 * Test that the parsing position moves forward after successful parsing of

Loading…
Cancel
Save