From 35771e15bcd284d72f963596c026cea748e23895 Mon Sep 17 00:00:00 2001 From: David Majda Date: Fri, 20 Apr 2012 19:50:00 +0200 Subject: [PATCH] Jasmine: Convert tests of parser's "braced" rule --- spec/parser.spec.js | 25 +++++++++++++++++++------ test/parser-test.js | 8 -------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/spec/parser.spec.js b/spec/parser.spec.js index ab59e18..c52bfed 100644 --- a/spec/parser.spec.js +++ b/spec/parser.spec.js @@ -1,5 +1,6 @@ describe("PEG.js grammar parser", function() { - var trivialGrammar; + var trivialGrammar, + literalAbcd = { type: "literal", value: "abcd", ignoreCase: false }; function oneRuleGrammar(displayName, expression) { return { @@ -17,6 +18,14 @@ describe("PEG.js grammar parser", function() { }; } + function actionGrammar(code) { + return oneRuleGrammar(null, { + type: "action", + expression: literalAbcd, + code: code + }); + } + function ruleRefGrammar(name) { return oneRuleGrammar(null, { type: "rule_ref", name: name }); } @@ -125,6 +134,14 @@ describe("PEG.js grammar parser", function() { }); }); + /* Canonical braced is "{ code }". */ + it("parses braced", function() { + expect('start = "abcd" {}' ).toParseAs(actionGrammar("")); + expect('start = "abcd" {a}' ).toParseAs(actionGrammar("a")); + expect('start = "abcd" {{a}}').toParseAs(actionGrammar("{a}")); + expect('start = "abcd" {aaa}').toParseAs(actionGrammar("aaa")); + }); + /* Trivial character rules are not tested. */ /* Canonical identifier is "a". */ @@ -153,11 +170,7 @@ describe("PEG.js grammar parser", function() { /* Canonical string is "\"abcd\"". */ it("parses string", function() { - var grammar = oneRuleGrammar("abcd", { - type: "literal", - value: "abcd", - ignoreCase: false - }); + var grammar = oneRuleGrammar("abcd", literalAbcd); expect('start "abcd" = "abcd"' ).toParseAs(grammar); expect('start \'abcd\' = "abcd"').toParseAs(grammar); diff --git a/test/parser-test.js b/test/parser-test.js index 0bcf836..abc8511 100644 --- a/test/parser-test.js +++ b/test/parser-test.js @@ -307,12 +307,4 @@ test("parses action", function() { parserParses('start = "a" { code }', actionGrammar(" code ")); }); -/* Canonical braced is "{ code }". */ -test("parses braced", function() { - parserParses('start = "a" {}', actionGrammar("")); - parserParses('start = "a" {a}', actionGrammar("a")); - parserParses('start = "a" {{a}}', actionGrammar("{a}")); - parserParses('start = "a" {aaa}', actionGrammar("aaa")); -}); - })();