1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
46 name: "SelfTests_compare"
48 function test_primitives_and_constants() {
49 compare(qtest_compareInternal(null, null), true, "null");
50 compare(qtest_compareInternal(null, {}), false, "null");
51 compare(qtest_compareInternal(null, undefined), false, "null");
52 compare(qtest_compareInternal(null, 0), false, "null");
53 compare(qtest_compareInternal(null, false), false, "null");
54 compare(qtest_compareInternal(null, ''), false, "null");
55 compare(qtest_compareInternal(null, []), false, "null");
57 compare(qtest_compareInternal(undefined, undefined), true, "undefined");
58 compare(qtest_compareInternal(undefined, null), false, "undefined");
59 compare(qtest_compareInternal(undefined, 0), false, "undefined");
60 compare(qtest_compareInternal(undefined, false), false, "undefined");
61 compare(qtest_compareInternal(undefined, {}), false, "undefined");
62 compare(qtest_compareInternal(undefined, []), false, "undefined");
63 compare(qtest_compareInternal(undefined, ""), false, "undefined");
65 // Nan usually doest not equal to Nan using the '==' operator.
66 // Only isNaN() is able to do it.
67 compare(qtest_compareInternal(0/0, 0/0), true, "NaN"); // NaN VS NaN
68 compare(qtest_compareInternal(1/0, 2/0), true, "Infinity"); // Infinity VS Infinity
69 compare(qtest_compareInternal(-1/0, 2/0), false, "-Infinity, Infinity"); // -Infinity VS Infinity
70 compare(qtest_compareInternal(-1/0, -2/0), true, "-Infinity, -Infinity"); // -Infinity VS -Infinity
71 compare(qtest_compareInternal(0/0, 1/0), false, "NaN, Infinity"); // Nan VS Infinity
72 compare(qtest_compareInternal(1/0, 0/0), false, "NaN, Infinity"); // Nan VS Infinity
73 compare(qtest_compareInternal(0/0, null), false, "NaN");
74 compare(qtest_compareInternal(0/0, undefined), false, "NaN");
75 compare(qtest_compareInternal(0/0, 0), false, "NaN");
76 compare(qtest_compareInternal(0/0, false), false, "NaN");
77 //compare(qtest_compareInternal(0/0, function () {}), false, "NaN"); // Do we really need that?
78 compare(qtest_compareInternal(1/0, null), false, "NaN, Infinity");
79 compare(qtest_compareInternal(1/0, undefined), false, "NaN, Infinity");
80 compare(qtest_compareInternal(1/0, 0), false, "NaN, Infinity");
81 compare(qtest_compareInternal(1/0, 1), false, "NaN, Infinity");
82 compare(qtest_compareInternal(1/0, false), false, "NaN, Infinity");
83 compare(qtest_compareInternal(1/0, true), false, "NaN, Infinity");
84 //compare(qtest_compareInternal(1/0, function () {}), false, "NaN"); // Do we really need that?
86 compare(qtest_compareInternal(0, 0), true, "number");
87 compare(qtest_compareInternal(0, 1), false, "number");
88 compare(qtest_compareInternal(1, 0), false, "number");
89 compare(qtest_compareInternal(1, 1), true, "number");
90 compare(qtest_compareInternal(1.1, 1.1), true, "number");
91 compare(qtest_compareInternal(0.0000005, 0.0000005), true, "number");
92 compare(qtest_compareInternal(0, ''), false, "number");
93 compare(qtest_compareInternal(0, '0'), false, "number");
94 compare(qtest_compareInternal(1, '1'), false, "number");
95 compare(qtest_compareInternal(0, false), false, "number");
96 compare(qtest_compareInternal(1, true), false, "number");
98 compare(qtest_compareInternal(true, true), true, "boolean");
99 compare(qtest_compareInternal(true, false), false, "boolean");
100 compare(qtest_compareInternal(false, true), false, "boolean");
101 compare(qtest_compareInternal(false, 0), false, "boolean");
102 compare(qtest_compareInternal(false, null), false, "boolean");
103 compare(qtest_compareInternal(false, undefined), false, "boolean");
104 compare(qtest_compareInternal(true, 1), false, "boolean");
105 compare(qtest_compareInternal(true, null), false, "boolean");
106 compare(qtest_compareInternal(true, undefined), false, "boolean");
108 compare(qtest_compareInternal('', ''), true, "string");
109 compare(qtest_compareInternal('a', 'a'), true, "string");
110 compare(qtest_compareInternal("foobar", "foobar"), true, "string");
111 compare(qtest_compareInternal("foobar", "foo"), false, "string");
112 compare(qtest_compareInternal('', 0), false, "string");
113 compare(qtest_compareInternal('', false), false, "string");
114 compare(qtest_compareInternal('', null), false, "string");
115 compare(qtest_compareInternal('', undefined), false, "string");
117 // Short annotation VS new annotation
118 compare(qtest_compareInternal(0, new Number()), true, "short annotation VS new annotation");
119 compare(qtest_compareInternal(new Number(), 0), true, "short annotation VS new annotation");
120 compare(qtest_compareInternal(1, new Number(1)), true, "short annotation VS new annotation");
121 compare(qtest_compareInternal(new Number(1), 1), true, "short annotation VS new annotation");
122 compare(qtest_compareInternal(new Number(0), 1), false, "short annotation VS new annotation");
123 compare(qtest_compareInternal(0, new Number(1)), false, "short annotation VS new annotation");
125 compare(qtest_compareInternal(new String(), ""), true, "short annotation VS new annotation");
126 compare(qtest_compareInternal("", new String()), true, "short annotation VS new annotation");
127 compare(qtest_compareInternal(new String("My String"), "My String"), true, "short annotation VS new annotation");
128 compare(qtest_compareInternal("My String", new String("My String")), true, "short annotation VS new annotation");
129 compare(qtest_compareInternal("Bad String", new String("My String")), false, "short annotation VS new annotation");
130 compare(qtest_compareInternal(new String("Bad String"), "My String"), false, "short annotation VS new annotation");
132 compare(qtest_compareInternal(false, new Boolean()), true, "short annotation VS new annotation");
133 compare(qtest_compareInternal(new Boolean(), false), true, "short annotation VS new annotation");
134 compare(qtest_compareInternal(true, new Boolean(true)), true, "short annotation VS new annotation");
135 compare(qtest_compareInternal(new Boolean(true), true), true, "short annotation VS new annotation");
136 compare(qtest_compareInternal(true, new Boolean(1)), true, "short annotation VS new annotation");
137 compare(qtest_compareInternal(false, new Boolean(false)), true, "short annotation VS new annotation");
138 compare(qtest_compareInternal(new Boolean(false), false), true, "short annotation VS new annotation");
139 compare(qtest_compareInternal(false, new Boolean(0)), true, "short annotation VS new annotation");
140 compare(qtest_compareInternal(true, new Boolean(false)), false, "short annotation VS new annotation");
141 compare(qtest_compareInternal(new Boolean(false), true), false, "short annotation VS new annotation");
143 compare(qtest_compareInternal(new Object(), {}), true, "short annotation VS new annotation");
144 compare(qtest_compareInternal({}, new Object()), true, "short annotation VS new annotation");
145 compare(qtest_compareInternal(new Object(), {a:1}), false, "short annotation VS new annotation");
146 compare(qtest_compareInternal({a:1}, new Object()), false, "short annotation VS new annotation");
147 compare(qtest_compareInternal({a:undefined}, new Object()), false, "short annotation VS new annotation");
148 compare(qtest_compareInternal(new Object(), {a:undefined}), false, "short annotation VS new annotation");
151 function test_objects_basics() {
152 compare(qtest_compareInternal({}, {}), true);
153 compare(qtest_compareInternal({}, null), false);
154 compare(qtest_compareInternal({}, undefined), false);
155 compare(qtest_compareInternal({}, 0), false);
156 compare(qtest_compareInternal({}, false), false);
158 // This test is a hard one, it is very important
160 // 1) They are of the same type "object"
161 // 2) [] instanceof Object is true
162 // 3) Their properties are the same (doesn't exists)
163 compare(qtest_compareInternal({}, []), false);
165 compare(qtest_compareInternal({a:1}, {a:1}), true);
166 compare(qtest_compareInternal({a:1}, {a:"1"}), false);
167 compare(qtest_compareInternal({a:[]}, {a:[]}), true);
168 compare(qtest_compareInternal({a:{}}, {a:null}), false);
169 compare(qtest_compareInternal({a:1}, {}), false);
170 compare(qtest_compareInternal({}, {a:1}), false);
173 compare(qtest_compareInternal({a:undefined}, {}), false);
174 compare(qtest_compareInternal({}, {a:undefined}), false);
175 compare(qtest_compareInternal(
177 a: [{ bar: undefined }]
180 a: [{ bat: undefined }]
185 function test_arrays_basics() {
186 compare(qtest_compareInternal([], []), true);
188 // May be a hard one, can invoke a crash at execution.
189 // because their types are both "object" but null isn't
190 // like a true object, it doesn't have any property at all.
191 compare(qtest_compareInternal([], null), false);
193 compare(qtest_compareInternal([], undefined), false);
194 compare(qtest_compareInternal([], false), false);
195 compare(qtest_compareInternal([], 0), false);
196 compare(qtest_compareInternal([], ""), false);
198 // May be a hard one, but less hard
199 // than {} with [] (note the order)
200 compare(qtest_compareInternal([], {}), false);
202 compare(qtest_compareInternal([null],[]), false);
203 compare(qtest_compareInternal([undefined],[]), false);
204 compare(qtest_compareInternal([],[null]), false);
205 compare(qtest_compareInternal([],[undefined]), false);
206 compare(qtest_compareInternal([null],[undefined]), false);
207 compare(qtest_compareInternal([[]],[[]]), true);
208 compare(qtest_compareInternal([[],[],[]],[[],[],[]]), true);
209 compare(qtest_compareInternal(
210 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]],
211 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]),
213 compare(qtest_compareInternal(
214 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]],
215 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), // shorter
217 compare(qtest_compareInternal(
218 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]],
219 [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), // deepest element not an array
222 // same multidimensional
223 compare(qtest_compareInternal(
224 [1,2,3,4,5,6,7,8,9, [
245 [1,2,3,4,5,6,7,8,9, [
266 true, "Multidimensional");
268 // different multidimensional
269 compare(qtest_compareInternal(
270 [1,2,3,4,5,6,7,8,9, [
291 [1,2,3,4,5,6,7,8,9, [
299 '1',2,3,4,[ // string instead of number
312 false, "Multidimensional");
314 // different multidimensional
315 compare(qtest_compareInternal(
316 [1,2,3,4,5,6,7,8,9, [
337 [1,2,3,4,5,6,7,8,9, [
343 2,3,[ // missing an element (4)
358 false, "Multidimensional");
361 function test_date_instances() {
362 // Date, we don't need to test Date.parse() because it returns a number.
363 // Only test the Date instances by setting them a fix date.
364 // The date use is midnight January 1, 1970
367 d1.setTime(0); // fix the date
370 d2.setTime(0); // fix the date
372 var d3 = new Date(); // The very now
374 // Anyway their types differs, just in case the code fails in the order in which it deals with date
375 compare(qtest_compareInternal(d1, 0), false); // d1.valueOf() returns 0, but d1 and 0 are different
376 // test same values date and different instances equality
377 compare(qtest_compareInternal(d1, d2), true);
378 // test different date and different instances difference
379 compare(qtest_compareInternal(d1, d3), false);
381 // try to fool equiv by adding a valueOf function to an object
382 // that would return the same value of a real date instance.
384 d4.setFullYear(2010);
390 d4.setMilliseconds(1);
392 valueOf: function () {
396 compare(qtest_compareInternal(d4, o4), false); // o4 isn't an instance of Date
400 function test_regexp() {
401 // Must test cases that imply those traps:
403 // a instanceof Object; // Oops
404 // a instanceof RegExp; // Oops
405 // typeof a === "function"; // Oops, false in IE and Opera, true in FF and Safari ("object")
407 // Tests same regex with same modifiers in different order
422 compare(qtest_compareInternal(r5, r6), true, "Modifier order");
423 compare(qtest_compareInternal(r5, r7), true, "Modifier order");
424 compare(qtest_compareInternal(r5, r8), true, "Modifier order");
425 compare(qtest_compareInternal(r5, r9), true, "Modifier order");
426 compare(qtest_compareInternal(r5, r10), true, "Modifier order");
427 compare(qtest_compareInternal(r, r5), false, "Modifier");
429 compare(qtest_compareInternal(ri1, ri2), true, "Modifier");
430 compare(qtest_compareInternal(r, ri1), false, "Modifier");
431 compare(qtest_compareInternal(ri1, rm1), false, "Modifier");
432 compare(qtest_compareInternal(r, rm1), false, "Modifier");
433 compare(qtest_compareInternal(rm1, ri1), false, "Modifier");
434 compare(qtest_compareInternal(rm1, rm2), true, "Modifier");
435 compare(qtest_compareInternal(rg1, rm1), false, "Modifier");
436 compare(qtest_compareInternal(rm1, rg1), false, "Modifier");
437 compare(qtest_compareInternal(rg1, rg2), true, "Modifier");
439 // Different regex, same modifiers
441 var r13 = /[0-9]/gi; // oops! different
442 compare(qtest_compareInternal(r11, r13), false, "Regex pattern");
445 var r15 = /"0"/ig; // oops! different
446 compare(qtest_compareInternal(r14, r15), false, "Regex pattern");
448 var r1 = /[\n\r\u2028\u2029]/g;
449 var r2 = /[\n\r\u2028\u2029]/g;
450 var r3 = /[\n\r\u2028\u2028]/g; // differs from r1
451 var r4 = /[\n\r\u2028\u2029]/; // differs from r1
453 compare(qtest_compareInternal(r1, r2), true, "Regex pattern");
454 compare(qtest_compareInternal(r1, r3), false, "Regex pattern");
455 compare(qtest_compareInternal(r1, r4), false, "Regex pattern");
457 // More complex regex
458 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]))$";
459 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]))$";
460 // regex 3 is different: '.' not escaped
461 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]))$";
463 var r21 = new RegExp(regex1);
464 var r22 = new RegExp(regex2);
465 var r23 = new RegExp(regex3); // diff from r21, not same pattern
466 var r23a = new RegExp(regex3, "gi"); // diff from r23, not same modifier
467 var r24a = new RegExp(regex3, "ig"); // same as r23a
469 compare(qtest_compareInternal(r21, r22), true, "Complex Regex");
470 compare(qtest_compareInternal(r21, r23), false, "Complex Regex");
471 compare(qtest_compareInternal(r23, r23a), false, "Complex Regex");
472 compare(qtest_compareInternal(r23a, r24a), true, "Complex Regex");
474 // typeof r1 is "function" in some browsers and "object" in others so we must cover this test
476 compare(qtest_compareInternal(re, function () {}), false, "Regex internal");
477 compare(qtest_compareInternal(re, {}), false, "Regex internal");
481 function test_complex_objects() {
490 // Try to invert the order of some properties to make sure it is covered.
491 // It can failed when properties are compared between unsorted arrays.
492 compare(qtest_compareInternal(
587 compare(qtest_compareInternal(
603 //r: "r", // different: missing a property
682 compare(qtest_compareInternal(
746 //t: undefined, // different: missing a property with an undefined value
777 compare(qtest_compareInternal(
854 q: {} // different was []
874 "string", null, 0, "1", 1, {
876 foo: [1,2,null,{}, [], [1,2,3]],
878 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
880 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
887 "string", null, 0, "1", 1, {
889 foo: [1,2,null,{}, [], [1,2,3]],
891 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
893 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
900 "string", null, 0, "1", 1, {
902 foo: [1,2,null,{}, [], [1,2,3,4]], // different: 4 was add to the array
904 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
906 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
913 "string", null, 0, "1", 1, {
915 foo: [1,2,null,{}, [], [1,2,3]],
916 newprop: undefined, // different: newprop was added
918 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
920 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
927 "string", null, 0, "1", 1, {
929 foo: [1,2,null,{}, [], [1,2,3]],
931 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ α" // different: missing last char
933 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
940 "string", null, 0, "1", 1, {
942 foo: [1,2,undefined,{}, [], [1,2,3]], // different: undefined instead of null
944 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
946 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
953 "string", null, 0, "1", 1, {
955 foo: [1,2,null,{}, [], [1,2,3]],
956 bat: undefined // different: property name not "bar"
957 }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας"
959 unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争",
964 compare(qtest_compareInternal(same1, same2), true);
965 compare(qtest_compareInternal(same2, same1), true);
966 compare(qtest_compareInternal(same2, diff1), false);
967 compare(qtest_compareInternal(diff1, same2), false);
969 compare(qtest_compareInternal(same1, diff1), false);
970 compare(qtest_compareInternal(same1, diff2), false);
971 compare(qtest_compareInternal(same1, diff3), false);
972 compare(qtest_compareInternal(same1, diff3), false);
973 compare(qtest_compareInternal(same1, diff4), false);
974 compare(qtest_compareInternal(same1, diff5), false);
975 compare(qtest_compareInternal(diff5, diff1), false);
979 function test_complex_arrays() {
984 compare(qtest_compareInternal(
985 [1, 2, 3, true, {}, null, [
991 [1, 2, 3, true, {}, null, [
999 compare(qtest_compareInternal(
1000 [1, 2, 3, true, {}, null, [
1006 [1, 2, 3, true, {}, null, [
1008 b: ["", '1', 0] // not same property name
1017 "do": "reserved word",
1019 ar: [3,5,9,"hey!", [], {
1021 3,4,6,9, null, [], []
1028 }, 5, "string", 0, fn, false, null, undefined, 0, [
1029 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1030 ], [], [[[], "foo", null, {
1033 a: [3,4,5,6,"yep!", undefined, undefined],
1038 compare(qtest_compareInternal(a,
1042 "do": "reserved word",
1044 ar: [3,5,9,"hey!", [], {
1046 3,4,6,9, null, [], []
1053 }, 5, "string", 0, fn, false, null, undefined, 0, [
1054 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1055 ], [], [[[], "foo", null, {
1058 a: [3,4,5,6,"yep!", undefined, undefined],
1063 compare(qtest_compareInternal(a,
1067 "do": "reserved word",
1069 ar: [3,5,9,"hey!", [], {
1071 3,4,6,9, null, [], []
1078 }, 5, "string", 0, fn, false, null, undefined, 0, [
1079 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[2]]]], "3"], {}, 1/0 // different: [[[[[2]]]]] instead of [[[[[3]]]]]
1080 ], [], [[[], "foo", null, {
1083 a: [3,4,5,6,"yep!", undefined, undefined],
1088 compare(qtest_compareInternal(a,
1092 "do": "reserved word",
1094 ar: [3,5,9,"hey!", [], {
1096 3,4,6,9, null, [], []
1103 }, 5, "string", 0, fn, false, null, undefined, 0, [
1104 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1105 ], [], [[[], "foo", null, {
1106 n: -1/0, // different, -Infinity instead of Infinity
1108 a: [3,4,5,6,"yep!", undefined, undefined],
1113 compare(qtest_compareInternal(a,
1117 "do": "reserved word",
1119 ar: [3,5,9,"hey!", [], {
1121 3,4,6,9, null, [], []
1128 }, 5, "string", 0, fn, false, null, undefined, 0, [
1129 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1130 ], [], [[[], "foo", { // different: null is missing
1133 a: [3,4,5,6,"yep!", undefined, undefined],
1138 compare(qtest_compareInternal(a,
1142 "do": "reserved word",
1144 ar: [3,5,9,"hey!", [], {
1146 3,4,6,9, null, [], []
1149 // different: missing property f: undefined
1153 }, 5, "string", 0, fn, false, null, undefined, 0, [
1154 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0
1155 ], [], [[[], "foo", null, {
1158 a: [3,4,5,6,"yep!", undefined, undefined],
1165 function test_prototypal_inheritance() {
1166 function Gizmo(id) {
1170 function Hoozit(id) {
1173 Hoozit.prototype = new Gizmo();
1175 var gizmo = new Gizmo("ok");
1176 var hoozit = new Hoozit("ok");
1178 // Try this test many times after test on instances that hold function
1179 // to make sure that our code does not mess with last object constructor memoization.
1180 compare(qtest_compareInternal(function () {}, function () {}), false);
1182 // Hoozit inherit from Gizmo
1183 // hoozit instanceof Hoozit; // true
1184 // hoozit instanceof Gizmo; // true
1185 compare(qtest_compareInternal(hoozit, gizmo), true);
1187 Gizmo.prototype.bar = true; // not a function just in case we skip them
1189 // Hoozit inherit from Gizmo
1190 // They are equivalent
1191 compare(qtest_compareInternal(hoozit, gizmo), true);
1193 // Make sure this is still true !important
1194 // The reason for this is that I forgot to reset the last
1195 // caller to where it were called from.
1196 compare(qtest_compareInternal(function () {}, function () {}), false);
1198 // Make sure this is still true !important
1199 compare(qtest_compareInternal(hoozit, gizmo), true);
1201 Hoozit.prototype.foo = true; // not a function just in case we skip them
1203 // Gizmo does not inherit from Hoozit
1204 // gizmo instanceof Gizmo; // true
1205 // gizmo instanceof Hoozit; // false
1206 // They are not equivalent
1207 compare(qtest_compareInternal(hoozit, gizmo), false);
1209 // Make sure this is still true !important
1210 compare(qtest_compareInternal(function () {}, function () {}), false);
1214 function test_instances() {
1220 this.fn = function () {};
1225 compare(qtest_compareInternal(a1, a2), true, "Same property, same constructor");
1227 // b1.fn and b2.fn are functions but they are different references
1228 // But we decided to skip function for instances.
1229 expectFail("", "Don't know if we want to take over function checking like in QUnit")
1230 compare(qtest_compareInternal(b1, b2), true, "Same property, same constructor");
1231 compare(qtest_compareInternal(a1, b1), false, "Same properties but different constructor"); // failed
1233 function Car(year) {
1236 this.isOld = function() {
1241 function Human(year) {
1244 this.isOld = function() {
1249 var car = new Car(30);
1250 var carSame = new Car(30);
1251 var carDiff = new Car(10);
1252 var human = new Human(30);
1260 isOld: function () {}
1263 compare(qtest_compareInternal(car, car), true);
1264 compare(qtest_compareInternal(car, carDiff), false);
1265 compare(qtest_compareInternal(car, carSame), true);
1266 compare(qtest_compareInternal(car, human), false);
1270 function test_complex_instances_nesting() {
1271 //"Complex Instances Nesting (with function value in literals and/or in nested instances)"
1281 this.fn1 = function () {};
1282 this.a = new A(function () {});
1285 function fnOutside() {
1289 function fnInside() {
1293 this.fn1 = function () {};
1294 this.fn2 = fnInside;
1297 b: fnOutside // ok make reference to a function in all instances scope
1301 // This function will be ignored.
1302 // Even if it is not visible for all instances (e.g. locked in a closures),
1303 // it is from a property that makes part of an instance (e.g. from the C constructor)
1304 this.b1 = new B(function () {});
1307 b2: new B(function() {})
1313 function fnInside() {
1317 this.fn1 = function () {};
1318 this.fn2 = fnInside;
1321 b: fnOutside, // ok make reference to a function in all instances scope
1323 // This function won't be ingored.
1324 // It isn't visible for all C insances
1325 // and it is not in a property of an instance. (in an Object instances e.g. the object literal)
1330 // This function will be ignored.
1331 // Even if it is not visible for all instances (e.g. locked in a closures),
1332 // it is from a property that makes part of an instance (e.g. from the C constructor)
1333 this.b1 = new B(function () {});
1336 b2: new B(function() {})
1342 function fnInside() {
1346 this.fn1 = function () {};
1347 this.fn2 = fnInside;
1350 b: fnOutside // ok make reference to a function in all instances scope
1354 // This function will be ignored.
1355 // Even if it is not visible for all instances (e.g. locked in a closures),
1356 // it is from a property that makes part of an instance (e.g. from the C constructor)
1357 this.b1 = new B(function () {});
1360 b1: new B({a: function() {}}),
1361 b2: new B(function() {})
1367 var a1 = new A(function () {});
1368 var a2 = new A(function () {});
1369 expectFail("", "Don't know if we want to take over function checking like in QUnit")
1370 compare(qtest_compareInternal(a1, a2), true);
1372 compare(qtest_compareInternal(a1, a2), true); // different instances
1374 var b1 = new B(function () {});
1375 var b2 = new B(function () {});
1376 compare(qtest_compareInternal(a1, a2), true);
1378 var c1 = new C(function () {});
1379 var c2 = new C(function () {});
1380 compare(qtest_compareInternal(c1, c2), true);
1382 var d1 = new D(function () {});
1383 var d2 = new D(function () {});
1384 compare(qtest_compareInternal(d1, d2), false);
1386 var e1 = new E(function () {});
1387 var e2 = new E(function () {});
1388 compare(qtest_compareInternal(e1, e2), false);