From 3e083cc51b53babdda0862adbe80532ed27467ed Mon Sep 17 00:00:00 2001 From: David Majda Date: Sat, 21 Apr 2012 10:39:31 +0200 Subject: [PATCH] Jasmine: Convert tests of parser's "suffixed" rule --- spec/parser.spec.js | 17 ++++++++++++++++- test/parser-test.js | 8 -------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/spec/parser.spec.js b/spec/parser.spec.js index e3919a4..2beaf6d 100644 --- a/spec/parser.spec.js +++ b/spec/parser.spec.js @@ -1,6 +1,7 @@ describe("PEG.js grammar parser", function() { var trivialGrammar, - literalAbcd = { type: "literal", value: "abcd", ignoreCase: false }; + literalAbcd = { type: "literal", value: "abcd", ignoreCase: false }, + optionalLiteral = { type: "optional", expression: literalAbcd }; function oneRuleGrammar(displayName, expression) { return { @@ -134,6 +135,20 @@ describe("PEG.js grammar parser", function() { }); }); + /* Canonical suffixed is "\"abcd\"?". */ + it("parses suffixed", function() { + expect('start = "abcd"?').toParseAs(oneRuleGrammar(null, optionalLiteral)); + expect('start = "abcd"*').toParseAs(oneRuleGrammar(null, { + type: "zero_or_more", + expression: literalAbcd + })); + expect('start = "abcd"+').toParseAs(oneRuleGrammar(null, { + type: "one_or_more", + expression: literalAbcd + })); + expect('start = "abcd"' ).toParseAs(literalGrammar("abcd")); + }); + /* Canonical primary is "\"abcd\"". */ it("parses primary", function() { expect('start = a' ).toParseAs(ruleRefGrammar("a")); diff --git a/test/parser-test.js b/test/parser-test.js index d28b778..d05ca2e 100644 --- a/test/parser-test.js +++ b/test/parser-test.js @@ -285,12 +285,4 @@ test("parses prefixed", function() { parserParses('start = "abcd"?', oneRuleGrammar(optionalLiteral)); }); -/* Canonical suffixed is "\"abcd\"?". */ -test("parses suffixed", function() { - parserParses('start = "abcd"?', oneRuleGrammar(optionalLiteral)); - parserParses('start = "abcd"*', oneRuleGrammar(zeroOrMore(literalAbcd))); - parserParses('start = "abcd"+', oneRuleGrammar(oneOrMore(literalAbcd))); - parserParses('start = "abcd"', literalGrammar("abcd")); -}); - })();