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

redux
David Majda 13 years ago
parent 2bb266bbaf
commit da4ac8bb92

@ -1,7 +1,7 @@
describe("PEG.js grammar parser", function() {
var trivialGrammar;
function literalGrammar(value) {
function oneRuleGrammar(expression) {
return {
type: "grammar",
initializer: null,
@ -10,13 +10,27 @@ describe("PEG.js grammar parser", function() {
type: "rule",
name: "start",
displayName: null,
expression: { type: "literal", value: value, ignoreCase: false }
expression: expression
}
],
startRule: "start"
};
}
function literalGrammar(value) {
return oneRuleGrammar({ type: "literal", value: value, ignoreCase: false });
}
function classGrammar(parts, rawText) {
return oneRuleGrammar({
type: "class",
inverted: false,
ignoreCase: false,
parts: parts,
rawText: rawText
});
}
beforeEach(function() {
trivialGrammar = literalGrammar("abcd");
@ -72,6 +86,15 @@ describe("PEG.js grammar parser", function() {
});
});
/* Canonical simpleBracketDelimiedCharacter is "a". */
it("parses simpleBracketDelimitedCharacter", function() {
expect('start = [a]').toParseAs(classGrammar(["a"], "[a]"));
expect('start = []]' ).toFailToParse();
expect('start = [\\]').toFailToParse();
expect('start = [\n]').toFailToParse();
});
/* Canonical simpleEscapeSequence is "\\n". */
it("parses simpleEscapeSequence", function() {
expect('start = "\\b"').toParseAs(literalGrammar("\b"));

@ -457,16 +457,4 @@ test("parses bracketDelimitedCharacter", function() {
parserParses("start = [\\\n]", classGrammar(false, ["\n"], "[\\n]"));
});
/* Canonical simpleBracketDelimiedCharacter is "a". */
test("parses simpleBracketDelimitedCharacter", function() {
parserParses("start = [a]", classGrammar(false, ["a"], "[a]"));
parserParses("start = [[]", classGrammar(false, ["["], "[[]"));
parserDoesNotParse("start = []]");
parserDoesNotParse("start = [\\]");
parserDoesNotParse("start = [\n]");
parserDoesNotParse("start = [\r]");
parserDoesNotParse("start = [\u2028]");
parserDoesNotParse("start = [\u2029]");
});
})();

Loading…
Cancel
Save