Instantly share code, notes, and snippets.

Embed
What would you like to do?
jQuery のビルドはできないが SpiderMonkey JavaScript Shell が利用できる環境で jQuery Deferred のテストを実行するためのスクリプト。
var window = this;
if (typeof JSON === 'undefined') {
this.JSON = {};
}
load('src/core.js');
load('src/callbacks.js');
load('src/deferred.js');
function module() {}
function moduleTeardown() {}
var finallyFailed = false;
var testCount = 0;
function strictEqual(actual, expected, description) {
testCount++;
if (actual === expected) {
print('ok: ' + description);
} else {
finallyFailed = true;
print('fail: ' + description);
print(' actual: ' + uneval(actual));
print(' expected: ' + uneval(expected));
print();
}
}
function notStrictEqual(actual, notExpected, description) {
testCount++;
if (actual !== notExpected) {
print('ok: ' + description);
} else {
finallyFailed = true;
print('fail: ' + description);
print(' actual: ' + uneval(actual));
print();
}
}
function deepEqual(actual, expected, description) {
testCount++;
if (_deepEqual(actual, expected)) {
print('ok: ' + description);
} else {
finallyFailed = true;
print('fail: ' + description);
print(' actual: ' + uneval(actual));
print(' expected: ' + uneval(expected));
print();
}
}
function _deepEqual(actual, expected) {
switch (actual ? typeof actual : 'primitive') {
case 'primitive':
case 'undefined':
case 'number':
case 'string':
case 'boolean':
return actual === expected;
default:
for (var i in actual) {
if (!_deepEqual(actual[i], expected[i])) {
return false;
}
}
return true;
}
}
function ok(actual, description) {
testCount++;
if (actual) {
print('ok: ' + description);
} else {
finallyFailed = true;
print('fail: ' + description);
print(' actual: ' + uneval(actual));
print();
}
}
var expect = null;
function test(name, process) {
var expectedCount = 0;
expect = function (count) {
expectedCount = count;
};
testCount = 0;
process();
expect = null;
print('done: ' + name);
if (expectedCount) {
if (expectedCount === testCount) {
print(' ok: ' + testCount + ' tests were done');
} else {
finallyFailed = true;
print(' failed: ' + testCount + ' tests were done (expected ' + expectedCount + ')');
}
}
print();
}
load('test/unit/deferred.js');
print(finallyFailed ? 'something failed' : 'all ok');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment