diff --git a/spec/parser.spec.js b/spec/parser.spec.js index 0194bcb..1933f98 100644 --- a/spec/parser.spec.js +++ b/spec/parser.spec.js @@ -1,7 +1,7 @@ describe("PEG.js grammar parser", function() { var trivialGrammar; - function literalGrammar(value) { + function oneRuleGrammar(expression) { return { type: "grammar", initializer: null, @@ -10,13 +10,27 @@ describe("PEG.js grammar parser", function() { type: "rule", name: "start", displayName: null, - expression: { type: "literal", value: value, ignoreCase: false } + expression: expression } ], startRule: "start" }; } + function literalGrammar(value) { + return oneRuleGrammar({ type: "literal", value: value, ignoreCase: false }); + } + + function classGrammar(parts, rawText) { + return oneRuleGrammar({ + type: "class", + inverted: false, + ignoreCase: false, + parts: parts, + rawText: rawText + }); + } + beforeEach(function() { trivialGrammar = literalGrammar("abcd"); @@ -72,6 +86,15 @@ describe("PEG.js grammar parser", function() { }); }); + /* Canonical simpleBracketDelimiedCharacter is "a". */ + it("parses simpleBracketDelimitedCharacter", function() { + expect('start = [a]').toParseAs(classGrammar(["a"], "[a]")); + + expect('start = []]' ).toFailToParse(); + expect('start = [\\]').toFailToParse(); + expect('start = [\n]').toFailToParse(); + }); + /* Canonical simpleEscapeSequence is "\\n". */ it("parses simpleEscapeSequence", function() { expect('start = "\\b"').toParseAs(literalGrammar("\b")); diff --git a/test/parser-test.js b/test/parser-test.js index 2c3c2da..42d61ab 100644 --- a/test/parser-test.js +++ b/test/parser-test.js @@ -457,16 +457,4 @@ test("parses bracketDelimitedCharacter", function() { parserParses("start = [\\\n]", classGrammar(false, ["\n"], "[\\n]")); }); -/* Canonical simpleBracketDelimiedCharacter is "a". */ -test("parses simpleBracketDelimitedCharacter", function() { - parserParses("start = [a]", classGrammar(false, ["a"], "[a]")); - parserParses("start = [[]", classGrammar(false, ["["], "[[]")); - parserDoesNotParse("start = []]"); - parserDoesNotParse("start = [\\]"); - parserDoesNotParse("start = [\n]"); - parserDoesNotParse("start = [\r]"); - parserDoesNotParse("start = [\u2028]"); - parserDoesNotParse("start = [\u2029]"); -}); - })();