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 }]
142 test("Arrays Basics.", function() {
144 equals(QUnit.equiv([], []), true);
146 // May be a hard one, can invoke a crash at execution.
147 // because their types are both "object" but null isn't
148 // like a true object, it doesn't have any property at all.
149 equals(QUnit.equiv([], null), false);
151 equals(QUnit.equiv([], undefined), false);
152 equals(QUnit.equiv([], false), false);
153 equals(QUnit.equiv([], 0), false);
154 equals(QUnit.equiv([], ""), false);
156 // May be a hard one, but less hard
157 // than {} with [] (note the order)
158 equals(QUnit.equiv([], {}), false);
160 equals(QUnit.equiv([null],[]), false);
161 equals(QUnit.equiv([undefined],[]), false);
162 equals(QUnit.equiv([],[null]), false);
163 equals(QUnit.equiv([],[undefined]), false);
164 equals(QUnit.equiv([null],[undefined]), false);
165 equals(QUnit.equiv([[]],[[]]), true);
166 equals(QUnit.equiv([[],[],[]],[[],[],[]]), true);
168 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]],
169 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]),
172 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]],
173 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), // shorter
176 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]],
177 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), // deepest element not an array
180 // same multidimensional
182 [1,2,3,4,5,6,7,8,9, [
203 [1,2,3,4,5,6,7,8,9, [
224 true, "Multidimensional");
226 // different multidimensional
228 [1,2,3,4,5,6,7,8,9, [
249 [1,2,3,4,5,6,7,8,9, [
257 '1',2,3,4,[ // string instead of number
270 false, "Multidimensional");
272 // different multidimensional
274 [1,2,3,4,5,6,7,8,9, [
295 [1,2,3,4,5,6,7,8,9, [
301 2,3,[ // missing an element (4)
316 false, "Multidimensional");
319 test("Functions.", function() {
320 var f0 = function () {};
321 var f1 = function () {};
323 // f2 and f3 have the same code, formatted differently
324 var f2 = function () {var i = 0;};
325 var f3 = function () {
326 var i = 0 // this comment and no semicoma as difference
329 equals(QUnit.equiv(function() {}, function() {}), false, "Anonymous functions"); // exact source code
330 equals(QUnit.equiv(function() {}, function() {return true;}), false, "Anonymous functions");
332 equals(QUnit.equiv(f0, f0), true, "Function references"); // same references
333 equals(QUnit.equiv(f0, f1), false, "Function references"); // exact source code, different references
334 equals(QUnit.equiv(f2, f3), false, "Function references"); // equivalent source code, different references
335 equals(QUnit.equiv(f1, f2), false, "Function references"); // different source code, different references
336 equals(QUnit.equiv(function() {}, true), false);
337 equals(QUnit.equiv(function() {}, undefined), false);
338 equals(QUnit.equiv(function() {}, null), false);
339 equals(QUnit.equiv(function() {}, {}), false);
343 test("Date instances.", function() {
344 // Date, we don't need to test Date.parse() because it returns a number.
345 // Only test the Date instances by setting them a fix date.
346 // The date use is midnight January 1, 1970
349 d1.setTime(0); // fix the date
352 d2.setTime(0); // fix the date
354 var d3 = new Date(); // The very now
356 // Anyway their types differs, just in case the code fails in the order in which it deals with date
357 equals(QUnit.equiv(d1, 0), false); // d1.valueOf() returns 0, but d1 and 0 are different
358 // test same values date and different instances equality
359 equals(QUnit.equiv(d1, d2), true);
360 // test different date and different instances difference
361 equals(QUnit.equiv(d1, d3), false);
365 test("RegExp.", function() {
366 // Must test cases that imply those traps:
368 // a instanceof Object; // Oops
369 // a instanceof RegExp; // Oops
370 // typeof a === "function"; // Oops, false in IE and Opera, true in FF and Safari ("object")
372 // Tests same regex with same modifiers in different order
387 equals(QUnit.equiv(r5, r6), true, "Modifier order");
388 equals(QUnit.equiv(r5, r7), true, "Modifier order");
389 equals(QUnit.equiv(r5, r8), true, "Modifier order");
390 equals(QUnit.equiv(r5, r9), true, "Modifier order");
391 equals(QUnit.equiv(r5, r10), true, "Modifier order");
392 equals(QUnit.equiv(r, r5), false, "Modifier");
394 equals(QUnit.equiv(ri1, ri2), true, "Modifier");
395 equals(QUnit.equiv(r, ri1), false, "Modifier");
396 equals(QUnit.equiv(ri1, rm1), false, "Modifier");
397 equals(QUnit.equiv(r, rm1), false, "Modifier");
398 equals(QUnit.equiv(rm1, ri1), false, "Modifier");
399 equals(QUnit.equiv(rm1, rm2), true, "Modifier");
400 equals(QUnit.equiv(rg1, rm1), false, "Modifier");
401 equals(QUnit.equiv(rm1, rg1), false, "Modifier");
402 equals(QUnit.equiv(rg1, rg2), true, "Modifier");
404 // Different regex, same modifiers
406 var r13 = /[0-9]/gi; // oops! different
407 equals(QUnit.equiv(r11, r13), false, "Regex pattern");
410 var r15 = /"0"/ig; // oops! different
411 equals(QUnit.equiv(r14, r15), false, "Regex pattern");
413 var r1 = /[\n\r\u2028\u2029]/g;
414 var r2 = /[\n\r\u2028\u2029]/g;
415 var r3 = /[\n\r\u2028\u2028]/g; // differs from r1
416 var r4 = /[\n\r\u2028\u2029]/; // differs from r1
418 equals(QUnit.equiv(r1, r2), true, "Regex pattern");
419 equals(QUnit.equiv(r1, r3), false, "Regex pattern");
420 equals(QUnit.equiv(r1, r4), false, "Regex pattern");
422 // More complex regex
423 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]))$";
424 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]))$";
425 // regex 3 is different: '.' not escaped
426 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]))$";
428 var r21 = new RegExp(regex1);
429 var r22 = new RegExp(regex2);
430 var r23 = new RegExp(regex3); // diff from r21, not same pattern
431 var r23a = new RegExp(regex3, "gi"); // diff from r23, not same modifier
432 var r24a = new RegExp(regex3, "ig"); // same as r23a
434 equals(QUnit.equiv(r21, r22), true, "Complex Regex");
435 equals(QUnit.equiv(r21, r23), false, "Complex Regex");
436 equals(QUnit.equiv(r23, r23a), false, "Complex Regex");
437 equals(QUnit.equiv(r23a, r24a), true, "Complex Regex");
439 // typeof r1 is "function" in some browsers and "object" in others so we must cover this test
441 equals(QUnit.equiv(re, function () {}), false, "Regex internal");
442 equals(QUnit.equiv(re, {}), false, "Regex internal");
446 test("Complex Objects.", function() {
455 // Try to invert the order of some properties to make sure it is covered.
456 // It can failed when properties are compared between unsorted arrays.
568 //r: "r", // different: missing a property
711 //t: undefined, // different: missing a property with an undefined value
819 q: {} // different was []
839 "string", null, 0, "1", 1, {
841 foo: [1,2,null,{}, [], [1,2,3]],
843 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
845 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
852 "string", null, 0, "1", 1, {
854 foo: [1,2,null,{}, [], [1,2,3]],
856 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
858 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
865 "string", null, 0, "1", 1, {
867 foo: [1,2,null,{}, [], [1,2,3,4]], // different: 4 was add to the array
869 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
871 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
878 "string", null, 0, "1", 1, {
880 foo: [1,2,null,{}, [], [1,2,3]],
881 newprop: undefined, // different: newprop was added
883 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
885 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
892 "string", null, 0, "1", 1, {
894 foo: [1,2,null,{}, [], [1,2,3]],
896 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ α" // different: missing last char
898 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
905 "string", null, 0, "1", 1, {
907 foo: [1,2,undefined,{}, [], [1,2,3]], // different: undefined instead of null
909 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
911 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
918 "string", null, 0, "1", 1, {
920 foo: [1,2,null,{}, [], [1,2,3]],
921 bat: undefined // different: property name not "bar"
922 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
924 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
929 equals(QUnit.equiv(same1, same2), true);
930 equals(QUnit.equiv(same2, same1), true);
931 equals(QUnit.equiv(same2, diff1), false);
932 equals(QUnit.equiv(diff1, same2), false);
934 equals(QUnit.equiv(same1, diff1), false);
935 equals(QUnit.equiv(same1, diff2), false);
936 equals(QUnit.equiv(same1, diff3), false);
937 equals(QUnit.equiv(same1, diff3), false);
938 equals(QUnit.equiv(same1, diff4), false);
939 equals(QUnit.equiv(same1, diff5), false);
940 equals(QUnit.equiv(diff5, diff1), false);
944 test("Complex Arrays.", function() {
950 [1, 2, 3, true, {}, null, [
956 [1, 2, 3, true, {}, null, [
965 [1, 2, 3, true, {}, null, [
971 [1, 2, 3, true, {}, null, [
973 b: ["", '1', 0] // not same property name
982 "do": "reserved word",
984 ar: [3,5,9,"hey!", [], {
986 3,4,6,9, null, [], []
993 }, 5, "string", 0, fn, false, null, undefined, 0, [
994 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
995 ], [], [[[], "foo", null, {
998 a: [3,4,5,6,"yep!", undefined, undefined],
1003 equals(QUnit.equiv(a,
1007 "do": "reserved word",
1009 ar: [3,5,9,"hey!", [], {
1011 3,4,6,9, null, [], []
1018 }, 5, "string", 0, fn, false, null, undefined, 0, [
1019 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1020 ], [], [[[], "foo", null, {
1023 a: [3,4,5,6,"yep!", undefined, undefined],
1028 equals(QUnit.equiv(a,
1032 "do": "reserved word",
1034 ar: [3,5,9,"hey!", [], {
1036 3,4,6,9, null, [], []
1043 }, 5, "string", 0, fn, false, null, undefined, 0, [
1044 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[2]]]], "3"], {}, 1/0 // different: [[[[[2]]]]] instead of [[[[[3]]]]]
1045 ], [], [[[], "foo", null, {
1048 a: [3,4,5,6,"yep!", undefined, undefined],
1053 equals(QUnit.equiv(a,
1057 "do": "reserved word",
1059 ar: [3,5,9,"hey!", [], {
1061 3,4,6,9, null, [], []
1068 }, 5, "string", 0, fn, false, null, undefined, 0, [
1069 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1070 ], [], [[[], "foo", null, {
1071 n: -1/0, // different, -Infinity instead of Infinity
1073 a: [3,4,5,6,"yep!", undefined, undefined],
1078 equals(QUnit.equiv(a,
1082 "do": "reserved word",
1084 ar: [3,5,9,"hey!", [], {
1086 3,4,6,9, null, [], []
1093 }, 5, "string", 0, fn, false, null, undefined, 0, [
1094 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1095 ], [], [[[], "foo", { // different: null is missing
1098 a: [3,4,5,6,"yep!", undefined, undefined],
1103 equals(QUnit.equiv(a,
1107 "do": "reserved word",
1109 ar: [3,5,9,"hey!", [], {
1111 3,4,6,9, null, [], []
1114 // different: missing property f: undefined
1118 }, 5, "string", 0, fn, false, null, undefined, 0, [
1119 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1120 ], [], [[[], "foo", null, {
1123 a: [3,4,5,6,"yep!", undefined, undefined],
1130 test("Prototypal inheritance", function() {
1131 function Gizmo(id) {
1135 function Hoozit(id) {
1138 Hoozit.prototype = new Gizmo();
1140 var gizmo = new Gizmo("ok");
1141 var hoozit = new Hoozit("ok");
1143 // Try this test many times after test on instances that hold function
1144 // to make sure that our code does not mess with last object constructor memoization.
1145 equals(QUnit.equiv(function () {}, function () {}), false);
1147 // Hoozit inherit from Gizmo
1148 // hoozit instanceof Hoozit; // true
1149 // hoozit instanceof Gizmo; // true
1150 equals(QUnit.equiv(hoozit, gizmo), true);
1152 Gizmo.prototype.bar = true; // not a function just in case we skip them
1154 // Hoozit inherit from Gizmo
1155 // They are equivalent
1156 equals(QUnit.equiv(hoozit, gizmo), true);
1158 // Make sure this is still true !important
1159 // The reason for this is that I forgot to reset the last
1160 // caller to where it were called from.
1161 equals(QUnit.equiv(function () {}, function () {}), false);
1163 // Make sure this is still true !important
1164 equals(QUnit.equiv(hoozit, gizmo), true);
1166 Hoozit.prototype.foo = true; // not a function just in case we skip them
1168 // Gizmo does not inherit from Hoozit
1169 // gizmo instanceof Gizmo; // true
1170 // gizmo instanceof Hoozit; // false
1171 // They are not equivalent
1172 equals(QUnit.equiv(hoozit, gizmo), false);
1174 // Make sure this is still true !important
1175 equals(QUnit.equiv(function () {}, function () {}), false);
1179 test("Instances", function() {
1185 this.fn = function () {};
1190 equals(QUnit.equiv(a1, a2), true, "Same property, same constructor");
1192 // b1.fn and b2.fn are functions but they are different references
1193 // But we decided to skip function for instances.
1194 equals(QUnit.equiv(b1, b2), true, "Same property, same constructor");
1195 equals(QUnit.equiv(a1, b1), false, "Same properties but different constructor"); // failed
1197 function Car(year) {
1200 this.isOld = function() {
1205 function Human(year) {
1208 this.isOld = function() {
1213 var car = new Car(30);
1214 var carSame = new Car(30);
1215 var carDiff = new Car(10);
1216 var human = new Human(30);
1224 isOld: function () {}
1227 equals(QUnit.equiv(car, car), true);
1228 equals(QUnit.equiv(car, carDiff), false);
1229 equals(QUnit.equiv(car, carSame), true);
1230 equals(QUnit.equiv(car, human), false);
1234 test("Complex Instances Nesting (with function value in literals and/or in nested instances)", function() {
1244 this.fn1 = function () {};
1245 this.a = new A(function () {});
1248 function fnOutside() {
1252 function fnInside() {
1256 this.fn1 = function () {};
1257 this.fn2 = fnInside;
1260 b: fnOutside // ok make reference to a function in all instances scope
1264 // This function will be ignored.
1265 // Even if it is not visible for all instances (e.g. locked in a closures),
1266 // it is from a property that makes part of an instance (e.g. from the C constructor)
1267 this.b1 = new B(function () {});
1270 b2: new B(function() {})
1276 function fnInside() {
1280 this.fn1 = function () {};
1281 this.fn2 = fnInside;
1284 b: fnOutside, // ok make reference to a function in all instances scope
1286 // This function won't be ingored.
1287 // It isn't visible for all C insances
1288 // and it is not in a property of an instance. (in an Object instances e.g. the object literal)
1293 // This function will be ignored.
1294 // Even if it is not visible for all instances (e.g. locked in a closures),
1295 // it is from a property that makes part of an instance (e.g. from the C constructor)
1296 this.b1 = new B(function () {});
1299 b2: new B(function() {})
1305 function fnInside() {
1309 this.fn1 = function () {};
1310 this.fn2 = fnInside;
1313 b: fnOutside // ok make reference to a function in all instances scope
1317 // This function will be ignored.
1318 // Even if it is not visible for all instances (e.g. locked in a closures),
1319 // it is from a property that makes part of an instance (e.g. from the C constructor)
1320 this.b1 = new B(function () {});
1323 b1: new B({a: function() {}}),
1324 b2: new B(function() {})
1330 var a1 = new A(function () {});
1331 var a2 = new A(function () {});
1332 equals(QUnit.equiv(a1, a2), true);
1334 equals(QUnit.equiv(a1, a2), true); // different instances
1336 var b1 = new B(function () {});
1337 var b2 = new B(function () {});
1338 equals(QUnit.equiv(a1, a2), true);
1340 var c1 = new C(function () {});
1341 var c2 = new C(function () {});
1342 equals(QUnit.equiv(c1, c2), true);
1344 var d1 = new D(function () {});
1345 var d2 = new D(function () {});
1346 equals(QUnit.equiv(d1, d2), false);
1348 var e1 = new E(function () {});
1349 var e2 = new E(function () {});
1350 equals(QUnit.equiv(e1, e2), false);
1355 test('object with references to self wont loop', function(){
1361 circularA.abc = circularA;
1362 circularB.abc = circularB;
1363 equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object (ambigous test)");
1367 equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object (ambigous test)");
1371 equals(QUnit.equiv(circularA, circularB), false, "Should not repeat test on object (unambigous test)");
1374 test('array with references to self wont loop', function(){
1377 circularA.push(circularA);
1378 circularB.push(circularB);
1379 equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on array (ambigous test)");
1381 circularA.push( 'abc' );
1382 circularB.push( 'abc' );
1383 equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on array (ambigous test)");
1385 circularA.push( 'hello' );
1386 circularB.push( 'goodbye' );
1387 equals(QUnit.equiv(circularA, circularB), false, "Should not repeat test on array (unambigous test)");
1390 test('mixed object/array with references to self wont loop', function(){
1391 var circularA = [{abc:null}],
1392 circularB = [{abc:null}];
1393 circularA[0].abc = circularA;
1394 circularB[0].abc = circularB;
1396 circularA.push(circularA);
1397 circularB.push(circularB);
1398 equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object/array (ambigous test)");
1400 circularA[0].def = 1;
1401 circularB[0].def = 1;
1402 equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object/array (ambigous test)");
1404 circularA[0].def = 1;
1405 circularB[0].def = 0;
1406 equals(QUnit.equiv(circularA, circularB), false, "Should not repeat test on object/array (unambigous test)");
1409 test("Test that must be done at the end because they extend some primitive's prototype", function() {
1410 // Try that a function looks like our regular expression.
1411 // This tests if we check that a and b are really both instance of RegExp
1412 Function.prototype.global = true;
1413 Function.prototype.multiline = true;
1414 Function.prototype.ignoreCase = false;
1415 Function.prototype.source = "my regex";
1416 var re = /my regex/gm;
1417 equals(QUnit.equiv(re, function () {}), false, "A function that looks that a regex isn't a regex");
1418 // This test will ensures it works in both ways, and ALSO especially that we can make differences
1419 // between RegExp and Function constructor because typeof on a RegExpt instance is "function"
1420 equals(QUnit.equiv(function () {}, re), false, "Same conversely, but ensures that function and regexp are distinct because their constructor are different");