From 4f5b78b372d4de6426db1215eadcb4fec0b05e9a Mon Sep 17 00:00:00 2001 From: David Majda Date: Fri, 20 Apr 2012 19:33:20 +0200 Subject: [PATCH] Jasmine: Convert tests of parser's "identifier" rule --- spec/parser.spec.js | 18 ++++++++++++++++++ test/parser-test.js | 21 --------------------- 2 files changed, 18 insertions(+), 21 deletions(-) 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")); -}); - })();