diff --git a/spec/parser.spec.js b/spec/parser.spec.js index 7138c69..af089b6 100644 --- a/spec/parser.spec.js +++ b/spec/parser.spec.js @@ -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". */ diff --git a/test/parser-test.js b/test/parser-test.js index 87948e2..630ef15 100644 --- a/test/parser-test.js +++ b/test/parser-test.js @@ -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")); -}); - })();