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

redux
David Majda 12 years ago
parent bf6d412a4f
commit ec8889f85d

@ -1,7 +1,8 @@
describe("PEG.js grammar parser", function() { describe("PEG.js grammar parser", function() {
var trivialGrammar, var trivialGrammar,
literalAbcd = { type: "literal", value: "abcd", ignoreCase: false }, literalAbcd = { type: "literal", value: "abcd", ignoreCase: false },
optionalLiteral = { type: "optional", expression: literalAbcd }; optionalLiteral = { type: "optional", expression: literalAbcd },
simpleNotLiteral = { type: "simple_not", expression: literalAbcd };
function oneRuleGrammar(displayName, expression) { function oneRuleGrammar(displayName, expression) {
return { return {
@ -135,6 +136,18 @@ describe("PEG.js grammar parser", function() {
}); });
}); });
/* Canonical labeled is "label:\"abcd\"". */
it("parses labeled", function() {
expect('start = label:!"abcd"').toParseAs(oneRuleGrammar(null, {
type: "labeled",
label: "label",
expression: simpleNotLiteral
}));
expect('start = !"abcd"' ).toParseAs(
oneRuleGrammar(null, simpleNotLiteral)
);
});
/* Canonical prefixed is "!\"abcd\"". */ /* Canonical prefixed is "!\"abcd\"". */
it("parses prefixed", function() { it("parses prefixed", function() {
expect('start = &{ code }').toParseAs(oneRuleGrammar(null, { expect('start = &{ code }').toParseAs(oneRuleGrammar(null, {

@ -267,13 +267,4 @@ test("parses sequence", function() {
); );
}); });
/* Canonical labeled is "label:\"abcd\"". */
test("parses labeled", function() {
parserParses(
'start = label:!"abcd"',
oneRuleGrammar(labeled("label", simpleNot(literalAbcd)))
);
parserParses('start = !"abcd"', oneRuleGrammar(simpleNot(literalAbcd)));
});
})(); })();

Loading…
Cancel
Save