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

redux
David Majda 13 years ago
parent 5fb59b05f2
commit ba68919b0a

@ -22,10 +22,13 @@ describe("PEG.js grammar parser", function() {
}
function classGrammar(parts, rawText) {
var inverted = arguments.length > 2 ? arguments[2] : false,
ignoreCase = arguments.length > 3 ? arguments[3] : false;
return oneRuleGrammar({
type: "class",
inverted: false,
ignoreCase: false,
inverted: inverted,
ignoreCase: ignoreCase,
parts: parts,
rawText: rawText
});
@ -112,6 +115,29 @@ describe("PEG.js grammar parser", function() {
});
});
/* Canonical class is "[a-d]". */
it("parses class", function() {
expect('start = []' ).toParseAs(classGrammar([], "[]"));
expect('start = [a-d]' ).toParseAs(classGrammar([["a", "d"]], "[a-d]"));
expect('start = [a]' ).toParseAs(classGrammar(["a"], "[a]"));
expect('start = [a-de-hi-l]').toParseAs(
classGrammar([["a", "d"], ["e", "h"], ["i", "l"]], "[a-de-hi-l]")
);
expect('start = [^a-d]').toParseAs(
classGrammar([["a", "d"]], "[^a-d]", true, false)
);
expect('start = [a-d]i').toParseAs(
classGrammar([["a", "d"]], "[a-d]i", false, true)
);
expect('start = [\u0080\u0081\u0082]').toParseAs(
classGrammar(["\u0080", "\u0081", "\u0082"], "[\\x80\\x81\\x82]")
);
expect('start = [a-d]\n').toParseAs(classGrammar([["a", "d"]], "[a-d]"));
});
/* Canonical classCharacterRange is "a-d". */
it("parses classCharacterRange", function() {
expect('start = [a-d]').toParseAs(classGrammar([["a", "d"]], "[a-d]"));

@ -413,22 +413,4 @@ test("parses simpleSingleQuotedCharacter", function() {
parserDoesNotParse("start = '\u2029'");
});
/* Canonical class is "[a-d]". */
test("parses class", function() {
parserParses("start = []", classGrammar(false, [], "[]"));
parserParses("start = [a-d]", classGrammar(false, [["a", "d"]], "[a-d]"));
parserParses("start = [^a-d]", classGrammar(true, [["a", "d"]], "[^a-d]"));
parserParses("start = [a]", classGrammar(false, ["a"], "[a]"));
parserParses(
"start = [a-de-hi-l]",
classGrammar(false, [["a", "d"], ["e", "h"], ["i", "l"]], "[a-de-hi-l]")
);
parserParses(
"start = [a-d]i",
oneRuleGrammar(klass(false, true, [["a", "d"]], "[a-d]i"))
);
parserParses("start = [a-d]\n", classGrammar(false, [["a", "d"]], "[a-d]"));
});
})();

Loading…
Cancel
Save