diff --git a/spec/parser.spec.js b/spec/parser.spec.js index cb03c88..560e4ba 100644 --- a/spec/parser.spec.js +++ b/spec/parser.spec.js @@ -1,7 +1,7 @@ describe("PEG.js grammar parser", function() { var trivialGrammar; - function oneRuleGrammar(expression) { + function oneRuleGrammar(displayName, expression) { return { type: "grammar", initializer: null, @@ -9,7 +9,7 @@ describe("PEG.js grammar parser", function() { { type: "rule", name: "start", - displayName: null, + displayName: displayName, expression: expression } ], @@ -18,14 +18,18 @@ describe("PEG.js grammar parser", function() { } function literalGrammar(value) { - return oneRuleGrammar({ type: "literal", value: value, ignoreCase: false }); + return oneRuleGrammar(null, { + type: "literal", + value: value, + ignoreCase: false + }); } function classGrammar(parts, rawText) { var inverted = arguments.length > 2 ? arguments[2] : false, ignoreCase = arguments.length > 3 ? arguments[3] : false; - return oneRuleGrammar({ + return oneRuleGrammar(null, { type: "class", inverted: inverted, ignoreCase: ignoreCase, @@ -115,6 +119,20 @@ describe("PEG.js grammar parser", function() { }); }); + /* Canonical string is "\"abcd\"". */ + it("parses string", function() { + var grammar = oneRuleGrammar("abcd", { + type: "literal", + value: "abcd", + ignoreCase: false + }); + + expect('start "abcd" = "abcd"' ).toParseAs(grammar); + expect('start \'abcd\' = "abcd"').toParseAs(grammar); + + expect('start "abcd"\n= "abcd"').toParseAs(grammar); + }); + /* Canonical doubleQuotedString is "\"abcd\"". */ it("parses doubleQuotedString", function() { expect('start = ""' ).toParseAs(literalGrammar("")); diff --git a/test/parser-test.js b/test/parser-test.js index 953c99d..d655b0a 100644 --- a/test/parser-test.js +++ b/test/parser-test.js @@ -347,12 +347,4 @@ test("parses literal", function() { parserParses('start = "abcd"\n', literalGrammar("abcd")); }); -/* Canonical string is "\"abcd\"". */ -test("parses string", function() { - parserParses('start "abcd" = "abcd"', namedRuleGrammar); - parserParses('start \'abcd\' = "abcd"', namedRuleGrammar); - - parserParses('start "abcd"\n= "abcd"', namedRuleGrammar); -}); - })();