From 927f2d65c99e99f18ac87ef86fa5f0622ff7f489 Mon Sep 17 00:00:00 2001 From: David Majda Date: Mon, 19 Apr 2010 20:18:15 +0200 Subject: [PATCH] Exception tests also test exception messages. --- test/compiler-test.js | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/test/compiler-test.js b/test/compiler-test.js index 4f84255..8c7f3b4 100644 --- a/test/compiler-test.js +++ b/test/compiler-test.js @@ -131,9 +131,11 @@ test("formatCode interpolates variables", function() { "foo\nbaz" ); - throws(function() { - PEG.Compiler.formatCode("foo", "${bar}"); - }, Error); + throws( + function() { PEG.Compiler.formatCode("foo", "${bar}"); }, + Error, + { message: "Undefined variable: \"bar\"." } + ); }); test("formatCode filters variables", function() { @@ -142,9 +144,11 @@ test("formatCode filters variables", function() { "foo\n\"baz\"" ); - throws(function() { - PEG.Compiler.formatCode("foo", "${bar|eeek}", { bar: "baz" }); - }, Error); + throws( + function() { PEG.Compiler.formatCode("foo", "${bar|eeek}", { bar: "baz" }); }, + Error, + { message: "Unrecognized filter: \"eeek\"." } + ); }); test("formatCode indents multiline parts", function() { @@ -166,11 +170,19 @@ test("generateUniqueIdentifier", function() { module("PEG"); test("buildParser reports invalid grammar object", function() { - throws(function() { PEG.buildParser(42); }, PEG.Grammar.GrammarError); + throws( + function() { PEG.buildParser(42); }, + PEG.Grammar.GrammarError, + { message: "Grammar must be object or string." } + ); }); test("buildParser reports missing start rule", function() { - throws(function() { PEG.buildParser({}); }, PEG.Grammar.GrammarError); + throws( + function() { PEG.buildParser({}); }, + PEG.Grammar.GrammarError, + { message: "Missing \"start\" rule." } + ); }); test("buildParser reports missing referenced rules", function() { @@ -187,7 +199,11 @@ test("buildParser reports missing referenced rules", function() { ]; PEG.ArrayUtils.each(grammars, function(grammar) { - throws(function() { PEG.buildParser(grammar); }, PEG.Grammar.GrammarError); + throws( + function() { PEG.buildParser(grammar); }, + PEG.Grammar.GrammarError, + { message: "Referenced rule \"missing\" does not exist." } + ); }); }); @@ -208,7 +224,11 @@ test("buildParser reports left recursion", function() { ]; PEG.ArrayUtils.each(grammars, function(grammar) { - throws(function() { PEG.buildParser(grammar); }, PEG.Grammar.GrammarError); + throws( + function() { PEG.buildParser(grammar); }, + PEG.Grammar.GrammarError, + { message: "Left recursion detected for rule \"start\"." } + ); }); });