-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expands
load
function, experiments with loading assertions from tests.
- Matches the behavior of `load` function in V8, SpiderMonkey, Rhino, etc. - Converts a few tests to load `tools/assertions.js` rather than define the assertion helpers within the test scripts themselves. Also a bit of hoop-jumping to get compatibility with Node.js which doesn't include/expose V8's `load` but does have `require`. - `load` works well when the script is run as a file, but there are still issues with using it from the REPL.
- Loading branch information
1 parent
d6f03f3
commit ab5382d
Showing
8 changed files
with
100 additions
and
44 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// assertions.js | ||
// ------------- | ||
|
||
(function() { | ||
|
||
// If this is a Node.js require, we need to set up the assertion helpers on | ||
// the GLOBAL object for compatability with the other implementations that | ||
// use `load` to evaluate this file. | ||
var root = this.GLOBAL || this; | ||
|
||
root.assert = console.assert; | ||
|
||
root.assertTrue = function(a) { assert(a); }; | ||
|
||
root.assertFalse = function(a) { assert(!a); }; | ||
|
||
root.assertEquals = function(a, b) { | ||
if (a !== b) | ||
console.log(a + ' !== ' + b); | ||
assert(a === b); | ||
}; | ||
|
||
root.assertArrayEquals = function(a, b) { | ||
assert(a.length === b.length); | ||
for (var i = 0; i < a.length; i++) { | ||
assert(a[i] === b[i]); | ||
} | ||
}; | ||
|
||
root.assertRegExpEquals = function(a, b) { | ||
assertEquals(a.source, b.source); | ||
assertEquals(a.global, b.global); | ||
assertEquals(a.multiline, b.multiline); | ||
assertEquals(a.ignoreCase, b.ignoreCase); | ||
}; | ||
|
||
root.assertEmptyRegExp = function(r, cmp) { | ||
// The value of the 'source' prop seems to be implementation-specific | ||
// when the 'pattern' constructor argument is undefined. | ||
// | ||
// Either '(?:)' or '' is acceptable. | ||
if (!(r.source === '(?:)' || r.source === '')) | ||
assert(false); | ||
assertEquals(r.global, cmp.global); | ||
assertEquals(r.multiline, cmp.multiline); | ||
assertEquals(r.ignoreCase, cmp.ignoreCase); | ||
}; | ||
|
||
root.assertBetween = function(x, min, max) { | ||
assert(x > min && x < max); // exclusive | ||
}; | ||
|
||
root.assertClose = function(a, b, tolerance) { | ||
assert(a < (b + tolerance)); | ||
assert(a > (b - tolerance)); | ||
}; | ||
|
||
// For now this is just a way to structure tests, but later it may be used to | ||
// generate reports. | ||
root.test = function(name, f) { | ||
f(); | ||
}; | ||
|
||
root.assertionsLoaded = true; | ||
})(); |
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
Empty file.