Jasmine: Convert tests of parser's "braced" rule

redux
David Majda 13 years ago
parent b1cb214e8b
commit 35771e15bc

@ -1,5 +1,6 @@
describe("PEG.js grammar parser", function() {
var trivialGrammar;
var trivialGrammar,
literalAbcd = { type: "literal", value: "abcd", ignoreCase: false };
function oneRuleGrammar(displayName, expression) {
return {
@ -17,6 +18,14 @@ describe("PEG.js grammar parser", function() {
};
}
function actionGrammar(code) {
return oneRuleGrammar(null, {
type: "action",
expression: literalAbcd,
code: code
});
}
function ruleRefGrammar(name) {
return oneRuleGrammar(null, { type: "rule_ref", name: name });
}
@ -125,6 +134,14 @@ describe("PEG.js grammar parser", function() {
});
});
/* Canonical braced is "{ code }". */
it("parses braced", function() {
expect('start = "abcd" {}' ).toParseAs(actionGrammar(""));
expect('start = "abcd" {a}' ).toParseAs(actionGrammar("a"));
expect('start = "abcd" {{a}}').toParseAs(actionGrammar("{a}"));
expect('start = "abcd" {aaa}').toParseAs(actionGrammar("aaa"));
});
/* Trivial character rules are not tested. */
/* Canonical identifier is "a". */
@ -153,11 +170,7 @@ describe("PEG.js grammar parser", function() {
/* Canonical string is "\"abcd\"". */
it("parses string", function() {
var grammar = oneRuleGrammar("abcd", {
type: "literal",
value: "abcd",
ignoreCase: false
});
var grammar = oneRuleGrammar("abcd", literalAbcd);
expect('start "abcd" = "abcd"' ).toParseAs(grammar);
expect('start \'abcd\' = "abcd"').toParseAs(grammar);

@ -307,12 +307,4 @@ test("parses action", function() {
parserParses('start = "a" { code }', actionGrammar(" code "));
});
/* Canonical braced is "{ code }". */
test("parses braced", function() {
parserParses('start = "a" {}', actionGrammar(""));
parserParses('start = "a" {a}', actionGrammar("a"));
parserParses('start = "a" {{a}}', actionGrammar("{a}"));
parserParses('start = "a" {aaa}', actionGrammar("aaa"));
});
})();

Loading…
Cancel
Save