Move test helper into its own file + reorder test file includes

redux
David Majda 14 years ago
parent fea6d85194
commit d493a4d143

@ -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() {

@ -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);

@ -4,12 +4,13 @@
<meta charset="utf-8">
<title>PEG.js Test Suite</title>
<link rel="stylesheet" href="vendor/qunit/qunit.css">
<script src="vendor/qunit/qunit.js"></script>
<script src="../lib/peg.js"></script>
<script src="compiler-test.js"></script>
<script src="vendor/qunit/qunit.js"></script>
<script src="helpers.js"></script>
<script src="parser-test.js"></script>
<script src="checks-test.js"></script>
<script src="passes-test.js"></script>
<script src="parser-test.js"></script>
<script src="compiler-test.js"></script>
</head>
<body>
<h1 id="qunit-header">PEG.js Test Suite</h1>

@ -1,21 +1,5 @@
(function(global) {
/* ===== Helpers ===== */
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);
}
/* ===== PEG.parser ===== */
module("PEG.parser");
function initializer(code) {

Loading…
Cancel
Save