1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Clone Test-Suite (Browser)</title>
<script>
var module = {};
var tests = exports = module.exports = {};
function require(moduleName) {
if (moduleName == './') {
return clone;
}
}
function log(str) {
logList.innerHTML += '<li>' + str + '</li>';
}
</script>
<script src="clone.js"></script>
<script src="test.js"></script>
</head>
<body>
<h1 id="nodeunit-header">Clone Test-Suite (Browser)</h1>
Tests started: <span id="testsStarted"></span>;
Tests finished: <span id="testsFinished"></span>.
<ul id="logList"></ul>
<script>
/* Methods copied from
* https://github.com/caolan/nodeunit/blob/master/lib/assert.js
*/
function isUndefinedOrNull(value) {
return value === null || value === undefined;
}
function isArguments(object) {
return Object.prototype.toString.call(object) == '[object Arguments]';
}
var _keys = function (obj){
if (Object.keys) return Object.keys(obj);
if (typeof obj != 'object' && typeof obj != 'function') {
throw new TypeError('-');
}
var keys = [];
for(var k in obj) if(obj.hasOwnProperty(k)) keys.push(k);
return keys;
};
function objEquiv(a, b) {
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
return false;
if (a.prototype !== b.prototype)
return false;
if (isArguments(a)) {
if (!isArguments(b)) return false;
a = pSlice.call(a);
b = pSlice.call(b);
return _deepEqual(a, b);
}
try {
var ka = _keys(a), kb = _keys(b), key, i;
} catch (e) {
return false
}
if (ka.length != kb.length)
return false;
ka.sort();
kb.sort();
for (i = ka.length - 1; i >= 0; i--) {
if (ka[i] != kb[i]) return false;
}
for (i = ka.length - 1; i >= 0; i--) {
key = ka[i];
if (!_deepEqual(a[key], b[key] ))
return false;
}
return true;
}
function _deepEqual(actual, expected) {
if (actual === expected) {
return true;
} else if (actual instanceof Date && expected instanceof Date) {
return actual.getTime() === expected.getTime();
} else if (actual instanceof RegExp && expected instanceof RegExp) {
return actual.source === expected.source &&
actual.global === expected.global &&
actual.ignoreCase === expected.ignoreCase &&
actual.multiline === expected.multiline;
} else if (typeof actual != 'object' && typeof expected != 'object') {
return actual == expected;
} else {
return objEquiv(actual, expected);
}
}
for (var testName in tests) {
setTimeout((function (testName) {
try {
testsStarted.innerHTML = (parseInt(testsStarted.innerHTML) || 0) + 1;
function incFinished() {
testsFinished.innerHTML = (parseInt(testsFinished.innerHTML) || 0) + 1;
}
tests[testName]({
expect: function (num) {
this._expect = num
},
ok: function (val) {
if(!val) throw new Error(val + ' is not ok.')
},
equal: function (a,b) {
if (a != b) throw new Error(a + ' is not equal to ' + b)
},
notEqual: function (a,b) {
if (a == b) throw new Error(a + ' is equal to ' + b)
},
strictEqual: function (a,b) {
if (a !== b) throw new Error(a + ' is not strict equal to ' + b)
},
deepEqual: function (a,b) {
if (!_deepEqual(a,b))
throw new Error(JSON.stringify(a) + ' is not deep equal to ' +
JSON.stringify(b))
},
done: function () {
log(testName + ' <span style="color:blue">is ok</span>.');
incFinished();
}
});
} catch(e) {
log(testName + ' <span style="color:red">FAIL.</span> <small>'+ e +'</small>');
incFinished();
console.log(e);
}
})(testName), 1);
}
</script>
</body>
</html>
|