From b3828919e2b0af03f4cdbd9578f2d03557ccf340 Mon Sep 17 00:00:00 2001 From: David Majda Date: Sat, 24 Jan 2015 20:02:06 +0100 Subject: [PATCH] Behavior specs cleanup: Improve sequence specs --- .../generated-parser-behavior.spec.js | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/spec/behavior/generated-parser-behavior.spec.js b/spec/behavior/generated-parser-behavior.spec.js index 6ff2423..0a0e0dc 100644 --- a/spec/behavior/generated-parser-behavior.spec.js +++ b/spec/behavior/generated-parser-behavior.spec.js @@ -770,16 +770,28 @@ describe("generated parser behavior", function() { }); describe("sequence", function() { - it("matches correctly", function() { - var parser = PEG.buildParser('start = "a" "b" "c"', options); + describe("when all expressions match", function() { + it("returns an array of their match results", function() { + var parser = PEG.buildParser('start = "a" "b" "c"', options); - expect(parser).toParse("abc", ["a", "b", "c"]); + expect(parser).toParse("abc", ["a", "b", "c"]); + }); }); - it("does not advance position on failure", function() { - var parser = PEG.buildParser('start = "a" "b" / "a"', options); + describe("when any expression doesn't match", function() { + it("reports match failure", function() { + var parser = PEG.buildParser('start = "a" "b" "c"', options); - expect(parser).toParse("a", "a"); + expect(parser).toFailToParse("dbc"); + expect(parser).toFailToParse("adc"); + expect(parser).toFailToParse("abd"); + }); + + it("resets parse position", function() { + var parser = PEG.buildParser('start = "a" "b" / "a"', options); + + expect(parser).toParse("a", "a"); + }); }); });