diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
commit | abd94a7f5a50f43c797a11b53549ae48fff667c3 (patch) | |
tree | ab8ed457f65cdd72e13e0571d2975729428f1551 /node_modules/clone/test.html | |
parent | a0247c6a3fd6a09a41a7e35a3441324c4dcb58be (diff) |
add node_modules to address #4364
Diffstat (limited to 'node_modules/clone/test.html')
-rw-r--r-- | node_modules/clone/test.html | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/node_modules/clone/test.html b/node_modules/clone/test.html new file mode 100644 index 000000000..a95570251 --- /dev/null +++ b/node_modules/clone/test.html @@ -0,0 +1,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> |