diff --git a/test/compiler-test.js b/test/compiler-test.js index d84375b..3c10657 100644 --- a/test/compiler-test.js +++ b/test/compiler-test.js @@ -1,62 +1,5 @@ (function(global) { -/* ===== Helpers ===== */ - -global.throws = function(block, exceptionType, exceptionProperties) { - var exception = null; - try { - block(); - } catch (e) { - exception = e; - } - - ok( - exception !== null, - exception !== null ? "okay: thrown something" : "failed, nothing thrown" - ); - if (exception !== null) { - ok( - exception instanceof exceptionType, - exception instanceof exceptionType - ? "okay: thrown " + exceptionType.name - : "failed, thrown " + exception.name + " instead of " + exceptionType.name - ); - - for (var property in exceptionProperties) { - strictEqual(exception[property], exceptionProperties[property]); - } - } -}; - -global.parses = function(parser, input, expected) { - deepEqual(parser.parse(input), expected); -}; - -global.doesNotParse = function(parser, input) { - throws(function() { parser.parse(input); }, parser.SyntaxError); -}; - -global.doesNotParseWithMessage = function(parser, input, message) { - throws( - function() { parser.parse(input); }, - parser.SyntaxError, - { message: message } - ); -}; - -global.doesNotParseWithPos = function(parser, input, line, column) { - var exception = throws( - function() { parser.parse(input); }, - parser.SyntaxError, - { - line: line, - column: column - } - ); -}; - -/* ===== PEG.compiler ===== */ - module("PEG.compiler"); test("choices", function() { diff --git a/test/helpers.js b/test/helpers.js new file mode 100644 index 0000000..027075a --- /dev/null +++ b/test/helpers.js @@ -0,0 +1,68 @@ +(function(global) { + +global.throws = function(block, exceptionType, exceptionProperties) { + var exception = null; + try { + block(); + } catch (e) { + exception = e; + } + + ok( + exception !== null, + exception !== null ? "okay: thrown something" : "failed, nothing thrown" + ); + if (exception !== null) { + ok( + exception instanceof exceptionType, + exception instanceof exceptionType + ? "okay: thrown " + exceptionType.name + : "failed, thrown " + exception.name + " instead of " + exceptionType.name + ); + + for (var property in exceptionProperties) { + strictEqual(exception[property], exceptionProperties[property]); + } + } +}; + +global.parses = function(parser, input, expected) { + deepEqual(parser.parse(input), expected); +}; + +global.doesNotParse = function(parser, input) { + throws(function() { parser.parse(input); }, parser.SyntaxError); +}; + +global.doesNotParseWithMessage = function(parser, input, message) { + throws( + function() { parser.parse(input); }, + parser.SyntaxError, + { message: message } + ); +}; + +global.doesNotParseWithPos = function(parser, input, line, column) { + var exception = throws( + function() { parser.parse(input); }, + parser.SyntaxError, + { + line: line, + column: column + } + ); +}; + +global.parserParses = function(input, expected) { + global.parses(PEG.parser, input, expected); +}; + +global.parserDoesNotParse = function(input) { + global.doesNotParse(PEG.parser, input); +} + +global.parserDoesNotParseWithMessage = function(input, message) { + global.doesNotParseWithMessage(PEG.parser, input, message); +} + +})(this); diff --git a/test/index.html b/test/index.html index 7b4c352..89c8bf8 100644 --- a/test/index.html +++ b/test/index.html @@ -4,12 +4,13 @@