Skip to content

Commit

Permalink
Refactored helpers for testing of thrown exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmajda committed Apr 19, 2010
1 parent de7536f commit b5ac4f0
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions test/compiler-test.js
Expand Up @@ -4,7 +4,7 @@ var global = this;

/* ===== Helpers ===== */

global.throws = function(block, exceptionType) {
global.throws = function(block, exceptionType, exceptionProperties) {
var exception = null;
try {
block();
Expand All @@ -23,9 +23,11 @@ global.throws = function(block, exceptionType) {
? "okay: thrown " + exceptionType.name
: "failed, thrown " + exception.name + " instead of " + exceptionType.name
);
}

return exception;
for (var property in exceptionProperties) {
strictEqual(exception[property], exceptionProperties[property]);
}
}
};

global.parses = function(parser, input, expected) {
Expand All @@ -37,24 +39,22 @@ global.doesNotParse = function(parser, input) {
};

global.doesNotParseWithMessage = function(parser, input, message) {
var exception = throws(
throws(
function() { parser.parse(input); },
parser.SyntaxError
parser.SyntaxError,
{ message: message }
);
if (exception) {
strictEqual(exception.message, message);
}
};

global.doesNotParseWithPos = function(parser, input, line, column) {
var exception = throws(
function() { parser.parse(input); },
parser.SyntaxError
parser.SyntaxError,
{
line: line,
column: column
}
);
if (exception) {
strictEqual(exception.line, line);
strictEqual(exception.column, column);
}
};

/* ===== PEG.ArrayUtils ===== */
Expand Down

0 comments on commit b5ac4f0

Please sign in to comment.