5 <title>Clone Test-Suite (Browser)</title>
8 var tests = exports = module.exports = {};
10 function require(moduleName) {
11 if (moduleName == './') {
17 logList.innerHTML += '<li>' + str + '</li>';
20 <script src="clone.js"></script>
21 <script src="test.js"></script>
24 <h1 id="nodeunit-header">Clone Test-Suite (Browser)</h1>
25 Tests started: <span id="testsStarted"></span>;
26 Tests finished: <span id="testsFinished"></span>.
27 <ul id="logList"></ul>
29 /* Methods copied from
30 * https://github.com/caolan/nodeunit/blob/master/lib/assert.js
32 function isUndefinedOrNull(value) {
33 return value === null || value === undefined;
36 function isArguments(object) {
37 return Object.prototype.toString.call(object) == '[object Arguments]';
40 var _keys = function (obj){
41 if (Object.keys) return Object.keys(obj);
42 if (typeof obj != 'object' && typeof obj != 'function') {
43 throw new TypeError('-');
46 for(var k in obj) if(obj.hasOwnProperty(k)) keys.push(k);
50 function objEquiv(a, b) {
51 if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
54 if (a.prototype !== b.prototype)
58 if (!isArguments(b)) return false;
61 return _deepEqual(a, b);
65 var ka = _keys(a), kb = _keys(b), key, i;
70 if (ka.length != kb.length)
76 for (i = ka.length - 1; i >= 0; i--) {
77 if (ka[i] != kb[i]) return false;
80 for (i = ka.length - 1; i >= 0; i--) {
82 if (!_deepEqual(a[key], b[key] ))
88 function _deepEqual(actual, expected) {
89 if (actual === expected) {
91 } else if (actual instanceof Date && expected instanceof Date) {
92 return actual.getTime() === expected.getTime();
93 } else if (actual instanceof RegExp && expected instanceof RegExp) {
94 return actual.source === expected.source &&
95 actual.global === expected.global &&
96 actual.ignoreCase === expected.ignoreCase &&
97 actual.multiline === expected.multiline;
98 } else if (typeof actual != 'object' && typeof expected != 'object') {
99 return actual == expected;
101 return objEquiv(actual, expected);
105 for (var testName in tests) {
106 setTimeout((function (testName) {
108 testsStarted.innerHTML = (parseInt(testsStarted.innerHTML) || 0) + 1;
109 function incFinished() {
110 testsFinished.innerHTML = (parseInt(testsFinished.innerHTML) || 0) + 1;
114 expect: function (num) {
118 if(!val) throw new Error(val + ' is not ok.')
120 equal: function (a,b) {
121 if (a != b) throw new Error(a + ' is not equal to ' + b)
123 notEqual: function (a,b) {
124 if (a == b) throw new Error(a + ' is equal to ' + b)
126 strictEqual: function (a,b) {
127 if (a !== b) throw new Error(a + ' is not strict equal to ' + b)
129 deepEqual: function (a,b) {
130 if (!_deepEqual(a,b))
131 throw new Error(JSON.stringify(a) + ' is not deep equal to ' +
135 log(testName + ' <span style="color:blue">is ok</span>.');
140 log(testName + ' <span style="color:red">FAIL.</span> <small>'+ e +'</small>');