Jasmine: Convert tests of parser's "identifier" rule
This commit is contained in:
parent
a3d93f000f
commit
4f5b78b372
|
@ -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"));
|
||||
|
|
|
@ -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"));
|
||||
});
|
||||
|
||||
})();
|
||||
|
|
Loading…
Reference in a new issue