-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix serialization of errors in failing tests; add QUnit test suite
- Loading branch information
1 parent
f45144f
commit f37b9ac
Showing
7 changed files
with
212 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../doctest.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var app = require('express').createServer(); | ||
|
||
app.get(/^\/((doc)?test[.]js)?$/, function (req, res) { | ||
res.sendfile(__dirname + '/' + (req.route.params[0] || 'test.html')); | ||
}); | ||
|
||
app.listen(3000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>doctest test suite</title> | ||
<script src="/doctest.js"></script> | ||
<script src="https://raw.github.com/documentcloud/underscore/master/underscore.js"></script> | ||
<script src="http://code.jquery.com/jquery-latest.js"></script> | ||
<script src="http://code.jquery.com/qunit/git/qunit.js"></script> | ||
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" /> | ||
<script> | ||
jQuery(function($) { | ||
|
||
doctest.complete = function(results) { | ||
var idx = 0 | ||
var t = function(message, expected) { | ||
if (expected[0]) expected[2] = expected[1] | ||
deepEqual(results[idx++], expected, message) | ||
} | ||
|
||
t('global variable accessible in outer scope', | ||
[true, '"global"', , 3]) | ||
|
||
t('global variable accessible in inner scope', | ||
[true, '"global"', , 10]) | ||
|
||
t('local variable referenced, not shadowed global', | ||
[true, '"shadowed"', , 14]) | ||
|
||
t('local variable accessible before declaratation', | ||
[true, 2, , 20]) | ||
|
||
t('assignment is an expression', | ||
[true, 3, , 25]) | ||
|
||
t('variable declared in doctest remains accessible', | ||
[true, [1, 2, 3], , 28]) | ||
|
||
t('arithmetic error reported', | ||
[false, 5, 4, 31]) | ||
|
||
t('TypeError captured and reported', | ||
[true, 'TypeError', , 35]) | ||
|
||
t('TypeError expected but not reported', | ||
[false, 'TypeError', 0, 38]) | ||
|
||
t('function accessible before declaration', | ||
[true, 12, , 42]) | ||
|
||
t('NaN can be used as expected result', | ||
[true, NaN, , 45]) | ||
|
||
t('function accessible after declaration', | ||
[true, 4, , 53]) | ||
|
||
t('multiline input', | ||
[true, [1, 2, 3, 4, 5, 6, 7, 8, 9], , 64]) | ||
|
||
t('multiline assignment', | ||
[true, '"input may span many lines"', , 70]) | ||
|
||
t('spaces following "//" and ">" are optional', | ||
[true, '"no spaces"', , 73]) | ||
|
||
t('indented doctest', | ||
[true, '"Docco-compatible whitespace"', , 76]) | ||
|
||
t('">" in doctest', | ||
[true, true, true, 79]) | ||
|
||
start() | ||
} | ||
asyncTest('all tests', function() { | ||
doctest('./test.js') | ||
}) | ||
|
||
}) | ||
</script> | ||
</head> | ||
<body> | ||
<h1 id="qunit-header">doctest test suite</h1> | ||
<h2 id="qunit-banner"></h2> | ||
<div id="qunit-testrunner-toolbar"></div> | ||
<h2 id="qunit-userAgent"></h2> | ||
<ol id="qunit-tests"></ol> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
0. | ||
// > global | ||
// "global" | ||
global = 'global' | ||
|
||
!function() { | ||
|
||
1. | ||
// > global | ||
// "global" | ||
!function() { | ||
2. | ||
// > global | ||
// "shadowed" | ||
var global = 'shadowed' | ||
}() | ||
|
||
3. | ||
// > one * two | ||
// 2 | ||
var one = 1 | ||
var two = 2 | ||
4. | ||
// > three = one + two | ||
// 3 | ||
5. | ||
// > [one, two, three] | ||
// [1, 2, 3] | ||
6. | ||
// > two + two | ||
// 5 | ||
|
||
7. | ||
// > null.length | ||
// TypeError | ||
8. | ||
// > [].length | ||
// TypeError | ||
|
||
9. | ||
// > double(6) | ||
// 12 | ||
10. | ||
// > double() | ||
// NaN | ||
var double = function(n) { | ||
// doctests should only be included in contexts where they'll be | ||
// invoked immediately (i.e. at the top level or within an IIFE) | ||
return 2 * n | ||
} | ||
11. | ||
// > double.call(null, 2) | ||
// 4 | ||
|
||
var triple = function(n) { | ||
// > this.doctest.should.never.be.executed | ||
// ( blow.up.if.for.some.reason.it.is ) | ||
return 3 * n | ||
} | ||
|
||
// > [1,2,3, | ||
// . 4,5,6, | ||
// . 7,8,9] | ||
// [1,2,3,4,5,6,7,8,9] | ||
// | ||
// > text = "input " + | ||
// . "may span many " + | ||
// . "lines" | ||
// > text | ||
// "input may span many lines" | ||
|
||
//>"no spaces" | ||
//"no spaces" | ||
// | ||
// > "Docco-compatible whitespace" | ||
// "Docco-compatible whitespace" | ||
// | ||
// > 2 > 1 | ||
// true | ||
|
||
}() |