From 88c50a3e3393f67e743b2a0e0c28e33d79a132db Mon Sep 17 00:00:00 2001 From: David Majda Date: Fri, 30 Sep 2011 10:53:12 +0200 Subject: [PATCH] Add tests for zero- and one-char literals We optimize these cases in the emitter so we should better test them. --- test/compiler-test.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test/compiler-test.js b/test/compiler-test.js index 72976d0..4ca27e6 100644 --- a/test/compiler-test.js +++ b/test/compiler-test.js @@ -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