From dac3b0d8d94d905b9f48caa1eb1886ba74b5fa8d Mon Sep 17 00:00:00 2001 From: David Majda Date: Fri, 20 Apr 2012 15:07:33 +0200 Subject: [PATCH] Jasmine: Convert tests of parser's "multiLineComment" rule --- spec/parser.spec.js | 35 ++++++++++++++++++++++++++++++++++- test/parser-test.js | 14 -------------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/spec/parser.spec.js b/spec/parser.spec.js index 29c3c37..1103e3b 100644 --- a/spec/parser.spec.js +++ b/spec/parser.spec.js @@ -17,7 +17,7 @@ describe("PEG.js grammar parser", function() { }; this.addMatchers({ - toParseAs: function(expected) { + toParseAs: function(expected) { var result; try { @@ -41,10 +41,43 @@ describe("PEG.js grammar parser", function() { return false; } + }, + + toFailToParse: function() { + var result; + + try { + result = PEG.parser.parse(this.actual); + + this.message = function() { + return "Expected " + jasmine.pp(this.actual) + " to fail to parse, " + + "but it parsed as " + jasmine.pp(result) + "."; + }; + + return false; + } catch (e) { + this.message = function() { + return "Expected " + jasmine.pp(this.actual) + " to parse, " + + "but it failed with message " + + jasmine.pp(e.message) + "."; + }; + + return true; + } } }); }); + // Canonical multiLineComment is "/* comment */". + it("parses multiLineComment", function() { + expect('start =/**/"abcd"' ).toParseAs(trivialGrammar); + expect('start =/*a*/"abcd"' ).toParseAs(trivialGrammar); + expect('start =/*aaa*/"abcd"').toParseAs(trivialGrammar); + expect('start =/***/"abcd"' ).toParseAs(trivialGrammar); + + expect('start =/**/*/"abcd"').toFailToParse(); + }); + /* Canonical eol is "\n". */ it("parses eol", function() { expect('start =\n"abcd"' ).toParseAs(trivialGrammar); diff --git a/test/parser-test.js b/test/parser-test.js index afc4af7..426cdb5 100644 --- a/test/parser-test.js +++ b/test/parser-test.js @@ -549,18 +549,4 @@ test("parses singleLineComment", function() { parserParses('start = "abcd"//', simpleGrammar); }); -// Canonical multiLineComment is "\/* comment *\/". -test("parses multiLineComment", function() { - parserParses('start =/**/"abcd"', simpleGrammar); - parserParses('start =/*a*/"abcd"', simpleGrammar); - parserParses('start =/*aaa*/"abcd"', simpleGrammar); - parserParses('start =/*\n*/"abcd"', simpleGrammar); - parserParses('start =/***/"abcd"', simpleGrammar); - parserParses('start =/*a/*/"abcd"', simpleGrammar); - - parserDoesNotParse('start =/*"abcd"'); - parserDoesNotParse('start =/*/"abcd"'); - parserDoesNotParse('start =/*/**/*/"abcd"'); -}); - })();