Home page Forum Wiki Mail Jabber Devel NIX-FILES

AltLUG Git

Git-repositories of Altai Linux User Group

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

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