4 test("Primitive types and constants", function () {
5 equals(QUnit.equiv(null, null), true, "null");
6 equals(QUnit.equiv(null, {}), false, "null");
7 equals(QUnit.equiv(null, undefined), false, "null");
8 equals(QUnit.equiv(null, 0), false, "null");
9 equals(QUnit.equiv(null, false), false, "null");
10 equals(QUnit.equiv(null, ''), false, "null");
11 equals(QUnit.equiv(null, []), false, "null");
13 equals(QUnit.equiv(undefined, undefined), true, "undefined");
14 equals(QUnit.equiv(undefined, null), false, "undefined");
15 equals(QUnit.equiv(undefined, 0), false, "undefined");
16 equals(QUnit.equiv(undefined, false), false, "undefined");
17 equals(QUnit.equiv(undefined, {}), false, "undefined");
18 equals(QUnit.equiv(undefined, []), false, "undefined");
19 equals(QUnit.equiv(undefined, ""), false, "undefined");
21 // Nan usually doest not equal to Nan using the '==' operator.
22 // Only isNaN() is able to do it.
23 equals(QUnit.equiv(0/0, 0/0), true, "NaN"); // NaN VS NaN
24 equals(QUnit.equiv(1/0, 2/0), true, "Infinity"); // Infinity VS Infinity
25 equals(QUnit.equiv(-1/0, 2/0), false, "-Infinity, Infinity"); // -Infinity VS Infinity
26 equals(QUnit.equiv(-1/0, -2/0), true, "-Infinity, -Infinity"); // -Infinity VS -Infinity
27 equals(QUnit.equiv(0/0, 1/0), false, "NaN, Infinity"); // Nan VS Infinity
28 equals(QUnit.equiv(1/0, 0/0), false, "NaN, Infinity"); // Nan VS Infinity
29 equals(QUnit.equiv(0/0, null), false, "NaN");
30 equals(QUnit.equiv(0/0, undefined), false, "NaN");
31 equals(QUnit.equiv(0/0, 0), false, "NaN");
32 equals(QUnit.equiv(0/0, false), false, "NaN");
33 equals(QUnit.equiv(0/0, function () {}), false, "NaN");
34 equals(QUnit.equiv(1/0, null), false, "NaN, Infinity");
35 equals(QUnit.equiv(1/0, undefined), false, "NaN, Infinity");
36 equals(QUnit.equiv(1/0, 0), false, "NaN, Infinity");
37 equals(QUnit.equiv(1/0, 1), false, "NaN, Infinity");
38 equals(QUnit.equiv(1/0, false), false, "NaN, Infinity");
39 equals(QUnit.equiv(1/0, true), false, "NaN, Infinity");
40 equals(QUnit.equiv(1/0, function () {}), false, "NaN, Infinity");
42 equals(QUnit.equiv(0, 0), true, "number");
43 equals(QUnit.equiv(0, 1), false, "number");
44 equals(QUnit.equiv(1, 0), false, "number");
45 equals(QUnit.equiv(1, 1), true, "number");
46 equals(QUnit.equiv(1.1, 1.1), true, "number");
47 equals(QUnit.equiv(0.0000005, 0.0000005), true, "number");
48 equals(QUnit.equiv(0, ''), false, "number");
49 equals(QUnit.equiv(0, '0'), false, "number");
50 equals(QUnit.equiv(1, '1'), false, "number");
51 equals(QUnit.equiv(0, false), false, "number");
52 equals(QUnit.equiv(1, true), false, "number");
54 equals(QUnit.equiv(true, true), true, "boolean");
55 equals(QUnit.equiv(true, false), false, "boolean");
56 equals(QUnit.equiv(false, true), false, "boolean");
57 equals(QUnit.equiv(false, 0), false, "boolean");
58 equals(QUnit.equiv(false, null), false, "boolean");
59 equals(QUnit.equiv(false, undefined), false, "boolean");
60 equals(QUnit.equiv(true, 1), false, "boolean");
61 equals(QUnit.equiv(true, null), false, "boolean");
62 equals(QUnit.equiv(true, undefined), false, "boolean");
64 equals(QUnit.equiv('', ''), true, "string");
65 equals(QUnit.equiv('a', 'a'), true, "string");
66 equals(QUnit.equiv("foobar", "foobar"), true, "string");
67 equals(QUnit.equiv("foobar", "foo"), false, "string");
68 equals(QUnit.equiv('', 0), false, "string");
69 equals(QUnit.equiv('', false), false, "string");
70 equals(QUnit.equiv('', null), false, "string");
71 equals(QUnit.equiv('', undefined), false, "string");
73 // Short annotation VS new annotation
74 equals(QUnit.equiv(0, new Number()), true, "short annotation VS new annotation");
75 equals(QUnit.equiv(new Number(), 0), true, "short annotation VS new annotation");
76 equals(QUnit.equiv(1, new Number(1)), true, "short annotation VS new annotation");
77 equals(QUnit.equiv(new Number(1), 1), true, "short annotation VS new annotation");
78 equals(QUnit.equiv(new Number(0), 1), false, "short annotation VS new annotation");
79 equals(QUnit.equiv(0, new Number(1)), false, "short annotation VS new annotation");
81 equals(QUnit.equiv(new String(), ""), true, "short annotation VS new annotation");
82 equals(QUnit.equiv("", new String()), true, "short annotation VS new annotation");
83 equals(QUnit.equiv(new String("My String"), "My String"), true, "short annotation VS new annotation");
84 equals(QUnit.equiv("My String", new String("My String")), true, "short annotation VS new annotation");
85 equals(QUnit.equiv("Bad String", new String("My String")), false, "short annotation VS new annotation");
86 equals(QUnit.equiv(new String("Bad String"), "My String"), false, "short annotation VS new annotation");
88 equals(QUnit.equiv(false, new Boolean()), true, "short annotation VS new annotation");
89 equals(QUnit.equiv(new Boolean(), false), true, "short annotation VS new annotation");
90 equals(QUnit.equiv(true, new Boolean(true)), true, "short annotation VS new annotation");
91 equals(QUnit.equiv(new Boolean(true), true), true, "short annotation VS new annotation");
92 equals(QUnit.equiv(true, new Boolean(1)), true, "short annotation VS new annotation");
93 equals(QUnit.equiv(false, new Boolean(false)), true, "short annotation VS new annotation");
94 equals(QUnit.equiv(new Boolean(false), false), true, "short annotation VS new annotation");
95 equals(QUnit.equiv(false, new Boolean(0)), true, "short annotation VS new annotation");
96 equals(QUnit.equiv(true, new Boolean(false)), false, "short annotation VS new annotation");
97 equals(QUnit.equiv(new Boolean(false), true), false, "short annotation VS new annotation");
99 equals(QUnit.equiv(new Object(), {}), true, "short annotation VS new annotation");
100 equals(QUnit.equiv({}, new Object()), true, "short annotation VS new annotation");
101 equals(QUnit.equiv(new Object(), {a:1}), false, "short annotation VS new annotation");
102 equals(QUnit.equiv({a:1}, new Object()), false, "short annotation VS new annotation");
103 equals(QUnit.equiv({a:undefined}, new Object()), false, "short annotation VS new annotation");
104 equals(QUnit.equiv(new Object(), {a:undefined}), false, "short annotation VS new annotation");
107 test("Objects Basics.", function() {
108 equals(QUnit.equiv({}, {}), true);
109 equals(QUnit.equiv({}, null), false);
110 equals(QUnit.equiv({}, undefined), false);
111 equals(QUnit.equiv({}, 0), false);
112 equals(QUnit.equiv({}, false), false);
114 // This test is a hard one, it is very important
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 equals(QUnit.equiv({}, []), false);
121 equals(QUnit.equiv({a:1}, {a:1}), true);
122 equals(QUnit.equiv({a:1}, {a:"1"}), false);
123 equals(QUnit.equiv({a:[]}, {a:[]}), true);
124 equals(QUnit.equiv({a:{}}, {a:null}), false);
125 equals(QUnit.equiv({a:1}, {}), false);
126 equals(QUnit.equiv({}, {a:1}), false);
129 equals(QUnit.equiv({a:undefined}, {}), false);
130 equals(QUnit.equiv({}, {a:undefined}), false);
133 a: [{ bar: undefined }]
136 a: [{ bat: undefined }]
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.
143 equals(QUnit.equiv(Object.create(null), {}), true, "empty object with no prototype VS empty object");
145 var nonEmptyWithNoProto = Object.create(null);
146 nonEmptyWithNoProto.foo = "bar";
148 equals(QUnit.equiv(nonEmptyWithNoProto, { foo: "bar" }), true, "nonempty object with no prototype VS empty object");
153 test("Arrays Basics.", function() {
155 equals(QUnit.equiv([], []), true);
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 equals(QUnit.equiv([], null), false);
162 equals(QUnit.equiv([], undefined), false);
163 equals(QUnit.equiv([], false), false);
164 equals(QUnit.equiv([], 0), false);
165 equals(QUnit.equiv([], ""), false);
167 // May be a hard one, but less hard
168 // than {} with [] (note the order)
169 equals(QUnit.equiv([], {}), false);
171 equals(QUnit.equiv([null],[]), false);
172 equals(QUnit.equiv([undefined],[]), false);
173 equals(QUnit.equiv([],[null]), false);
174 equals(QUnit.equiv([],[undefined]), false);
175 equals(QUnit.equiv([null],[undefined]), false);
176 equals(QUnit.equiv([[]],[[]]), true);
177 equals(QUnit.equiv([[],[],[]],[[],[],[]]), true);
179 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]],
180 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]),
183 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]],
184 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), // shorter
187 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]],
188 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), // deepest element not an array
191 // same multidimensional
193 [1,2,3,4,5,6,7,8,9, [
214 [1,2,3,4,5,6,7,8,9, [
235 true, "Multidimensional");
237 // different multidimensional
239 [1,2,3,4,5,6,7,8,9, [
260 [1,2,3,4,5,6,7,8,9, [
268 '1',2,3,4,[ // string instead of number
281 false, "Multidimensional");
283 // different multidimensional
285 [1,2,3,4,5,6,7,8,9, [
306 [1,2,3,4,5,6,7,8,9, [
312 2,3,[ // missing an element (4)
327 false, "Multidimensional");
330 test("Functions.", function() {
331 var f0 = function () {};
332 var f1 = function () {};
334 // f2 and f3 have the same code, formatted differently
335 var f2 = function () {var i = 0;};
336 var f3 = function () {
337 var i = 0 // this comment and no semicoma as difference
340 equals(QUnit.equiv(function() {}, function() {}), false, "Anonymous functions"); // exact source code
341 equals(QUnit.equiv(function() {}, function() {return true;}), false, "Anonymous functions");
343 equals(QUnit.equiv(f0, f0), true, "Function references"); // same references
344 equals(QUnit.equiv(f0, f1), false, "Function references"); // exact source code, different references
345 equals(QUnit.equiv(f2, f3), false, "Function references"); // equivalent source code, different references
346 equals(QUnit.equiv(f1, f2), false, "Function references"); // different source code, different references
347 equals(QUnit.equiv(function() {}, true), false);
348 equals(QUnit.equiv(function() {}, undefined), false);
349 equals(QUnit.equiv(function() {}, null), false);
350 equals(QUnit.equiv(function() {}, {}), false);
354 test("Date instances.", function() {
355 // Date, we don't need to test Date.parse() because it returns a number.
356 // Only test the Date instances by setting them a fix date.
357 // The date use is midnight January 1, 1970
360 d1.setTime(0); // fix the date
363 d2.setTime(0); // fix the date
365 var d3 = new Date(); // The very now
367 // Anyway their types differs, just in case the code fails in the order in which it deals with date
368 equals(QUnit.equiv(d1, 0), false); // d1.valueOf() returns 0, but d1 and 0 are different
369 // test same values date and different instances equality
370 equals(QUnit.equiv(d1, d2), true);
371 // test different date and different instances difference
372 equals(QUnit.equiv(d1, d3), false);
376 test("RegExp.", function() {
377 // Must test cases that imply those traps:
379 // a instanceof Object; // Oops
380 // a instanceof RegExp; // Oops
381 // typeof a === "function"; // Oops, false in IE and Opera, true in FF and Safari ("object")
383 // Tests same regex with same modifiers in different order
398 equals(QUnit.equiv(r5, r6), true, "Modifier order");
399 equals(QUnit.equiv(r5, r7), true, "Modifier order");
400 equals(QUnit.equiv(r5, r8), true, "Modifier order");
401 equals(QUnit.equiv(r5, r9), true, "Modifier order");
402 equals(QUnit.equiv(r5, r10), true, "Modifier order");
403 equals(QUnit.equiv(r, r5), false, "Modifier");
405 equals(QUnit.equiv(ri1, ri2), true, "Modifier");
406 equals(QUnit.equiv(r, ri1), false, "Modifier");
407 equals(QUnit.equiv(ri1, rm1), false, "Modifier");
408 equals(QUnit.equiv(r, rm1), false, "Modifier");
409 equals(QUnit.equiv(rm1, ri1), false, "Modifier");
410 equals(QUnit.equiv(rm1, rm2), true, "Modifier");
411 equals(QUnit.equiv(rg1, rm1), false, "Modifier");
412 equals(QUnit.equiv(rm1, rg1), false, "Modifier");
413 equals(QUnit.equiv(rg1, rg2), true, "Modifier");
415 // Different regex, same modifiers
417 var r13 = /[0-9]/gi; // oops! different
418 equals(QUnit.equiv(r11, r13), false, "Regex pattern");
421 var r15 = /"0"/ig; // oops! different
422 equals(QUnit.equiv(r14, r15), false, "Regex pattern");
424 var r1 = /[\n\r\u2028\u2029]/g;
425 var r2 = /[\n\r\u2028\u2029]/g;
426 var r3 = /[\n\r\u2028\u2028]/g; // differs from r1
427 var r4 = /[\n\r\u2028\u2029]/; // differs from r1
429 equals(QUnit.equiv(r1, r2), true, "Regex pattern");
430 equals(QUnit.equiv(r1, r3), false, "Regex pattern");
431 equals(QUnit.equiv(r1, r4), false, "Regex pattern");
433 // More complex regex
434 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]))$";
435 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]))$";
436 // regex 3 is different: '.' not escaped
437 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 var r21 = new RegExp(regex1);
440 var r22 = new RegExp(regex2);
441 var r23 = new RegExp(regex3); // diff from r21, not same pattern
442 var r23a = new RegExp(regex3, "gi"); // diff from r23, not same modifier
443 var r24a = new RegExp(regex3, "ig"); // same as r23a
445 equals(QUnit.equiv(r21, r22), true, "Complex Regex");
446 equals(QUnit.equiv(r21, r23), false, "Complex Regex");
447 equals(QUnit.equiv(r23, r23a), false, "Complex Regex");
448 equals(QUnit.equiv(r23a, r24a), true, "Complex Regex");
450 // typeof r1 is "function" in some browsers and "object" in others so we must cover this test
452 equals(QUnit.equiv(re, function () {}), false, "Regex internal");
453 equals(QUnit.equiv(re, {}), false, "Regex internal");
457 test("Complex Objects.", function() {
466 // Try to invert the order of some properties to make sure it is covered.
467 // It can failed when properties are compared between unsorted arrays.
579 //r: "r", // different: missing a property
722 //t: undefined, // different: missing a property with an undefined value
830 q: {} // different was []
850 "string", null, 0, "1", 1, {
852 foo: [1,2,null,{}, [], [1,2,3]],
854 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
856 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
863 "string", null, 0, "1", 1, {
865 foo: [1,2,null,{}, [], [1,2,3]],
867 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
869 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
876 "string", null, 0, "1", 1, {
878 foo: [1,2,null,{}, [], [1,2,3,4]], // different: 4 was add to the array
880 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
882 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
889 "string", null, 0, "1", 1, {
891 foo: [1,2,null,{}, [], [1,2,3]],
892 newprop: undefined, // different: newprop was added
894 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
896 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
903 "string", null, 0, "1", 1, {
905 foo: [1,2,null,{}, [], [1,2,3]],
907 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ α" // different: missing last char
909 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
916 "string", null, 0, "1", 1, {
918 foo: [1,2,undefined,{}, [], [1,2,3]], // different: undefined instead of null
920 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
922 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
929 "string", null, 0, "1", 1, {
931 foo: [1,2,null,{}, [], [1,2,3]],
932 bat: undefined // different: property name not "bar"
933 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
935 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
940 equals(QUnit.equiv(same1, same2), true);
941 equals(QUnit.equiv(same2, same1), true);
942 equals(QUnit.equiv(same2, diff1), false);
943 equals(QUnit.equiv(diff1, same2), false);
945 equals(QUnit.equiv(same1, diff1), false);
946 equals(QUnit.equiv(same1, diff2), false);
947 equals(QUnit.equiv(same1, diff3), false);
948 equals(QUnit.equiv(same1, diff3), false);
949 equals(QUnit.equiv(same1, diff4), false);
950 equals(QUnit.equiv(same1, diff5), false);
951 equals(QUnit.equiv(diff5, diff1), false);
955 test("Complex Arrays.", function() {
961 [1, 2, 3, true, {}, null, [
967 [1, 2, 3, true, {}, null, [
976 [1, 2, 3, true, {}, null, [
982 [1, 2, 3, true, {}, null, [
984 b: ["", '1', 0] // not same property name
993 "do": "reserved word",
995 ar: [3,5,9,"hey!", [], {
997 3,4,6,9, null, [], []
1004 }, 5, "string", 0, fn, false, null, undefined, 0, [
1005 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1006 ], [], [[[], "foo", null, {
1009 a: [3,4,5,6,"yep!", undefined, undefined],
1014 equals(QUnit.equiv(a,
1018 "do": "reserved word",
1020 ar: [3,5,9,"hey!", [], {
1022 3,4,6,9, null, [], []
1029 }, 5, "string", 0, fn, false, null, undefined, 0, [
1030 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1031 ], [], [[[], "foo", null, {
1034 a: [3,4,5,6,"yep!", undefined, undefined],
1039 equals(QUnit.equiv(a,
1043 "do": "reserved word",
1045 ar: [3,5,9,"hey!", [], {
1047 3,4,6,9, null, [], []
1054 }, 5, "string", 0, fn, false, null, undefined, 0, [
1055 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[2]]]], "3"], {}, 1/0 // different: [[[[[2]]]]] instead of [[[[[3]]]]]
1056 ], [], [[[], "foo", null, {
1059 a: [3,4,5,6,"yep!", undefined, undefined],
1064 equals(QUnit.equiv(a,
1068 "do": "reserved word",
1070 ar: [3,5,9,"hey!", [], {
1072 3,4,6,9, null, [], []
1079 }, 5, "string", 0, fn, false, null, undefined, 0, [
1080 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1081 ], [], [[[], "foo", null, {
1082 n: -1/0, // different, -Infinity instead of Infinity
1084 a: [3,4,5,6,"yep!", undefined, undefined],
1089 equals(QUnit.equiv(a,
1093 "do": "reserved word",
1095 ar: [3,5,9,"hey!", [], {
1097 3,4,6,9, null, [], []
1104 }, 5, "string", 0, fn, false, null, undefined, 0, [
1105 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1106 ], [], [[[], "foo", { // different: null is missing
1109 a: [3,4,5,6,"yep!", undefined, undefined],
1114 equals(QUnit.equiv(a,
1118 "do": "reserved word",
1120 ar: [3,5,9,"hey!", [], {
1122 3,4,6,9, null, [], []
1125 // different: missing property f: undefined
1129 }, 5, "string", 0, fn, false, null, undefined, 0, [
1130 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1131 ], [], [[[], "foo", null, {
1134 a: [3,4,5,6,"yep!", undefined, undefined],
1141 test("Prototypal inheritance", function() {
1142 function Gizmo(id) {
1146 function Hoozit(id) {
1149 Hoozit.prototype = new Gizmo();
1151 var gizmo = new Gizmo("ok");
1152 var hoozit = new Hoozit("ok");
1154 // Try this test many times after test on instances that hold function
1155 // to make sure that our code does not mess with last object constructor memoization.
1156 equals(QUnit.equiv(function () {}, function () {}), false);
1158 // Hoozit inherit from Gizmo
1159 // hoozit instanceof Hoozit; // true
1160 // hoozit instanceof Gizmo; // true
1161 equals(QUnit.equiv(hoozit, gizmo), true);
1163 Gizmo.prototype.bar = true; // not a function just in case we skip them
1165 // Hoozit inherit from Gizmo
1166 // They are equivalent
1167 equals(QUnit.equiv(hoozit, gizmo), true);
1169 // Make sure this is still true !important
1170 // The reason for this is that I forgot to reset the last
1171 // caller to where it were called from.
1172 equals(QUnit.equiv(function () {}, function () {}), false);
1174 // Make sure this is still true !important
1175 equals(QUnit.equiv(hoozit, gizmo), true);
1177 Hoozit.prototype.foo = true; // not a function just in case we skip them
1179 // Gizmo does not inherit from Hoozit
1180 // gizmo instanceof Gizmo; // true
1181 // gizmo instanceof Hoozit; // false
1182 // They are not equivalent
1183 equals(QUnit.equiv(hoozit, gizmo), false);
1185 // Make sure this is still true !important
1186 equals(QUnit.equiv(function () {}, function () {}), false);
1190 test("Instances", function() {
1196 this.fn = function () {};
1201 equals(QUnit.equiv(a1, a2), true, "Same property, same constructor");
1203 // b1.fn and b2.fn are functions but they are different references
1204 // But we decided to skip function for instances.
1205 equals(QUnit.equiv(b1, b2), true, "Same property, same constructor");
1206 equals(QUnit.equiv(a1, b1), false, "Same properties but different constructor"); // failed
1208 function Car(year) {
1211 this.isOld = function() {
1216 function Human(year) {
1219 this.isOld = function() {
1224 var car = new Car(30);
1225 var carSame = new Car(30);
1226 var carDiff = new Car(10);
1227 var human = new Human(30);
1235 isOld: function () {}
1238 equals(QUnit.equiv(car, car), true);
1239 equals(QUnit.equiv(car, carDiff), false);
1240 equals(QUnit.equiv(car, carSame), true);
1241 equals(QUnit.equiv(car, human), false);
1245 test("Complex Instances Nesting (with function value in literals and/or in nested instances)", function() {
1255 this.fn1 = function () {};
1256 this.a = new A(function () {});
1259 function fnOutside() {
1263 function fnInside() {
1267 this.fn1 = function () {};
1268 this.fn2 = fnInside;
1271 b: fnOutside // ok make reference to a function in all instances scope
1275 // This function will be ignored.
1276 // Even if it is not visible for all instances (e.g. locked in a closures),
1277 // it is from a property that makes part of an instance (e.g. from the C constructor)
1278 this.b1 = new B(function () {});
1281 b2: new B(function() {})
1287 function fnInside() {
1291 this.fn1 = function () {};
1292 this.fn2 = fnInside;
1295 b: fnOutside, // ok make reference to a function in all instances scope
1297 // This function won't be ingored.
1298 // It isn't visible for all C insances
1299 // and it is not in a property of an instance. (in an Object instances e.g. the object literal)
1304 // This function will be ignored.
1305 // Even if it is not visible for all instances (e.g. locked in a closures),
1306 // it is from a property that makes part of an instance (e.g. from the C constructor)
1307 this.b1 = new B(function () {});
1310 b2: new B(function() {})
1316 function fnInside() {
1320 this.fn1 = function () {};
1321 this.fn2 = fnInside;
1324 b: fnOutside // ok make reference to a function in all instances scope
1328 // This function will be ignored.
1329 // Even if it is not visible for all instances (e.g. locked in a closures),
1330 // it is from a property that makes part of an instance (e.g. from the C constructor)
1331 this.b1 = new B(function () {});
1334 b1: new B({a: function() {}}),
1335 b2: new B(function() {})
1341 var a1 = new A(function () {});
1342 var a2 = new A(function () {});
1343 equals(QUnit.equiv(a1, a2), true);
1345 equals(QUnit.equiv(a1, a2), true); // different instances
1347 var b1 = new B(function () {});
1348 var b2 = new B(function () {});
1349 equals(QUnit.equiv(b1, b2), true);
1351 var c1 = new C(function () {});
1352 var c2 = new C(function () {});
1353 equals(QUnit.equiv(c1, c2), true);
1355 var d1 = new D(function () {});
1356 var d2 = new D(function () {});
1357 equals(QUnit.equiv(d1, d2), false);
1359 var e1 = new E(function () {});
1360 var e2 = new E(function () {});
1361 equals(QUnit.equiv(e1, e2), false);
1366 test('object with references to self wont loop', function(){
1372 circularA.abc = circularA;
1373 circularB.abc = circularB;
1374 equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object (ambigous test)");
1378 equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object (ambigous test)");
1382 equals(QUnit.equiv(circularA, circularB), false, "Should not repeat test on object (unambigous test)");
1385 test('array with references to self wont loop', function(){
1388 circularA.push(circularA);
1389 circularB.push(circularB);
1390 equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on array (ambigous test)");
1392 circularA.push( 'abc' );
1393 circularB.push( 'abc' );
1394 equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on array (ambigous test)");
1396 circularA.push( 'hello' );
1397 circularB.push( 'goodbye' );
1398 equals(QUnit.equiv(circularA, circularB), false, "Should not repeat test on array (unambigous test)");
1401 test('mixed object/array with references to self wont loop', function(){
1402 var circularA = [{abc:null}],
1403 circularB = [{abc:null}];
1404 circularA[0].abc = circularA;
1405 circularB[0].abc = circularB;
1407 circularA.push(circularA);
1408 circularB.push(circularB);
1409 equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object/array (ambigous test)");
1411 circularA[0].def = 1;
1412 circularB[0].def = 1;
1413 equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object/array (ambigous test)");
1415 circularA[0].def = 1;
1416 circularB[0].def = 0;
1417 equals(QUnit.equiv(circularA, circularB), false, "Should not repeat test on object/array (unambigous test)");
1420 test("Test that must be done at the end because they extend some primitive's prototype", function() {
1421 // Try that a function looks like our regular expression.
1422 // This tests if we check that a and b are really both instance of RegExp
1423 Function.prototype.global = true;
1424 Function.prototype.multiline = true;
1425 Function.prototype.ignoreCase = false;
1426 Function.prototype.source = "my regex";
1427 var re = /my regex/gm;
1428 equals(QUnit.equiv(re, function () {}), false, "A function that looks that a regex isn't a regex");
1429 // This test will ensures it works in both ways, and ALSO especially that we can make differences
1430 // between RegExp and Function constructor because typeof on a RegExpt instance is "function"
1431 equals(QUnit.equiv(function () {}, re), false, "Same conversely, but ensures that function and regexp are distinct because their constructor are different");