Home page Forum Wiki Mail Jabber Devel NIX-FILES

AltLUG Git

Git-repositories of Altai Linux User Group

Lint: Tighten .jshintrc options and enforce them.
[qunit.git] / test / deepEqual.js
1 module("equiv");
2
3
4 test("Primitive types and constants", function () {
5         equal(QUnit.equiv(null, null), true, "null");
6         equal(QUnit.equiv(null, {}), false, "null");
7         equal(QUnit.equiv(null, undefined), false, "null");
8         equal(QUnit.equiv(null, 0), false, "null");
9         equal(QUnit.equiv(null, false), false, "null");
10         equal(QUnit.equiv(null, ''), false, "null");
11         equal(QUnit.equiv(null, []), false, "null");
12
13         equal(QUnit.equiv(undefined, undefined), true, "undefined");
14         equal(QUnit.equiv(undefined, null), false, "undefined");
15         equal(QUnit.equiv(undefined, 0), false, "undefined");
16         equal(QUnit.equiv(undefined, false), false, "undefined");
17         equal(QUnit.equiv(undefined, {}), false, "undefined");
18         equal(QUnit.equiv(undefined, []), false, "undefined");
19         equal(QUnit.equiv(undefined, ""), false, "undefined");
20
21         // Nan usually doest not equal to Nan using the '==' operator.
22         // Only isNaN() is able to do it.
23         equal(QUnit.equiv(0/0, 0/0), true, "NaN"); // NaN VS NaN
24         equal(QUnit.equiv(1/0, 2/0), true, "Infinity"); // Infinity VS Infinity
25         equal(QUnit.equiv(-1/0, 2/0), false, "-Infinity, Infinity"); // -Infinity VS Infinity
26         equal(QUnit.equiv(-1/0, -2/0), true, "-Infinity, -Infinity"); // -Infinity VS -Infinity
27         equal(QUnit.equiv(0/0, 1/0), false, "NaN, Infinity"); // Nan VS Infinity
28         equal(QUnit.equiv(1/0, 0/0), false, "NaN, Infinity"); // Nan VS Infinity
29         equal(QUnit.equiv(0/0, null), false, "NaN");
30         equal(QUnit.equiv(0/0, undefined), false, "NaN");
31         equal(QUnit.equiv(0/0, 0), false, "NaN");
32         equal(QUnit.equiv(0/0, false), false, "NaN");
33         equal(QUnit.equiv(0/0, function () {}), false, "NaN");
34         equal(QUnit.equiv(1/0, null), false, "NaN, Infinity");
35         equal(QUnit.equiv(1/0, undefined), false, "NaN, Infinity");
36         equal(QUnit.equiv(1/0, 0), false, "NaN, Infinity");
37         equal(QUnit.equiv(1/0, 1), false, "NaN, Infinity");
38         equal(QUnit.equiv(1/0, false), false, "NaN, Infinity");
39         equal(QUnit.equiv(1/0, true), false, "NaN, Infinity");
40         equal(QUnit.equiv(1/0, function () {}), false, "NaN, Infinity");
41
42         equal(QUnit.equiv(0, 0), true, "number");
43         equal(QUnit.equiv(0, 1), false, "number");
44         equal(QUnit.equiv(1, 0), false, "number");
45         equal(QUnit.equiv(1, 1), true, "number");
46         equal(QUnit.equiv(1.1, 1.1), true, "number");
47         equal(QUnit.equiv(0.0000005, 0.0000005), true, "number");
48         equal(QUnit.equiv(0, ''), false, "number");
49         equal(QUnit.equiv(0, '0'), false, "number");
50         equal(QUnit.equiv(1, '1'), false, "number");
51         equal(QUnit.equiv(0, false), false, "number");
52         equal(QUnit.equiv(1, true), false, "number");
53
54         equal(QUnit.equiv(true, true), true, "boolean");
55         equal(QUnit.equiv(true, false), false, "boolean");
56         equal(QUnit.equiv(false, true), false, "boolean");
57         equal(QUnit.equiv(false, 0), false, "boolean");
58         equal(QUnit.equiv(false, null), false, "boolean");
59         equal(QUnit.equiv(false, undefined), false, "boolean");
60         equal(QUnit.equiv(true, 1), false, "boolean");
61         equal(QUnit.equiv(true, null), false, "boolean");
62         equal(QUnit.equiv(true, undefined), false, "boolean");
63
64         equal(QUnit.equiv('', ''), true, "string");
65         equal(QUnit.equiv('a', 'a'), true, "string");
66         equal(QUnit.equiv("foobar", "foobar"), true, "string");
67         equal(QUnit.equiv("foobar", "foo"), false, "string");
68         equal(QUnit.equiv('', 0), false, "string");
69         equal(QUnit.equiv('', false), false, "string");
70         equal(QUnit.equiv('', null), false, "string");
71         equal(QUnit.equiv('', undefined), false, "string");
72
73         // Rename for lint validation.
74         // We know this is bad, we are asserting whether we can coop with bad code like this.
75         var SafeNumber = Number, SafeString = String, SafeBoolean = Boolean, SafeObject = Object;
76
77         // primitives vs. objects
78
79         equal(QUnit.equiv(0, new SafeNumber()), true, "primitives vs. objects");
80         equal(QUnit.equiv(new SafeNumber(), 0), true, "primitives vs. objects");
81         equal(QUnit.equiv(1, new SafeNumber(1)), true, "primitives vs. objects");
82         equal(QUnit.equiv(new SafeNumber(1), 1), true, "primitives vs. objects");
83         equal(QUnit.equiv(new SafeNumber(0), 1), false, "primitives vs. objects");
84         equal(QUnit.equiv(0, new SafeNumber(1)), false, "primitives vs. objects");
85
86         equal(QUnit.equiv(new SafeString(), ""), true, "primitives vs. objects");
87         equal(QUnit.equiv("", new SafeString()), true, "primitives vs. objects");
88         equal(QUnit.equiv(new SafeString("My String"), "My String"), true, "primitives vs. objects");
89         equal(QUnit.equiv("My String", new SafeString("My String")), true, "primitives vs. objects");
90         equal(QUnit.equiv("Bad String", new SafeString("My String")), false, "primitives vs. objects");
91         equal(QUnit.equiv(new SafeString("Bad String"), "My String"), false, "primitives vs. objects");
92
93         equal(QUnit.equiv(false, new SafeBoolean()), true, "primitives vs. objects");
94         equal(QUnit.equiv(new SafeBoolean(), false), true, "primitives vs. objects");
95         equal(QUnit.equiv(true, new SafeBoolean(true)), true, "primitives vs. objects");
96         equal(QUnit.equiv(new SafeBoolean(true), true), true, "primitives vs. objects");
97         equal(QUnit.equiv(true, new SafeBoolean(1)), true, "primitives vs. objects");
98         equal(QUnit.equiv(false, new SafeBoolean(false)), true, "primitives vs. objects");
99         equal(QUnit.equiv(new SafeBoolean(false), false), true, "primitives vs. objects");
100         equal(QUnit.equiv(false, new SafeBoolean(0)), true, "primitives vs. objects");
101         equal(QUnit.equiv(true, new SafeBoolean(false)), false, "primitives vs. objects");
102         equal(QUnit.equiv(new SafeBoolean(false), true), false, "primitives vs. objects");
103
104         equal(QUnit.equiv(new SafeObject(), {}), true, "object literal vs. instantiation");
105         equal(QUnit.equiv({}, new SafeObject()), true, "object literal vs. instantiation");
106         equal(QUnit.equiv(new SafeObject(), {a:1}), false, "object literal vs. instantiation");
107         equal(QUnit.equiv({a:1}, new SafeObject()), false, "object literal vs. instantiation");
108         equal(QUnit.equiv({a:undefined}, new SafeObject()), false, "object literal vs. instantiation");
109         equal(QUnit.equiv(new SafeObject(), {a:undefined}), false, "object literal vs. instantiation");
110 });
111
112 test("Objects Basics.", function() {
113         equal(QUnit.equiv({}, {}), true);
114         equal(QUnit.equiv({}, null), false);
115         equal(QUnit.equiv({}, undefined), false);
116         equal(QUnit.equiv({}, 0), false);
117         equal(QUnit.equiv({}, false), false);
118
119         // This test is a hard one, it is very important
120         // REASONS:
121         //      1) They are of the same type "object"
122         //      2) [] instanceof Object is true
123         //      3) Their properties are the same (doesn't exists)
124         equal(QUnit.equiv({}, []), false);
125
126         equal(QUnit.equiv({a:1}, {a:1}), true);
127         equal(QUnit.equiv({a:1}, {a:"1"}), false);
128         equal(QUnit.equiv({a:[]}, {a:[]}), true);
129         equal(QUnit.equiv({a:{}}, {a:null}), false);
130         equal(QUnit.equiv({a:1}, {}), false);
131         equal(QUnit.equiv({}, {a:1}), false);
132
133         // Hard ones
134         equal(QUnit.equiv({a:undefined}, {}), false);
135         equal(QUnit.equiv({}, {a:undefined}), false);
136         equal(QUnit.equiv(
137                 {
138                         a: [{ bar: undefined }]
139                 },
140                 {
141                         a: [{ bat: undefined }]
142                 }
143         ), false);
144
145         // Objects with no prototype, created via Object.create(null), are used e.g. as dictionaries.
146         // Being able to test equivalence against object literals is quite useful.
147         if (typeof Object.create === 'function') {
148                 equal(QUnit.equiv(Object.create(null), {}), true, "empty object without prototype VS empty object");
149
150                 var nonEmptyWithNoProto = Object.create(null);
151                 nonEmptyWithNoProto.foo = "bar";
152
153                 equal(QUnit.equiv(nonEmptyWithNoProto, { foo: "bar" }), true, "object without prototype VS object");
154         }
155 });
156
157
158 test("Arrays Basics.", function() {
159
160         equal(QUnit.equiv([], []), true);
161
162         // May be a hard one, can invoke a crash at execution.
163         // because their types are both "object" but null isn't
164         // like a true object, it doesn't have any property at all.
165         equal(QUnit.equiv([], null), false);
166
167         equal(QUnit.equiv([], undefined), false);
168         equal(QUnit.equiv([], false), false);
169         equal(QUnit.equiv([], 0), false);
170         equal(QUnit.equiv([], ""), false);
171
172         // May be a hard one, but less hard
173         // than {} with [] (note the order)
174         equal(QUnit.equiv([], {}), false);
175
176         equal(QUnit.equiv([null],[]), false);
177         equal(QUnit.equiv([undefined],[]), false);
178         equal(QUnit.equiv([],[null]), false);
179         equal(QUnit.equiv([],[undefined]), false);
180         equal(QUnit.equiv([null],[undefined]), false);
181         equal(QUnit.equiv([[]],[[]]), true);
182         equal(QUnit.equiv([[],[],[]],[[],[],[]]), true);
183         equal(QUnit.equiv(
184                                                         [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]],
185                                                         [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]),
186                                                         true);
187         equal(QUnit.equiv(
188                                                         [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]],
189                                                         [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), // shorter
190                                                         false);
191         equal(QUnit.equiv(
192                                                         [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]],
193                                                         [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), // deepest element not an array
194                                                         false);
195
196         // same multidimensional
197         equal(QUnit.equiv(
198                                                         [1,2,3,4,5,6,7,8,9, [
199                                                                 1,2,3,4,5,6,7,8,9, [
200                                                                         1,2,3,4,5,[
201                                                                                 [6,7,8,9, [
202                                                                                         [
203                                                                                                 1,2,3,4,[
204                                                                                                         2,3,4,[
205                                                                                                                 1,2,[
206                                                                                                                         1,2,3,4,[
207                                                                                                                                 1,2,3,4,5,6,7,8,9,[
208                                                                                                                                         0
209                                                                                                                                 ],1,2,3,4,5,6,7,8,9
210                                                                                                                         ],5,6,7,8,9
211                                                                                                                 ],4,5,6,7,8,9
212                                                                                                         ],5,6,7,8,9
213                                                                                                 ],5,6,7
214                                                                                         ]
215                                                                                 ]
216                                                                         ]
217                                                                 ]
218                                                         ]]],
219                                                         [1,2,3,4,5,6,7,8,9, [
220                                                                 1,2,3,4,5,6,7,8,9, [
221                                                                         1,2,3,4,5,[
222                                                                                 [6,7,8,9, [
223                                                                                         [
224                                                                                                 1,2,3,4,[
225                                                                                                         2,3,4,[
226                                                                                                                 1,2,[
227                                                                                                                         1,2,3,4,[
228                                                                                                                                 1,2,3,4,5,6,7,8,9,[
229                                                                                                                                         0
230                                                                                                                                 ],1,2,3,4,5,6,7,8,9
231                                                                                                                         ],5,6,7,8,9
232                                                                                                                 ],4,5,6,7,8,9
233                                                                                                         ],5,6,7,8,9
234                                                                                                 ],5,6,7
235                                                                                         ]
236                                                                                 ]
237                                                                         ]
238                                                                 ]
239                                                         ]]]),
240                                                         true, "Multidimensional");
241
242         // different multidimensional
243         equal(QUnit.equiv(
244                                                         [1,2,3,4,5,6,7,8,9, [
245                                                                 1,2,3,4,5,6,7,8,9, [
246                                                                         1,2,3,4,5,[
247                                                                                 [6,7,8,9, [
248                                                                                         [
249                                                                                                 1,2,3,4,[
250                                                                                                         2,3,4,[
251                                                                                                                 1,2,[
252                                                                                                                         1,2,3,4,[
253                                                                                                                                 1,2,3,4,5,6,7,8,9,[
254                                                                                                                                         0
255                                                                                                                                 ],1,2,3,4,5,6,7,8,9
256                                                                                                                         ],5,6,7,8,9
257                                                                                                                 ],4,5,6,7,8,9
258                                                                                                         ],5,6,7,8,9
259                                                                                                 ],5,6,7
260                                                                                         ]
261                                                                                 ]
262                                                                         ]
263                                                                 ]
264                                                         ]]],
265                                                         [1,2,3,4,5,6,7,8,9, [
266                                                                 1,2,3,4,5,6,7,8,9, [
267                                                                         1,2,3,4,5,[
268                                                                                 [6,7,8,9, [
269                                                                                         [
270                                                                                                 1,2,3,4,[
271                                                                                                         2,3,4,[
272                                                                                                                 1,2,[
273                                                                                                                         '1',2,3,4,[                 // string instead of number
274                                                                                                                                 1,2,3,4,5,6,7,8,9,[
275                                                                                                                                         0
276                                                                                                                                 ],1,2,3,4,5,6,7,8,9
277                                                                                                                         ],5,6,7,8,9
278                                                                                                                 ],4,5,6,7,8,9
279                                                                                                         ],5,6,7,8,9
280                                                                                                 ],5,6,7
281                                                                                         ]
282                                                                                 ]
283                                                                         ]
284                                                                 ]
285                                                         ]]]),
286                                                         false, "Multidimensional");
287
288         // different multidimensional
289         equal(QUnit.equiv(
290                                                         [1,2,3,4,5,6,7,8,9, [
291                                                                 1,2,3,4,5,6,7,8,9, [
292                                                                         1,2,3,4,5,[
293                                                                                 [6,7,8,9, [
294                                                                                         [
295                                                                                                 1,2,3,4,[
296                                                                                                         2,3,4,[
297                                                                                                                 1,2,[
298                                                                                                                         1,2,3,4,[
299                                                                                                                                 1,2,3,4,5,6,7,8,9,[
300                                                                                                                                         0
301                                                                                                                                 ],1,2,3,4,5,6,7,8,9
302                                                                                                                         ],5,6,7,8,9
303                                                                                                                 ],4,5,6,7,8,9
304                                                                                                         ],5,6,7,8,9
305                                                                                                 ],5,6,7
306                                                                                         ]
307                                                                                 ]
308                                                                         ]
309                                                                 ]
310                                                         ]]],
311                                                         [1,2,3,4,5,6,7,8,9, [
312                                                                 1,2,3,4,5,6,7,8,9, [
313                                                                         1,2,3,4,5,[
314                                                                                 [6,7,8,9, [
315                                                                                         [
316                                                                                                 1,2,3,4,[
317                                                                                                         2,3,[                   // missing an element (4)
318                                                                                                                 1,2,[
319                                                                                                                         1,2,3,4,[
320                                                                                                                                 1,2,3,4,5,6,7,8,9,[
321                                                                                                                                         0
322                                                                                                                                 ],1,2,3,4,5,6,7,8,9
323                                                                                                                         ],5,6,7,8,9
324                                                                                                                 ],4,5,6,7,8,9
325                                                                                                         ],5,6,7,8,9
326                                                                                                 ],5,6,7
327                                                                                         ]
328                                                                                 ]
329                                                                         ]
330                                                                 ]
331                                                         ]]]),
332                                                         false, "Multidimensional");
333 });
334
335 test("Functions.", function() {
336         var f0 = function () {};
337         var f1 = function () {};
338
339         // f2 and f3 have the same code, formatted differently
340         var f2 = function () {var i = 0;};
341         var f3 = function () {
342                 /*jshint asi:true */
343                 var i = 0 // this comment and no semicoma as difference
344         };
345
346         equal(QUnit.equiv(function() {}, function() {}), false, "Anonymous functions"); // exact source code
347         equal(QUnit.equiv(function() {}, function() {return true;}), false, "Anonymous functions");
348
349         equal(QUnit.equiv(f0, f0), true, "Function references"); // same references
350         equal(QUnit.equiv(f0, f1), false, "Function references"); // exact source code, different references
351         equal(QUnit.equiv(f2, f3), false, "Function references"); // equivalent source code, different references
352         equal(QUnit.equiv(f1, f2), false, "Function references"); // different source code, different references
353         equal(QUnit.equiv(function() {}, true), false);
354         equal(QUnit.equiv(function() {}, undefined), false);
355         equal(QUnit.equiv(function() {}, null), false);
356         equal(QUnit.equiv(function() {}, {}), false);
357 });
358
359
360 test("Date instances.", function() {
361         // Date, we don't need to test Date.parse() because it returns a number.
362         // Only test the Date instances by setting them a fix date.
363         // The date use is midnight January 1, 1970
364
365         var d1 = new Date();
366         d1.setTime(0); // fix the date
367
368         var d2 = new Date();
369         d2.setTime(0); // fix the date
370
371         var d3 = new Date(); // The very now
372
373         // Anyway their types differs, just in case the code fails in the order in which it deals with date
374         equal(QUnit.equiv(d1, 0), false); // d1.valueOf() returns 0, but d1 and 0 are different
375         // test same values date and different instances equality
376         equal(QUnit.equiv(d1, d2), true);
377         // test different date and different instances difference
378         equal(QUnit.equiv(d1, d3), false);
379 });
380
381
382 test("RegExp.", function() {
383         // Must test cases that imply those traps:
384         // var a = /./;
385         // a instanceof Object;        // Oops
386         // a instanceof RegExp;        // Oops
387         // typeof a === "function";    // Oops, false in IE and Opera, true in FF and Safari ("object")
388
389         // Tests same regex with same modifiers in different order
390         var r = /foo/;
391         var r5 = /foo/gim;
392         var r6 = /foo/gmi;
393         var r7 = /foo/igm;
394         var r8 = /foo/img;
395         var r9 = /foo/mig;
396         var r10 = /foo/mgi;
397         var ri1 = /foo/i;
398         var ri2 = /foo/i;
399         var rm1 = /foo/m;
400         var rm2 = /foo/m;
401         var rg1 = /foo/g;
402         var rg2 = /foo/g;
403
404         equal(QUnit.equiv(r5, r6), true, "Modifier order");
405         equal(QUnit.equiv(r5, r7), true, "Modifier order");
406         equal(QUnit.equiv(r5, r8), true, "Modifier order");
407         equal(QUnit.equiv(r5, r9), true, "Modifier order");
408         equal(QUnit.equiv(r5, r10), true, "Modifier order");
409         equal(QUnit.equiv(r, r5), false, "Modifier");
410
411         equal(QUnit.equiv(ri1, ri2), true, "Modifier");
412         equal(QUnit.equiv(r, ri1), false, "Modifier");
413         equal(QUnit.equiv(ri1, rm1), false, "Modifier");
414         equal(QUnit.equiv(r, rm1), false, "Modifier");
415         equal(QUnit.equiv(rm1, ri1), false, "Modifier");
416         equal(QUnit.equiv(rm1, rm2), true, "Modifier");
417         equal(QUnit.equiv(rg1, rm1), false, "Modifier");
418         equal(QUnit.equiv(rm1, rg1), false, "Modifier");
419         equal(QUnit.equiv(rg1, rg2), true, "Modifier");
420
421         // Different regex, same modifiers
422         var r11 = /[a-z]/gi;
423         var r13 = /[0-9]/gi; // oops! different
424         equal(QUnit.equiv(r11, r13), false, "Regex pattern");
425
426         var r14 = /0/ig;
427         var r15 = /"0"/ig; // oops! different
428         equal(QUnit.equiv(r14, r15), false, "Regex pattern");
429
430         var r1 = /[\n\r\u2028\u2029]/g;
431         var r2 = /[\n\r\u2028\u2029]/g;
432         var r3 = /[\n\r\u2028\u2028]/g; // differs from r1
433         var r4 = /[\n\r\u2028\u2029]/;  // differs from r1
434
435         equal(QUnit.equiv(r1, r2), true, "Regex pattern");
436         equal(QUnit.equiv(r1, r3), false, "Regex pattern");
437         equal(QUnit.equiv(r1, r4), false, "Regex pattern");
438
439         // More complex regex
440         var regex1 = "^[-_.a-z0-9]+@([-_a-z0-9]+\\.)+([A-Za-z][A-Za-z]|[A-Za-z][A-Za-z][A-Za-z])|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$";
441         var regex2 = "^[-_.a-z0-9]+@([-_a-z0-9]+\\.)+([A-Za-z][A-Za-z]|[A-Za-z][A-Za-z][A-Za-z])|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$";
442         // regex 3 is different: '.' not escaped
443         var regex3 = "^[-_.a-z0-9]+@([-_a-z0-9]+.)+([A-Za-z][A-Za-z]|[A-Za-z][A-Za-z][A-Za-z])|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$";
444
445         var r21 = new RegExp(regex1);
446         var r22 = new RegExp(regex2);
447         var r23 = new RegExp(regex3); // diff from r21, not same pattern
448         var r23a = new RegExp(regex3, "gi"); // diff from r23, not same modifier
449         var r24a = new RegExp(regex3, "ig"); // same as r23a
450
451         equal(QUnit.equiv(r21, r22), true, "Complex Regex");
452         equal(QUnit.equiv(r21, r23), false, "Complex Regex");
453         equal(QUnit.equiv(r23, r23a), false, "Complex Regex");
454         equal(QUnit.equiv(r23a, r24a), true, "Complex Regex");
455
456         // typeof r1 is "function" in some browsers and "object" in others so we must cover this test
457         var re = / /;
458         equal(QUnit.equiv(re, function () {}), false, "Regex internal");
459         equal(QUnit.equiv(re, {}), false, "Regex internal");
460 });
461
462
463 test("Complex Objects.", function() {
464
465         function fn1() {
466                 return "fn1";
467         }
468         function fn2() {
469                 return "fn2";
470         }
471
472         // Try to invert the order of some properties to make sure it is covered.
473         // It can failed when properties are compared between unsorted arrays.
474         equal(QUnit.equiv(
475                 {
476                         a: 1,
477                         b: null,
478                         c: [{}],
479                         d: {
480                                 a: 3.14159,
481                                 b: false,
482                                 c: {
483                                         e: fn1,
484                                         f: [[[]]],
485                                         g: {
486                                                 j: {
487                                                         k: {
488                                                                 n: {
489                                                                         r: "r",
490                                                                         s: [1,2,3],
491                                                                         t: undefined,
492                                                                         u: 0,
493                                                                         v: {
494                                                                                 w: {
495                                                                                         x: {
496                                                                                                 y: "Yahoo!",
497                                                                                                 z: null
498                                                                                         }
499                                                                                 }
500                                                                         }
501                                                                 },
502                                                                 q: [],
503                                                                 p: 1/0,
504                                                                 o: 99
505                                                         },
506                                                         l: undefined,
507                                                         m: null
508                                                 }
509                                         },
510                                         d: 0,
511                                         i: true,
512                                         h: "false"
513                                 }
514                         },
515                         e: undefined,
516                         g: "",
517                         h: "h",
518                         f: {},
519                         i: []
520                 },
521                 {
522                         a: 1,
523                         b: null,
524                         c: [{}],
525                         d: {
526                                 b: false,
527                                 a: 3.14159,
528                                 c: {
529                                         d: 0,
530                                         e: fn1,
531                                         f: [[[]]],
532                                         g: {
533                                                 j: {
534                                                         k: {
535                                                                 n: {
536                                                                         r: "r",
537                                                                         t: undefined,
538                                                                         u: 0,
539                                                                         s: [1,2,3],
540                                                                         v: {
541                                                                                 w: {
542                                                                                         x: {
543                                                                                                 z: null,
544                                                                                                 y: "Yahoo!"
545                                                                                         }
546                                                                                 }
547                                                                         }
548                                                                 },
549                                                                 o: 99,
550                                                                 p: 1/0,
551                                                                 q: []
552                                                         },
553                                                         l: undefined,
554                                                         m: null
555                                                 }
556                                         },
557                                         i: true,
558                                         h: "false"
559                                 }
560                         },
561                         e: undefined,
562                         g: "",
563                         f: {},
564                         h: "h",
565                         i: []
566                 }
567         ), true);
568
569         equal(QUnit.equiv(
570                 {
571                         a: 1,
572                         b: null,
573                         c: [{}],
574                         d: {
575                                 a: 3.14159,
576                                 b: false,
577                                 c: {
578                                         d: 0,
579                                         e: fn1,
580                                         f: [[[]]],
581                                         g: {
582                                                 j: {
583                                                         k: {
584                                                                 n: {
585                                                                         //r: "r",   // different: missing a property
586                                                                         s: [1,2,3],
587                                                                         t: undefined,
588                                                                         u: 0,
589                                                                         v: {
590                                                                                 w: {
591                                                                                         x: {
592                                                                                                 y: "Yahoo!",
593                                                                                                 z: null
594                                                                                         }
595                                                                                 }
596                                                                         }
597                                                                 },
598                                                                 o: 99,
599                                                                 p: 1/0,
600                                                                 q: []
601                                                         },
602                                                         l: undefined,
603                                                         m: null
604                                                 }
605                                         },
606                                         h: "false",
607                                         i: true
608                                 }
609                         },
610                         e: undefined,
611                         f: {},
612                         g: "",
613                         h: "h",
614                         i: []
615                 },
616                 {
617                         a: 1,
618                         b: null,
619                         c: [{}],
620                         d: {
621                                 a: 3.14159,
622                                 b: false,
623                                 c: {
624                                         d: 0,
625                                         e: fn1,
626                                         f: [[[]]],
627                                         g: {
628                                                 j: {
629                                                         k: {
630                                                                 n: {
631                                                                         r: "r",
632                                                                         s: [1,2,3],
633                                                                         t: undefined,
634                                                                         u: 0,
635                                                                         v: {
636                                                                                 w: {
637                                                                                         x: {
638                                                                                                 y: "Yahoo!",
639                                                                                                 z: null
640                                                                                         }
641                                                                                 }
642                                                                         }
643                                                                 },
644                                                                 o: 99,
645                                                                 p: 1/0,
646                                                                 q: []
647                                                         },
648                                                         l: undefined,
649                                                         m: null
650                                                 }
651                                         },
652                                         h: "false",
653                                         i: true
654                                 }
655                         },
656                         e: undefined,
657                         f: {},
658                         g: "",
659                         h: "h",
660                         i: []
661                 }
662         ), false);
663
664         equal(QUnit.equiv(
665                 {
666                         a: 1,
667                         b: null,
668                         c: [{}],
669                         d: {
670                                 a: 3.14159,
671                                 b: false,
672                                 c: {
673                                         d: 0,
674                                         e: fn1,
675                                         f: [[[]]],
676                                         g: {
677                                                 j: {
678                                                         k: {
679                                                                 n: {
680                                                                         r: "r",
681                                                                         s: [1,2,3],
682                                                                         t: undefined,
683                                                                         u: 0,
684                                                                         v: {
685                                                                                 w: {
686                                                                                         x: {
687                                                                                                 y: "Yahoo!",
688                                                                                                 z: null
689                                                                                         }
690                                                                                 }
691                                                                         }
692                                                                 },
693                                                                 o: 99,
694                                                                 p: 1/0,
695                                                                 q: []
696                                                         },
697                                                         l: undefined,
698                                                         m: null
699                                                 }
700                                         },
701                                         h: "false",
702                                         i: true
703                                 }
704                         },
705                         e: undefined,
706                         f: {},
707                         g: "",
708                         h: "h",
709                         i: []
710                 },
711                 {
712                         a: 1,
713                         b: null,
714                         c: [{}],
715                         d: {
716                                 a: 3.14159,
717                                 b: false,
718                                 c: {
719                                         d: 0,
720                                         e: fn1,
721                                         f: [[[]]],
722                                         g: {
723                                                 j: {
724                                                         k: {
725                                                                 n: {
726                                                                         r: "r",
727                                                                         s: [1,2,3],
728                                                                         //t: undefined,                 // different: missing a property with an undefined value
729                                                                         u: 0,
730                                                                         v: {
731                                                                                 w: {
732                                                                                         x: {
733                                                                                                 y: "Yahoo!",
734                                                                                                 z: null
735                                                                                         }
736                                                                                 }
737                                                                         }
738                                                                 },
739                                                                 o: 99,
740                                                                 p: 1/0,
741                                                                 q: []
742                                                         },
743                                                         l: undefined,
744                                                         m: null
745                                                 }
746                                         },
747                                         h: "false",
748                                         i: true
749                                 }
750                         },
751                         e: undefined,
752                         f: {},
753                         g: "",
754                         h: "h",
755                         i: []
756                 }
757         ), false);
758
759         equal(QUnit.equiv(
760                 {
761                         a: 1,
762                         b: null,
763                         c: [{}],
764                         d: {
765                                 a: 3.14159,
766                                 b: false,
767                                 c: {
768                                         d: 0,
769                                         e: fn1,
770                                         f: [[[]]],
771                                         g: {
772                                                 j: {
773                                                         k: {
774                                                                 n: {
775                                                                         r: "r",
776                                                                         s: [1,2,3],
777                                                                         t: undefined,
778                                                                         u: 0,
779                                                                         v: {
780                                                                                 w: {
781                                                                                         x: {
782                                                                                                 y: "Yahoo!",
783                                                                                                 z: null
784                                                                                         }
785                                                                                 }
786                                                                         }
787                                                                 },
788                                                                 o: 99,
789                                                                 p: 1/0,
790                                                                 q: []
791                                                         },
792                                                         l: undefined,
793                                                         m: null
794                                                 }
795                                         },
796                                         h: "false",
797                                         i: true
798                                 }
799                         },
800                         e: undefined,
801                         f: {},
802                         g: "",
803                         h: "h",
804                         i: []
805                 },
806                 {
807                         a: 1,
808                         b: null,
809                         c: [{}],
810                         d: {
811                                 a: 3.14159,
812                                 b: false,
813                                 c: {
814                                         d: 0,
815                                         e: fn1,
816                                         f: [[[]]],
817                                         g: {
818                                                 j: {
819                                                         k: {
820                                                                 n: {
821                                                                         r: "r",
822                                                                         s: [1,2,3],
823                                                                         t: undefined,
824                                                                         u: 0,
825                                                                         v: {
826                                                                                 w: {
827                                                                                         x: {
828                                                                                                 y: "Yahoo!",
829                                                                                                 z: null
830                                                                                         }
831                                                                                 }
832                                                                         }
833                                                                 },
834                                                                 o: 99,
835                                                                 p: 1/0,
836                                                                 q: {}           // different was []
837                                                         },
838                                                         l: undefined,
839                                                         m: null
840                                                 }
841                                         },
842                                         h: "false",
843                                         i: true
844                                 }
845                         },
846                         e: undefined,
847                         f: {},
848                         g: "",
849                         h: "h",
850                         i: []
851                 }
852         ), false);
853
854         var same1 = {
855                 a: [
856                         "string", null, 0, "1", 1, {
857                                 prop: null,
858                                 foo: [1,2,null,{}, [], [1,2,3]],
859                                 bar: undefined
860                         }, 3, "Hey!", "Κάνε Ï€Î¬Î½Ï„α Î³Î½Ï‰Ïίζουμε Î±Ï‚ Ï„ων, Î¼Î·Ï‡Î±Î½Î®Ï‚ ÎµÏ€Î¹Î´Î¹ÏŒÏθωσης ÎµÏ€Î¹Î´Î¹Î¿Ïθώσεις ÏŽÏ‚ Î¼Î¹Î±. ÎšÎ»Ï€ Î±Ï‚"
861                 ],
862                 unicode: "耠汉è¯ä¸å˜åœ¨ æ¸¯æ¾³å’Œæµ·å¤–çš„åŽäººåœˆä¸ è´µå·ž æˆ‘去了书店 çŽ°åœ¨å°šæœ‰äº‰",
863                 b: "b",
864                 c: fn1
865         };
866
867         var same2 = {
868                 a: [
869                         "string", null, 0, "1", 1, {
870                                 prop: null,
871                                 foo: [1,2,null,{}, [], [1,2,3]],
872                                 bar: undefined
873                         }, 3, "Hey!", "Κάνε Ï€Î¬Î½Ï„α Î³Î½Ï‰Ïίζουμε Î±Ï‚ Ï„ων, Î¼Î·Ï‡Î±Î½Î®Ï‚ ÎµÏ€Î¹Î´Î¹ÏŒÏθωσης ÎµÏ€Î¹Î´Î¹Î¿Ïθώσεις ÏŽÏ‚ Î¼Î¹Î±. ÎšÎ»Ï€ Î±Ï‚"
874                 ],
875                 unicode: "耠汉è¯ä¸å˜åœ¨ æ¸¯æ¾³å’Œæµ·å¤–çš„åŽäººåœˆä¸ è´µå·ž æˆ‘去了书店 çŽ°åœ¨å°šæœ‰äº‰",
876                 b: "b",
877                 c: fn1
878         };
879
880         var diff1 = {
881                 a: [
882                         "string", null, 0, "1", 1, {
883                                 prop: null,
884                                 foo: [1,2,null,{}, [], [1,2,3,4]], // different: 4 was add to the array
885                                 bar: undefined
886                         }, 3, "Hey!", "Κάνε Ï€Î¬Î½Ï„α Î³Î½Ï‰Ïίζουμε Î±Ï‚ Ï„ων, Î¼Î·Ï‡Î±Î½Î®Ï‚ ÎµÏ€Î¹Î´Î¹ÏŒÏθωσης ÎµÏ€Î¹Î´Î¹Î¿Ïθώσεις ÏŽÏ‚ Î¼Î¹Î±. ÎšÎ»Ï€ Î±Ï‚"
887                 ],
888                 unicode: "耠汉è¯ä¸å˜åœ¨ æ¸¯æ¾³å’Œæµ·å¤–çš„åŽäººåœˆä¸ è´µå·ž æˆ‘去了书店 çŽ°åœ¨å°šæœ‰äº‰",
889                 b: "b",
890                 c: fn1
891         };
892
893         var diff2 = {
894                 a: [
895                         "string", null, 0, "1", 1, {
896                                 prop: null,
897                                 foo: [1,2,null,{}, [], [1,2,3]],
898                                 newprop: undefined, // different: newprop was added
899                                 bar: undefined
900                         }, 3, "Hey!", "Κάνε Ï€Î¬Î½Ï„α Î³Î½Ï‰Ïίζουμε Î±Ï‚ Ï„ων, Î¼Î·Ï‡Î±Î½Î®Ï‚ ÎµÏ€Î¹Î´Î¹ÏŒÏθωσης ÎµÏ€Î¹Î´Î¹Î¿Ïθώσεις ÏŽÏ‚ Î¼Î¹Î±. ÎšÎ»Ï€ Î±Ï‚"
901                 ],
902                 unicode: "耠汉è¯ä¸å˜åœ¨ æ¸¯æ¾³å’Œæµ·å¤–çš„åŽäººåœˆä¸ è´µå·ž æˆ‘去了书店 çŽ°åœ¨å°šæœ‰äº‰",
903                 b: "b",
904                 c: fn1
905         };
906
907         var diff3 = {
908                 a: [
909                         "string", null, 0, "1", 1, {
910                                 prop: null,
911                                 foo: [1,2,null,{}, [], [1,2,3]],
912                                 bar: undefined
913                         }, 3, "Hey!", "Κάνε Ï€Î¬Î½Ï„α Î³Î½Ï‰Ïίζουμε Î±Ï‚ Ï„ων, Î¼Î·Ï‡Î±Î½Î®Ï‚ ÎµÏ€Î¹Î´Î¹ÏŒÏθωσης ÎµÏ€Î¹Î´Î¹Î¿Ïθώσεις ÏŽÏ‚ Î¼Î¹Î±. ÎšÎ»Ï€ Î±" // different: missing last char
914                 ],
915                 unicode: "耠汉è¯ä¸å˜åœ¨ æ¸¯æ¾³å’Œæµ·å¤–çš„åŽäººåœˆä¸ è´µå·ž æˆ‘去了书店 çŽ°åœ¨å°šæœ‰äº‰",
916                 b: "b",
917                 c: fn1
918         };
919
920         var diff4 = {
921                 a: [
922                         "string", null, 0, "1", 1, {
923                                 prop: null,
924                                 foo: [1,2,undefined,{}, [], [1,2,3]], // different: undefined instead of null
925                                 bar: undefined
926                         }, 3, "Hey!", "Κάνε Ï€Î¬Î½Ï„α Î³Î½Ï‰Ïίζουμε Î±Ï‚ Ï„ων, Î¼Î·Ï‡Î±Î½Î®Ï‚ ÎµÏ€Î¹Î´Î¹ÏŒÏθωσης ÎµÏ€Î¹Î´Î¹Î¿Ïθώσεις ÏŽÏ‚ Î¼Î¹Î±. ÎšÎ»Ï€ Î±Ï‚"
927                 ],
928                 unicode: "耠汉è¯ä¸å˜åœ¨ æ¸¯æ¾³å’Œæµ·å¤–çš„åŽäººåœˆä¸ è´µå·ž æˆ‘去了书店 çŽ°åœ¨å°šæœ‰äº‰",
929                 b: "b",
930                 c: fn1
931         };
932
933         var diff5 = {
934                 a: [
935                         "string", null, 0, "1", 1, {
936                                 prop: null,
937                                 foo: [1,2,null,{}, [], [1,2,3]],
938                                 bat: undefined // different: property name not "bar"
939                         }, 3, "Hey!", "Κάνε Ï€Î¬Î½Ï„α Î³Î½Ï‰Ïίζουμε Î±Ï‚ Ï„ων, Î¼Î·Ï‡Î±Î½Î®Ï‚ ÎµÏ€Î¹Î´Î¹ÏŒÏθωσης ÎµÏ€Î¹Î´Î¹Î¿Ïθώσεις ÏŽÏ‚ Î¼Î¹Î±. ÎšÎ»Ï€ Î±Ï‚"
940                 ],
941                 unicode: "耠汉è¯ä¸å˜åœ¨ æ¸¯æ¾³å’Œæµ·å¤–çš„åŽäººåœˆä¸ è´µå·ž æˆ‘去了书店 çŽ°åœ¨å°šæœ‰äº‰",
942                 b: "b",
943                 c: fn1
944         };
945
946         equal(QUnit.equiv(same1, same2), true);
947         equal(QUnit.equiv(same2, same1), true);
948         equal(QUnit.equiv(same2, diff1), false);
949         equal(QUnit.equiv(diff1, same2), false);
950
951         equal(QUnit.equiv(same1, diff1), false);
952         equal(QUnit.equiv(same1, diff2), false);
953         equal(QUnit.equiv(same1, diff3), false);
954         equal(QUnit.equiv(same1, diff3), false);
955         equal(QUnit.equiv(same1, diff4), false);
956         equal(QUnit.equiv(same1, diff5), false);
957         equal(QUnit.equiv(diff5, diff1), false);
958 });
959
960
961 test("Complex Arrays.", function() {
962
963         function fn() {
964         }
965
966         equal(QUnit.equiv(
967                                 [1, 2, 3, true, {}, null, [
968                                         {
969                                                 a: ["", '1', 0]
970                                         },
971                                         5, 6, 7
972                                 ], "foo"],
973                                 [1, 2, 3, true, {}, null, [
974                                         {
975                                                 a: ["", '1', 0]
976                                         },
977                                         5, 6, 7
978                                 ], "foo"]),
979                         true);
980
981         equal(QUnit.equiv(
982                                 [1, 2, 3, true, {}, null, [
983                                         {
984                                                 a: ["", '1', 0]
985                                         },
986                                         5, 6, 7
987                                 ], "foo"],
988                                 [1, 2, 3, true, {}, null, [
989                                         {
990                                                 b: ["", '1', 0]         // not same property name
991                                         },
992                                         5, 6, 7
993                                 ], "foo"]),
994                         false);
995
996         var a = [{
997                 b: fn,
998                 c: false,
999                 "do": "reserved word",
1000                 "for": {
1001                         ar: [3,5,9,"hey!", [], {
1002                                 ar: [1,[
1003                                         3,4,6,9, null, [], []
1004                                 ]],
1005                                 e: fn,
1006                                 f: undefined
1007                         }]
1008                 },
1009                 e: 0.43445
1010         }, 5, "string", 0, fn, false, null, undefined, 0, [
1011                 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1012         ], [], [[[], "foo", null, {
1013                 n: 1/0,
1014                 z: {
1015                         a: [3,4,5,6,"yep!", undefined, undefined],
1016                         b: {}
1017                 }
1018         }, {}]]];
1019
1020         equal(QUnit.equiv(a,
1021                         [{
1022                                 b: fn,
1023                                 c: false,
1024                                 "do": "reserved word",
1025                                 "for": {
1026                                         ar: [3,5,9,"hey!", [], {
1027                                                 ar: [1,[
1028                                                         3,4,6,9, null, [], []
1029                                                 ]],
1030                                                 e: fn,
1031                                                 f: undefined
1032                                         }]
1033                                 },
1034                                 e: 0.43445
1035                         }, 5, "string", 0, fn, false, null, undefined, 0, [
1036                                 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1037                         ], [], [[[], "foo", null, {
1038                                 n: 1/0,
1039                                 z: {
1040                                         a: [3,4,5,6,"yep!", undefined, undefined],
1041                                         b: {}
1042                                 }
1043                         }, {}]]]), true);
1044
1045         equal(QUnit.equiv(a,
1046                         [{
1047                                 b: fn,
1048                                 c: false,
1049                                 "do": "reserved word",
1050                                 "for": {
1051                                         ar: [3,5,9,"hey!", [], {
1052                                                 ar: [1,[
1053                                                         3,4,6,9, null, [], []
1054                                                 ]],
1055                                                 e: fn,
1056                                                 f: undefined
1057                                         }]
1058                                 },
1059                                 e: 0.43445
1060                         }, 5, "string", 0, fn, false, null, undefined, 0, [
1061                                 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[2]]]], "3"], {}, 1/0    // different: [[[[[2]]]]] instead of [[[[[3]]]]]
1062                         ], [], [[[], "foo", null, {
1063                                 n: 1/0,
1064                                 z: {
1065                                         a: [3,4,5,6,"yep!", undefined, undefined],
1066                                         b: {}
1067                                 }
1068                         }, {}]]]), false);
1069
1070         equal(QUnit.equiv(a,
1071                         [{
1072                                 b: fn,
1073                                 c: false,
1074                                 "do": "reserved word",
1075                                 "for": {
1076                                         ar: [3,5,9,"hey!", [], {
1077                                                 ar: [1,[
1078                                                         3,4,6,9, null, [], []
1079                                                 ]],
1080                                                 e: fn,
1081                                                 f: undefined
1082                                         }]
1083                                 },
1084                                 e: 0.43445
1085                         }, 5, "string", 0, fn, false, null, undefined, 0, [
1086                                 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1087                         ], [], [[[], "foo", null, {
1088                                 n: -1/0,                                                                // different, -Infinity instead of Infinity
1089                                 z: {
1090                                         a: [3,4,5,6,"yep!", undefined, undefined],
1091                                         b: {}
1092                                 }
1093                         }, {}]]]), false);
1094
1095         equal(QUnit.equiv(a,
1096                         [{
1097                                 b: fn,
1098                                 c: false,
1099                                 "do": "reserved word",
1100                                 "for": {
1101                                         ar: [3,5,9,"hey!", [], {
1102                                                 ar: [1,[
1103                                                         3,4,6,9, null, [], []
1104                                                 ]],
1105                                                 e: fn,
1106                                                 f: undefined
1107                                         }]
1108                                 },
1109                                 e: 0.43445
1110                         }, 5, "string", 0, fn, false, null, undefined, 0, [
1111                                 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1112                         ], [], [[[], "foo", {                                                       // different: null is missing
1113                                 n: 1/0,
1114                                 z: {
1115                                         a: [3,4,5,6,"yep!", undefined, undefined],
1116                                         b: {}
1117                                 }
1118                         }, {}]]]), false);
1119
1120         equal(QUnit.equiv(a,
1121                         [{
1122                                 b: fn,
1123                                 c: false,
1124                                 "do": "reserved word",
1125                                 "for": {
1126                                         ar: [3,5,9,"hey!", [], {
1127                                                 ar: [1,[
1128                                                         3,4,6,9, null, [], []
1129                                                 ]],
1130                                                 e: fn
1131                                                                                                                                                                 // different: missing property f: undefined
1132                                         }]
1133                                 },
1134                                 e: 0.43445
1135                         }, 5, "string", 0, fn, false, null, undefined, 0, [
1136                                 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1137                         ], [], [[[], "foo", null, {
1138                                 n: 1/0,
1139                                 z: {
1140                                         a: [3,4,5,6,"yep!", undefined, undefined],
1141                                         b: {}
1142                                 }
1143                         }, {}]]]), false);
1144 });
1145
1146
1147 test("Prototypal inheritance", function() {
1148         function Gizmo(id) {
1149                 this.id = id;
1150         }
1151
1152         function Hoozit(id) {
1153                 this.id = id;
1154         }
1155         Hoozit.prototype = new Gizmo();
1156
1157         var gizmo = new Gizmo("ok");
1158         var hoozit = new Hoozit("ok");
1159
1160         // Try this test many times after test on instances that hold function
1161         // to make sure that our code does not mess with last object constructor memoization.
1162         equal(QUnit.equiv(function () {}, function () {}), false);
1163
1164         // Hoozit inherit from Gizmo
1165         // hoozit instanceof Hoozit; // true
1166         // hoozit instanceof Gizmo; // true
1167         equal(QUnit.equiv(hoozit, gizmo), true);
1168
1169         Gizmo.prototype.bar = true; // not a function just in case we skip them
1170
1171         // Hoozit inherit from Gizmo
1172         // They are equivalent
1173         equal(QUnit.equiv(hoozit, gizmo), true);
1174
1175         // Make sure this is still true !important
1176         // The reason for this is that I forgot to reset the last
1177         // caller to where it were called from.
1178         equal(QUnit.equiv(function () {}, function () {}), false);
1179
1180         // Make sure this is still true !important
1181         equal(QUnit.equiv(hoozit, gizmo), true);
1182
1183         Hoozit.prototype.foo = true; // not a function just in case we skip them
1184
1185         // Gizmo does not inherit from Hoozit
1186         // gizmo instanceof Gizmo; // true
1187         // gizmo instanceof Hoozit; // false
1188         // They are not equivalent
1189         equal(QUnit.equiv(hoozit, gizmo), false);
1190
1191         // Make sure this is still true !important
1192         equal(QUnit.equiv(function () {}, function () {}), false);
1193 });
1194
1195
1196 test("Instances", function() {
1197         function A() {}
1198         var a1 = new A();
1199         var a2 = new A();
1200
1201         function B() {
1202                 this.fn = function () {};
1203         }
1204         var b1 = new B();
1205         var b2 = new B();
1206
1207         equal(QUnit.equiv(a1, a2), true, "Same property, same constructor");
1208
1209         // b1.fn and b2.fn are functions but they are different references
1210         // But we decided to skip function for instances.
1211         equal(QUnit.equiv(b1, b2), true, "Same property, same constructor");
1212         equal(QUnit.equiv(a1, b1), false, "Same properties but different constructor"); // failed
1213
1214         function Car(year) {
1215                 var privateVar = 0;
1216                 this.year = year;
1217                 this.isOld = function() {
1218                         return year > 10;
1219                 };
1220         }
1221
1222         function Human(year) {
1223                 var privateVar = 1;
1224                 this.year = year;
1225                 this.isOld = function() {
1226                         return year > 80;
1227                 };
1228         }
1229
1230         var car = new Car(30);
1231         var carSame = new Car(30);
1232         var carDiff = new Car(10);
1233         var human = new Human(30);
1234
1235         var diff = {
1236                 year: 30
1237         };
1238
1239         var same = {
1240                 year: 30,
1241                 isOld: function () {}
1242         };
1243
1244         equal(QUnit.equiv(car, car), true);
1245         equal(QUnit.equiv(car, carDiff), false);
1246         equal(QUnit.equiv(car, carSame), true);
1247         equal(QUnit.equiv(car, human), false);
1248 });
1249
1250
1251 test("Complex Instances Nesting (with function value in literals and/or in nested instances)", function() {
1252         function A(fn) {
1253                 this.a = {};
1254                 this.fn = fn;
1255                 this.b = {a: []};
1256                 this.o = {};
1257                 this.fn1 = fn;
1258         }
1259         function B(fn) {
1260                 this.fn = fn;
1261                 this.fn1 = function () {};
1262                 this.a = new A(function () {});
1263         }
1264
1265         function fnOutside() {
1266         }
1267
1268         function C(fn) {
1269                 function fnInside() {
1270                 }
1271                 this.x = 10;
1272                 this.fn = fn;
1273                 this.fn1 = function () {};
1274                 this.fn2 = fnInside;
1275                 this.fn3 = {
1276                         a: true,
1277                         b: fnOutside // ok make reference to a function in all instances scope
1278                 };
1279                 this.o1 = {};
1280
1281                 // This function will be ignored.
1282                 // Even if it is not visible for all instances (e.g. locked in a closures),
1283                 // it is from a  property that makes part of an instance (e.g. from the C constructor)
1284                 this.b1 = new B(function () {});
1285                 this.b2 = new B({
1286                         x: {
1287                                 b2: new B(function() {})
1288                         }
1289                 });
1290         }
1291
1292         function D(fn) {
1293                 function fnInside() {
1294                 }
1295                 this.x = 10;
1296                 this.fn = fn;
1297                 this.fn1 = function () {};
1298                 this.fn2 = fnInside;
1299                 this.fn3 = {
1300                         a: true,
1301                         b: fnOutside, // ok make reference to a function in all instances scope
1302
1303                         // This function won't be ingored.
1304                         // It isn't visible for all C insances
1305                         // and it is not in a property of an instance. (in an Object instances e.g. the object literal)
1306                         c: fnInside
1307                 };
1308                 this.o1 = {};
1309
1310                 // This function will be ignored.
1311                 // Even if it is not visible for all instances (e.g. locked in a closures),
1312                 // it is from a  property that makes part of an instance (e.g. from the C constructor)
1313                 this.b1 = new B(function () {});
1314                 this.b2 = new B({
1315                         x: {
1316                                 b2: new B(function() {})
1317                         }
1318                 });
1319         }
1320
1321         function E(fn) {
1322                 function fnInside() {
1323                 }
1324                 this.x = 10;
1325                 this.fn = fn;
1326                 this.fn1 = function () {};
1327                 this.fn2 = fnInside;
1328                 this.fn3 = {
1329                         a: true,
1330                         b: fnOutside // ok make reference to a function in all instances scope
1331                 };
1332                 this.o1 = {};
1333
1334                 // This function will be ignored.
1335                 // Even if it is not visible for all instances (e.g. locked in a closures),
1336                 // it is from a  property that makes part of an instance (e.g. from the C constructor)
1337                 this.b1 = new B(function () {});
1338                 this.b2 = new B({
1339                         x: {
1340                                 b1: new B({a: function() {}}),
1341                                 b2: new B(function() {})
1342                         }
1343                 });
1344         }
1345
1346
1347         var a1 = new A(function () {});
1348         var a2 = new A(function () {});
1349         equal(QUnit.equiv(a1, a2), true);
1350
1351         equal(QUnit.equiv(a1, a2), true); // different instances
1352
1353         var b1 = new B(function () {});
1354         var b2 = new B(function () {});
1355         equal(QUnit.equiv(b1, b2), true);
1356
1357         var c1 = new C(function () {});
1358         var c2 = new C(function () {});
1359         equal(QUnit.equiv(c1, c2), true);
1360
1361         var d1 = new D(function () {});
1362         var d2 = new D(function () {});
1363         equal(QUnit.equiv(d1, d2), false);
1364
1365         var e1 = new E(function () {});
1366         var e2 = new E(function () {});
1367         equal(QUnit.equiv(e1, e2), false);
1368
1369 });
1370
1371
1372 test('object with references to self wont loop', function() {
1373         var circularA = {
1374                 abc:null
1375         }, circularB = {
1376                 abc:null
1377         };
1378         circularA.abc = circularA;
1379         circularB.abc = circularB;
1380         equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object (ambigous test)");
1381
1382         circularA.def = 1;
1383         circularB.def = 1;
1384         equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object (ambigous test)");
1385
1386         circularA.def = 1;
1387         circularB.def = 0;
1388         equal(QUnit.equiv(circularA, circularB), false, "Should not repeat test on object (unambigous test)");
1389 });
1390
1391 test('array with references to self wont loop', function() {
1392         var circularA = [],
1393                 circularB = [];
1394         circularA.push(circularA);
1395         circularB.push(circularB);
1396         equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on array (ambigous test)");
1397
1398         circularA.push( 'abc' );
1399         circularB.push( 'abc' );
1400         equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on array (ambigous test)");
1401
1402         circularA.push( 'hello' );
1403         circularB.push( 'goodbye' );
1404         equal(QUnit.equiv(circularA, circularB), false, "Should not repeat test on array (unambigous test)");
1405 });
1406
1407 test('mixed object/array with references to self wont loop', function() {
1408         var circularA = [{abc:null}],
1409                 circularB = [{abc:null}];
1410         circularA[0].abc = circularA;
1411         circularB[0].abc = circularB;
1412
1413         circularA.push(circularA);
1414         circularB.push(circularB);
1415         equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object/array (ambigous test)");
1416
1417         circularA[0].def = 1;
1418         circularB[0].def = 1;
1419         equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object/array (ambigous test)");
1420
1421         circularA[0].def = 1;
1422         circularB[0].def = 0;
1423         equal(QUnit.equiv(circularA, circularB), false, "Should not repeat test on object/array (unambigous test)");
1424 });
1425
1426 test("Test that must be done at the end because they extend some primitive's prototype", function() {
1427         // Try that a function looks like our regular expression.
1428         // This tests if we check that a and b are really both instance of RegExp
1429         Function.prototype.global = true;
1430         Function.prototype.multiline = true;
1431         Function.prototype.ignoreCase = false;
1432         Function.prototype.source = "my regex";
1433         var re = /my regex/gm;
1434         equal(QUnit.equiv(re, function () {}), false, "A function that looks that a regex isn't a regex");
1435         // This test will ensures it works in both ways, and ALSO especially that we can make differences
1436         // between RegExp and Function constructor because typeof on a RegExpt instance is "function"
1437         equal(QUnit.equiv(function () {}, re), false, "Same conversely, but ensures that function and regexp are distinct because their constructor are different");
1438 });

Hosting is provided AltSPAHow to use Git
Please direct any questions on jabber alex.wolf@jabber.ru

Valid HTML 4.0 Transitional Valid CSS!

Designer Alexander Wolf