From 1b0789fbae4046767dacff299b4cfdbff0fb10cd Mon Sep 17 00:00:00 2001 From: David Majda Date: Sun, 22 Apr 2012 16:29:22 +0200 Subject: [PATCH] Jasmine: Convert sequence matching tests --- spec/generated-parser.spec.js | 22 ++++++++++++++++++++++ test/compiler-test.js | 20 -------------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/spec/generated-parser.spec.js b/spec/generated-parser.spec.js index 9a342f5..ed4763b 100644 --- a/spec/generated-parser.spec.js +++ b/spec/generated-parser.spec.js @@ -91,6 +91,28 @@ describe("generated parser", function() { }); }); + describe("sequence matching", function() { + varyAll(function(options) { + it("matches empty sequence correctly", function() { + var parser = PEG.buildParser('start = ', options); + + expect(parser).toParse("", []); + }); + + it("matches non-empty sequence correctly", function() { + var parser = PEG.buildParser('start = "a" "b" "c"', options); + + expect(parser).toParse("abc", ["a", "b", "c"]); + }); + + it("does not advance position on failure", function() { + var parser = PEG.buildParser('start = "a" "b" / "a"', options); + + expect(parser).toParse("a", "a"); + }); + }); + }); + describe("labeled matching", function() { varyAll(function(options) { it("delegates to the expression", function() { diff --git a/test/compiler-test.js b/test/compiler-test.js index 5d9089a..69f9205 100644 --- a/test/compiler-test.js +++ b/test/compiler-test.js @@ -23,26 +23,6 @@ testWithVaryingTrackLineAndColumn("choices", function(options) { doesNotParse(parser, "d"); }); -testWithVaryingTrackLineAndColumn("sequences", function(options) { - var emptySequenceParser = PEG.buildParser('start = ', options); - parses(emptySequenceParser, "", []); - doesNotParse(emptySequenceParser, "abc"); - - var nonEmptySequenceParser = PEG.buildParser('start = "a" "b" "c"', options); - parses(nonEmptySequenceParser, "abc", ["a", "b", "c"]); - doesNotParse(nonEmptySequenceParser, ""); - doesNotParse(nonEmptySequenceParser, "ab"); - doesNotParse(nonEmptySequenceParser, "abcd"); - doesNotParse(nonEmptySequenceParser, "efg"); - - /* - * Test that the parsing position returns after unsuccessful parsing of a - * sequence. - */ - var posTestParser = PEG.buildParser('start = ("a" "b") / "a"', options); - parses(posTestParser, "a", "a"); -}); - testWithVaryingTrackLineAndColumn("initializer", function(options) { var variableInActionParser = PEG.buildParser( '{ a = 42; }; start = "a" { return a; }',