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