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

redux
David Majda 13 years ago
parent 4f91286013
commit a27dc5ae4a

@ -1,8 +1,8 @@
describe("PEG.js grammar parser", function() {
var trivialGrammar;
beforeEach(function() {
trivialGrammar = {
function literalGrammar(value) {
return {
type: "grammar",
initializer: null,
rules: [
@ -10,11 +10,15 @@ describe("PEG.js grammar parser", function() {
type: "rule",
name: "start",
displayName: null,
expression: { type: "literal", value: "abcd", ignoreCase: false }
expression: { type: "literal", value: value, ignoreCase: false }
}
],
startRule: "start"
};
}
beforeEach(function() {
trivialGrammar = literalGrammar("abcd");
this.addMatchers({
toParseAs: function(expected) {
@ -68,6 +72,15 @@ describe("PEG.js grammar parser", function() {
});
});
/* Canonical eolEscapeSequence is "\\\n". */
it("parses eolEscapeSequence", function() {
expect('start = "\\\n"' ).toParseAs(literalGrammar("\n"));
expect('start = "\\\r\n"' ).toParseAs(literalGrammar("\r\n"));
expect('start = "\\\r"' ).toParseAs(literalGrammar("\r"));
expect('start = "\\\u2028"').toParseAs(literalGrammar("\u2028"));
expect('start = "\\\u2029"').toParseAs(literalGrammar("\u2029"));
});
/* Trivial character class rules are not tested. */
/* Canonical __ is "\n". */

@ -516,13 +516,4 @@ test("parses unicodeEscapeSequence", function() {
parserParses('start = "\\u01234"', literalGrammar("\u01234"));
});
/* Canonical eolEscapeSequence is "\\\n". */
test("parses eolEscapeSequence", function() {
parserParses('start = "\\\n"', literalGrammar("\n"));
parserParses('start = "\\\r\n"', literalGrammar("\r\n"));
parserParses('start = "\\\r"', literalGrammar("\r"));
parserParses('start = "\\\u2028"', literalGrammar("\u2028"));
parserParses('start = "\\\u2029"', literalGrammar("\u2029"));
});
})();

Loading…
Cancel
Save