Skip to content

Commit

Permalink
Exception tests also test exception messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmajda committed Apr 19, 2010
1 parent b5ac4f0 commit 927f2d6
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions test/compiler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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." }
);
});
});

Expand All @@ -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\"." }
);
});
});

Expand Down

0 comments on commit 927f2d6

Please sign in to comment.