diff --git a/spec/parser.spec.js b/spec/parser.spec.js index 5266bc9..5842ef4 100644 --- a/spec/parser.spec.js +++ b/spec/parser.spec.js @@ -17,6 +17,10 @@ describe("PEG.js grammar parser", function() { }; } + function ruleRefGrammar(name) { + return oneRuleGrammar(null, { type: "rule_ref", name: name }); + } + function literalGrammar(value) { var ignoreCase = arguments.length > 1 ? arguments[1] : false; @@ -121,6 +125,20 @@ describe("PEG.js grammar parser", function() { }); }); + /* Canonical identifier is "a". */ + it("parses identifier", function() { + expect('start = a' ).toParseAs(ruleRefGrammar("a")); + expect('start = _' ).toParseAs(ruleRefGrammar("_")); + expect('start = $' ).toParseAs(ruleRefGrammar("$")); + expect('start = aa' ).toParseAs(ruleRefGrammar("aa")); + expect('start = a0' ).toParseAs(ruleRefGrammar("a0")); + expect('start = a_' ).toParseAs(ruleRefGrammar("a_")); + expect('start = a$' ).toParseAs(ruleRefGrammar("a$")); + expect('start = abcd').toParseAs(ruleRefGrammar("abcd")); + + expect('start = a\n').toParseAs(ruleRefGrammar("a")); + }); + /* Canonical literal is "\"abcd\"". */ it("parses literal", function() { expect('start = "abcd"' ).toParseAs(literalGrammar("abcd")); diff --git a/test/parser-test.js b/test/parser-test.js index bf86baf..451ba38 100644 --- a/test/parser-test.js +++ b/test/parser-test.js @@ -317,25 +317,4 @@ test("parses braced", function() { /* Trivial character rules are not tested. */ -/* Canonical identifier is "a". */ -test("parses identifier", function() { - parserParses('start = a', identifierGrammar("a")); - parserParses('start = z', identifierGrammar("z")); - parserParses('start = A', identifierGrammar("A")); - parserParses('start = Z', identifierGrammar("Z")); - parserParses('start = _', identifierGrammar("_")); - parserParses('start = $', identifierGrammar("$")); - parserParses('start = aa', identifierGrammar("aa")); - parserParses('start = az', identifierGrammar("az")); - parserParses('start = aA', identifierGrammar("aA")); - parserParses('start = aZ', identifierGrammar("aZ")); - parserParses('start = a0', identifierGrammar("a0")); - parserParses('start = a9', identifierGrammar("a9")); - parserParses('start = a_', identifierGrammar("a_")); - parserParses('start = a$', identifierGrammar("a$")); - parserParses('start = abcd', identifierGrammar("abcd")); - - parserParses('start = a\n', identifierGrammar("a")); -}); - })();