1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | (function(window) {
|
12 |
|
13 | var QUnit = {
|
14 |
|
15 |
|
16 | init: function() {
|
17 | config = {
|
18 | stats: { all: 0, bad: 0 },
|
19 | moduleStats: { all: 0, bad: 0 },
|
20 | started: +new Date,
|
21 | blocking: false,
|
22 | autorun: false,
|
23 | assertions: [],
|
24 | filters: [],
|
25 | queue: []
|
26 | };
|
27 |
|
28 | var tests = id("qunit-tests"),
|
29 | banner = id("qunit-banner"),
|
30 | result = id("qunit-testresult");
|
31 |
|
32 | if ( tests ) {
|
33 | tests.innerHTML = "";
|
34 | }
|
35 |
|
36 | if ( banner ) {
|
37 | banner.className = "";
|
38 | }
|
39 |
|
40 | if ( result ) {
|
41 | result.parentNode.removeChild( result );
|
42 | }
|
43 | },
|
44 |
|
45 |
|
46 | module: function(name, testEnvironment) {
|
47 | config.currentModule = name;
|
48 |
|
49 | synchronize(function() {
|
50 | if ( config.currentModule ) {
|
51 | QUnit.moduleDone( config.currentModule, config.moduleStats.bad, config.moduleStats.all );
|
52 | }
|
53 |
|
54 | config.currentModule = name;
|
55 | config.moduleTestEnvironment = testEnvironment;
|
56 | config.moduleStats = { all: 0, bad: 0 };
|
57 |
|
58 | QUnit.moduleStart( name, testEnvironment );
|
59 | });
|
60 | },
|
61 |
|
62 | asyncTest: function(testName, expected, callback) {
|
63 | if ( arguments.length === 2 ) {
|
64 | callback = expected;
|
65 | expected = 0;
|
66 | }
|
67 |
|
68 | QUnit.test(testName, expected, callback, true);
|
69 | },
|
70 |
|
71 | test: function(testName, expected, callback, async) {
|
72 | var name = testName, testEnvironment, testEnvironmentArg;
|
73 |
|
74 | if ( arguments.length === 2 ) {
|
75 | callback = expected;
|
76 | expected = null;
|
77 | }
|
78 |
|
79 | if ( expected && typeof expected === 'object') {
|
80 | testEnvironmentArg = expected;
|
81 | expected = null;
|
82 | }
|
83 |
|
84 | if ( config.currentModule ) {
|
85 | name = config.currentModule + " module: " + name;
|
86 | }
|
87 |
|
88 | if ( !validTest(name) ) {
|
89 | return;
|
90 | }
|
91 |
|
92 | synchronize(function() {
|
93 | QUnit.testStart( testName );
|
94 |
|
95 | testEnvironment = extend({
|
96 | setup: function() {},
|
97 | teardown: function() {}
|
98 | }, config.moduleTestEnvironment);
|
99 | if (testEnvironmentArg) {
|
100 | extend(testEnvironment,testEnvironmentArg);
|
101 | }
|
102 |
|
103 |
|
104 | QUnit.current_testEnvironment = testEnvironment;
|
105 |
|
106 | config.assertions = [];
|
107 | config.expected = expected;
|
108 |
|
109 | try {
|
110 | if ( !config.pollution ) {
|
111 | saveGlobal();
|
112 | }
|
113 |
|
114 | testEnvironment.setup.call(testEnvironment);
|
115 | } catch(e) {
|
116 | QUnit.ok( false, "Setup failed on " + name + ": " + e.message );
|
117 | }
|
118 |
|
119 | if ( async ) {
|
120 | QUnit.stop();
|
121 | }
|
122 |
|
123 | try {
|
124 | callback.call(testEnvironment);
|
125 | } catch(e) {
|
126 | fail("Test " + name + " died, exception and test follows", e, callback);
|
127 | QUnit.ok( false, "Died on test #" + (config.assertions.length + 1) + ": " + e.message );
|
128 |
|
129 | saveGlobal();
|
130 |
|
131 |
|
132 | if ( config.blocking ) {
|
133 | start();
|
134 | }
|
135 | }
|
136 | });
|
137 |
|
138 | synchronize(function() {
|
139 | try {
|
140 | checkPollution();
|
141 | testEnvironment.teardown.call(testEnvironment);
|
142 | } catch(e) {
|
143 | QUnit.ok( false, "Teardown failed on " + name + ": " + e.message );
|
144 | }
|
145 |
|
146 | try {
|
147 | QUnit.reset();
|
148 | } catch(e) {
|
149 | fail("reset() failed, following Test " + name + ", exception and reset fn follows", e, reset);
|
150 | }
|
151 |
|
152 | if ( config.expected && config.expected != config.assertions.length ) {
|
153 | QUnit.ok( false, "Expected " + config.expected + " assertions, but " + config.assertions.length + " were run" );
|
154 | }
|
155 |
|
156 | var good = 0, bad = 0,
|
157 | tests = id("qunit-tests");
|
158 |
|
159 | config.stats.all += config.assertions.length;
|
160 | config.moduleStats.all += config.assertions.length;
|
161 |
|
162 | if ( tests ) {
|
163 | var ol = document.createElement("ol");
|
164 | ol.style.display = "none";
|
165 |
|
166 | for ( var i = 0; i < config.assertions.length; i++ ) {
|
167 | var assertion = config.assertions[i];
|
168 |
|
169 | var li = document.createElement("li");
|
170 | li.className = assertion.result ? "pass" : "fail";
|
171 | li.appendChild(document.createTextNode(assertion.message || "(no message)"));
|
172 | ol.appendChild( li );
|
173 |
|
174 | if ( assertion.result ) {
|
175 | good++;
|
176 | } else {
|
177 | bad++;
|
178 | config.stats.bad++;
|
179 | config.moduleStats.bad++;
|
180 | }
|
181 | }
|
182 |
|
183 | var b = document.createElement("strong");
|
184 | b.innerHTML = name + " <b style='color:black;'>(<b class='fail'>" + bad + "</b>, <b class='pass'>" + good + "</b>, " + config.assertions.length + ")</b>";
|
185 |
|
186 | addEvent(b, "click", function() {
|
187 | var next = b.nextSibling, display = next.style.display;
|
188 | next.style.display = display === "none" ? "block" : "none";
|
189 | });
|
190 |
|
191 | addEvent(b, "dblclick", function(e) {
|
192 | var target = e && e.target ? e.target : window.event.srcElement;
|
193 | if ( target.nodeName.toLowerCase() === "strong" ) {
|
194 | var text = "", node = target.firstChild;
|
195 |
|
196 | while ( node.nodeType === 3 ) {
|
197 | text += node.nodeValue;
|
198 | node = node.nextSibling;
|
199 | }
|
200 |
|
201 | text = text.replace(/(^\s*|\s*$)/g, "");
|
202 |
|
203 | if ( window.location ) {
|
204 | window.location.href = window.location.href.match(/^(.+?)(\?.*)?$/)[1] + "?" + encodeURIComponent(text);
|
205 | }
|
206 | }
|
207 | });
|
208 |
|
209 | var li = document.createElement("li");
|
210 | li.className = bad ? "fail" : "pass";
|
211 | li.appendChild( b );
|
212 | li.appendChild( ol );
|
213 | tests.appendChild( li );
|
214 |
|
215 | if ( bad ) {
|
216 | var toolbar = id("qunit-testrunner-toolbar");
|
217 | if ( toolbar ) {
|
218 | toolbar.style.display = "block";
|
219 | id("qunit-filter-pass").disabled = null;
|
220 | id("qunit-filter-missing").disabled = null;
|
221 | }
|
222 | }
|
223 |
|
224 | } else {
|
225 | for ( var i = 0; i < config.assertions.length; i++ ) {
|
226 | if ( !config.assertions[i].result ) {
|
227 | bad++;
|
228 | config.stats.bad++;
|
229 | config.moduleStats.bad++;
|
230 | }
|
231 | }
|
232 | }
|
233 |
|
234 | QUnit.testDone( testName, bad, config.assertions.length );
|
235 |
|
236 | if ( !window.setTimeout && !config.queue.length ) {
|
237 | done();
|
238 | }
|
239 | });
|
240 |
|
241 | if ( window.setTimeout && !config.doneTimer ) {
|
242 | config.doneTimer = window.setTimeout(function(){
|
243 | if ( !config.queue.length ) {
|
244 | done();
|
245 | } else {
|
246 | synchronize( done );
|
247 | }
|
248 | }, 13);
|
249 | }
|
250 | },
|
251 |
|
252 | |
253 |
|
254 |
|
255 | expect: function(asserts) {
|
256 | config.expected = asserts;
|
257 | },
|
258 |
|
259 | |
260 |
|
261 |
|
262 |
|
263 | ok: function(a, msg) {
|
264 | QUnit.log(a, msg);
|
265 |
|
266 | config.assertions.push({
|
267 | result: !!a,
|
268 | message: msg
|
269 | });
|
270 | },
|
271 |
|
272 | |
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 | equal: function(actual, expected, message) {
|
285 | push(expected == actual, actual, expected, message);
|
286 | },
|
287 |
|
288 | notEqual: function(actual, expected, message) {
|
289 | push(expected != actual, actual, expected, message);
|
290 | },
|
291 |
|
292 | deepEqual: function(a, b, message) {
|
293 | push(QUnit.equiv(a, b), a, b, message);
|
294 | },
|
295 |
|
296 | notDeepEqual: function(a, b, message) {
|
297 | push(!QUnit.equiv(a, b), a, b, message);
|
298 | },
|
299 |
|
300 | strictEqual: function(actual, expected, message) {
|
301 | push(expected === actual, actual, expected, message);
|
302 | },
|
303 |
|
304 | notStrictEqual: function(actual, expected, message) {
|
305 | push(expected !== actual, actual, expected, message);
|
306 | },
|
307 |
|
308 | start: function() {
|
309 |
|
310 | if ( window.setTimeout ) {
|
311 | window.setTimeout(function() {
|
312 | if ( config.timeout ) {
|
313 | clearTimeout(config.timeout);
|
314 | }
|
315 |
|
316 | config.blocking = false;
|
317 | process();
|
318 | }, 13);
|
319 | } else {
|
320 | config.blocking = false;
|
321 | process();
|
322 | }
|
323 | },
|
324 |
|
325 | stop: function(timeout) {
|
326 | config.blocking = true;
|
327 |
|
328 | if ( timeout && window.setTimeout ) {
|
329 | config.timeout = window.setTimeout(function() {
|
330 | QUnit.ok( false, "Test timed out" );
|
331 | QUnit.start();
|
332 | }, timeout);
|
333 | }
|
334 | },
|
335 |
|
336 | |
337 |
|
338 |
|
339 | reset: function() {
|
340 | if ( window.jQuery ) {
|
341 | jQuery("#main").html( config.fixture );
|
342 | jQuery.event.global = {};
|
343 | jQuery.ajaxSettings = extend({}, config.ajaxSettings);
|
344 | }
|
345 | },
|
346 |
|
347 | |
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 | triggerEvent: function( elem, type, event ) {
|
356 | if ( document.createEvent ) {
|
357 | event = document.createEvent("MouseEvents");
|
358 | event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView,
|
359 | 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
360 | elem.dispatchEvent( event );
|
361 |
|
362 | } else if ( elem.fireEvent ) {
|
363 | elem.fireEvent("on"+type);
|
364 | }
|
365 | },
|
366 |
|
367 |
|
368 | is: function( type, obj ) {
|
369 | return Object.prototype.toString.call( obj ) === "[object "+ type +"]";
|
370 | },
|
371 |
|
372 |
|
373 | done: function(failures, total) {},
|
374 | log: function(result, message) {},
|
375 | testStart: function(name) {},
|
376 | testDone: function(name, failures, total) {},
|
377 | moduleStart: function(name, testEnvironment) {},
|
378 | moduleDone: function(name, failures, total) {}
|
379 | };
|
380 |
|
381 |
|
382 | QUnit.equals = QUnit.equal;
|
383 | QUnit.same = QUnit.deepEqual;
|
384 |
|
385 |
|
386 | var config = {
|
387 |
|
388 | queue: [],
|
389 |
|
390 |
|
391 | blocking: true
|
392 | };
|
393 |
|
394 |
|
395 | (function() {
|
396 | var location = window.location || { search: "", protocol: "file:" },
|
397 | GETParams = location.search.slice(1).split('&');
|
398 |
|
399 | for ( var i = 0; i < GETParams.length; i++ ) {
|
400 | GETParams[i] = decodeURIComponent( GETParams[i] );
|
401 | if ( GETParams[i] === "noglobals" ) {
|
402 | GETParams.splice( i, 1 );
|
403 | i--;
|
404 | config.noglobals = true;
|
405 | } else if ( GETParams[i].search('=') > -1 ) {
|
406 | GETParams.splice( i, 1 );
|
407 | i--;
|
408 | }
|
409 | }
|
410 |
|
411 |
|
412 | config.filters = GETParams;
|
413 |
|
414 |
|
415 | QUnit.isLocal = !!(location.protocol === 'file:');
|
416 | })();
|
417 |
|
418 |
|
419 |
|
420 | if ( typeof exports === "undefined" || typeof require === "undefined" ) {
|
421 | extend(window, QUnit);
|
422 | window.QUnit = QUnit;
|
423 | } else {
|
424 | extend(exports, QUnit);
|
425 | exports.QUnit = QUnit;
|
426 | }
|
427 |
|
428 | if ( typeof document === "undefined" || document.readyState === "complete" ) {
|
429 | config.autorun = true;
|
430 | }
|
431 |
|
432 | addEvent(window, "load", function() {
|
433 |
|
434 | var oldconfig = extend({}, config);
|
435 | QUnit.init();
|
436 | extend(config, oldconfig);
|
437 |
|
438 | config.blocking = false;
|
439 |
|
440 | var userAgent = id("qunit-userAgent");
|
441 | if ( userAgent ) {
|
442 | userAgent.innerHTML = navigator.userAgent;
|
443 | }
|
444 |
|
445 | var toolbar = id("qunit-testrunner-toolbar");
|
446 | if ( toolbar ) {
|
447 | toolbar.style.display = "none";
|
448 |
|
449 | var filter = document.createElement("input");
|
450 | filter.type = "checkbox";
|
451 | filter.id = "qunit-filter-pass";
|
452 | filter.disabled = true;
|
453 | addEvent( filter, "click", function() {
|
454 | var li = document.getElementsByTagName("li");
|
455 | for ( var i = 0; i < li.length; i++ ) {
|
456 | if ( li[i].className.indexOf("pass") > -1 ) {
|
457 | li[i].style.display = filter.checked ? "none" : "";
|
458 | }
|
459 | }
|
460 | });
|
461 | toolbar.appendChild( filter );
|
462 |
|
463 | var label = document.createElement("label");
|
464 | label.setAttribute("for", "qunit-filter-pass");
|
465 | label.innerHTML = "Hide passed tests";
|
466 | toolbar.appendChild( label );
|
467 |
|
468 | var missing = document.createElement("input");
|
469 | missing.type = "checkbox";
|
470 | missing.id = "qunit-filter-missing";
|
471 | missing.disabled = true;
|
472 | addEvent( missing, "click", function() {
|
473 | var li = document.getElementsByTagName("li");
|
474 | for ( var i = 0; i < li.length; i++ ) {
|
475 | if ( li[i].className.indexOf("fail") > -1 && li[i].innerHTML.indexOf('missing test - untested code is broken code') > - 1 ) {
|
476 | li[i].parentNode.parentNode.style.display = missing.checked ? "none" : "block";
|
477 | }
|
478 | }
|
479 | });
|
480 | toolbar.appendChild( missing );
|
481 |
|
482 | label = document.createElement("label");
|
483 | label.setAttribute("for", "qunit-filter-missing");
|
484 | label.innerHTML = "Hide missing tests (untested code is broken code)";
|
485 | toolbar.appendChild( label );
|
486 | }
|
487 |
|
488 | var main = id('main');
|
489 | if ( main ) {
|
490 | config.fixture = main.innerHTML;
|
491 | }
|
492 |
|
493 | if ( window.jQuery ) {
|
494 | config.ajaxSettings = window.jQuery.ajaxSettings;
|
495 | }
|
496 |
|
497 | QUnit.start();
|
498 | });
|
499 |
|
500 | function done() {
|
501 | if ( config.doneTimer && window.clearTimeout ) {
|
502 | window.clearTimeout( config.doneTimer );
|
503 | config.doneTimer = null;
|
504 | }
|
505 |
|
506 | if ( config.queue.length ) {
|
507 | config.doneTimer = window.setTimeout(function(){
|
508 | if ( !config.queue.length ) {
|
509 | done();
|
510 | } else {
|
511 | synchronize( done );
|
512 | }
|
513 | }, 13);
|
514 |
|
515 | return;
|
516 | }
|
517 |
|
518 | config.autorun = true;
|
519 |
|
520 |
|
521 | if ( config.currentModule ) {
|
522 | QUnit.moduleDone( config.currentModule, config.moduleStats.bad, config.moduleStats.all );
|
523 | }
|
524 |
|
525 | var banner = id("qunit-banner"),
|
526 | tests = id("qunit-tests"),
|
527 | html = ['Tests completed in ',
|
528 | +new Date - config.started, ' milliseconds.<br/>',
|
529 | '<span class="passed">', config.stats.all - config.stats.bad, '</span> tests of <span class="total">', config.stats.all, '</span> passed, <span class="failed">', config.stats.bad,'</span> failed.'].join('');
|
530 |
|
531 | if ( banner ) {
|
532 | banner.className = (config.stats.bad ? "qunit-fail" : "qunit-pass");
|
533 | }
|
534 |
|
535 | if ( tests ) {
|
536 | var result = id("qunit-testresult");
|
537 |
|
538 | if ( !result ) {
|
539 | result = document.createElement("p");
|
540 | result.id = "qunit-testresult";
|
541 | result.className = "result";
|
542 | tests.parentNode.insertBefore( result, tests.nextSibling );
|
543 | }
|
544 |
|
545 | result.innerHTML = html;
|
546 | }
|
547 |
|
548 | QUnit.done( config.stats.bad, config.stats.all );
|
549 | }
|
550 |
|
551 | function validTest( name ) {
|
552 | var i = config.filters.length,
|
553 | run = false;
|
554 |
|
555 | if ( !i ) {
|
556 | return true;
|
557 | }
|
558 |
|
559 | while ( i-- ) {
|
560 | var filter = config.filters[i],
|
561 | not = filter.charAt(0) == '!';
|
562 |
|
563 | if ( not ) {
|
564 | filter = filter.slice(1);
|
565 | }
|
566 |
|
567 | if ( name.indexOf(filter) !== -1 ) {
|
568 | return !not;
|
569 | }
|
570 |
|
571 | if ( not ) {
|
572 | run = true;
|
573 | }
|
574 | }
|
575 |
|
576 | return run;
|
577 | }
|
578 |
|
579 | function push(result, actual, expected, message) {
|
580 | message = message || (result ? "okay" : "failed");
|
581 | QUnit.ok( result, result ? message + ": " + expected : message + ", expected: " + QUnit.jsDump.parse(expected) + " result: " + QUnit.jsDump.parse(actual) );
|
582 | }
|
583 |
|
584 | function synchronize( callback ) {
|
585 | config.queue.push( callback );
|
586 |
|
587 | if ( config.autorun && !config.blocking ) {
|
588 | process();
|
589 | }
|
590 | }
|
591 |
|
592 | function process() {
|
593 | while ( config.queue.length && !config.blocking ) {
|
594 | config.queue.shift()();
|
595 | }
|
596 | }
|
597 |
|
598 | function saveGlobal() {
|
599 | config.pollution = [];
|
600 |
|
601 | if ( config.noglobals ) {
|
602 | for ( var key in window ) {
|
603 | config.pollution.push( key );
|
604 | }
|
605 | }
|
606 | }
|
607 |
|
608 | function checkPollution( name ) {
|
609 | var old = config.pollution;
|
610 | saveGlobal();
|
611 |
|
612 | var newGlobals = diff( old, config.pollution );
|
613 | if ( newGlobals.length > 0 ) {
|
614 | ok( false, "Introduced global variable(s): " + newGlobals.join(", ") );
|
615 | config.expected++;
|
616 | }
|
617 |
|
618 | var deletedGlobals = diff( config.pollution, old );
|
619 | if ( deletedGlobals.length > 0 ) {
|
620 | ok( false, "Deleted global variable(s): " + deletedGlobals.join(", ") );
|
621 | config.expected++;
|
622 | }
|
623 | }
|
624 |
|
625 |
|
626 | function diff( a, b ) {
|
627 | var result = a.slice();
|
628 | for ( var i = 0; i < result.length; i++ ) {
|
629 | for ( var j = 0; j < b.length; j++ ) {
|
630 | if ( result[i] === b[j] ) {
|
631 | result.splice(i, 1);
|
632 | i--;
|
633 | break;
|
634 | }
|
635 | }
|
636 | }
|
637 | return result;
|
638 | }
|
639 |
|
640 | function fail(message, exception, callback) {
|
641 | if ( typeof console !== "undefined" && console.error && console.warn ) {
|
642 | console.error(message);
|
643 | console.error(exception);
|
644 | console.warn(callback.toString());
|
645 |
|
646 | } else if ( window.opera && opera.postError ) {
|
647 | opera.postError(message, exception, callback.toString);
|
648 | }
|
649 | }
|
650 |
|
651 | function extend(a, b) {
|
652 | for ( var prop in b ) {
|
653 | a[prop] = b[prop];
|
654 | }
|
655 |
|
656 | return a;
|
657 | }
|
658 |
|
659 | function addEvent(elem, type, fn) {
|
660 | if ( elem.addEventListener ) {
|
661 | elem.addEventListener( type, fn, false );
|
662 | } else if ( elem.attachEvent ) {
|
663 | elem.attachEvent( "on" + type, fn );
|
664 | } else {
|
665 | fn();
|
666 | }
|
667 | }
|
668 |
|
669 | function id(name) {
|
670 | return !!(typeof document !== "undefined" && document && document.getElementById) &&
|
671 | document.getElementById( name );
|
672 | }
|
673 |
|
674 |
|
675 |
|
676 |
|
677 |
|
678 | QUnit.equiv = function () {
|
679 |
|
680 | var innerEquiv;
|
681 | var callers = [];
|
682 |
|
683 |
|
684 |
|
685 | function hoozit(o) {
|
686 | if (QUnit.is("String", o)) {
|
687 | return "string";
|
688 |
|
689 | } else if (QUnit.is("Boolean", o)) {
|
690 | return "boolean";
|
691 |
|
692 | } else if (QUnit.is("Number", o)) {
|
693 |
|
694 | if (isNaN(o)) {
|
695 | return "nan";
|
696 | } else {
|
697 | return "number";
|
698 | }
|
699 |
|
700 | } else if (typeof o === "undefined") {
|
701 | return "undefined";
|
702 |
|
703 |
|
704 | } else if (o === null) {
|
705 | return "null";
|
706 |
|
707 |
|
708 | } else if (QUnit.is( "Array", o)) {
|
709 | return "array";
|
710 |
|
711 |
|
712 | } else if (QUnit.is( "Date", o)) {
|
713 | return "date";
|
714 |
|
715 |
|
716 |
|
717 |
|
718 |
|
719 | } else if (QUnit.is( "RegExp", o)) {
|
720 | return "regexp";
|
721 |
|
722 | } else if (typeof o === "object") {
|
723 | return "object";
|
724 |
|
725 | } else if (QUnit.is( "Function", o)) {
|
726 | return "function";
|
727 | } else {
|
728 | return undefined;
|
729 | }
|
730 | }
|
731 |
|
732 |
|
733 | function bindCallbacks(o, callbacks, args) {
|
734 | var prop = hoozit(o);
|
735 | if (prop) {
|
736 | if (hoozit(callbacks[prop]) === "function") {
|
737 | return callbacks[prop].apply(callbacks, args);
|
738 | } else {
|
739 | return callbacks[prop];
|
740 | }
|
741 | }
|
742 | }
|
743 |
|
744 | var callbacks = function () {
|
745 |
|
746 |
|
747 | function useStrictEquality(b, a) {
|
748 | if (b instanceof a.constructor || a instanceof b.constructor) {
|
749 |
|
750 |
|
751 |
|
752 | return a == b;
|
753 | } else {
|
754 | return a === b;
|
755 | }
|
756 | }
|
757 |
|
758 | return {
|
759 | "string": useStrictEquality,
|
760 | "boolean": useStrictEquality,
|
761 | "number": useStrictEquality,
|
762 | "null": useStrictEquality,
|
763 | "undefined": useStrictEquality,
|
764 |
|
765 | "nan": function (b) {
|
766 | return isNaN(b);
|
767 | },
|
768 |
|
769 | "date": function (b, a) {
|
770 | return hoozit(b) === "date" && a.valueOf() === b.valueOf();
|
771 | },
|
772 |
|
773 | "regexp": function (b, a) {
|
774 | return hoozit(b) === "regexp" &&
|
775 | a.source === b.source &&
|
776 | a.global === b.global &&
|
777 | a.ignoreCase === b.ignoreCase &&
|
778 | a.multiline === b.multiline;
|
779 | },
|
780 |
|
781 |
|
782 |
|
783 |
|
784 | "function": function () {
|
785 | var caller = callers[callers.length - 1];
|
786 | return caller !== Object &&
|
787 | typeof caller !== "undefined";
|
788 | },
|
789 |
|
790 | "array": function (b, a) {
|
791 | var i;
|
792 | var len;
|
793 |
|
794 |
|
795 | if ( ! (hoozit(b) === "array")) {
|
796 | return false;
|
797 | }
|
798 |
|
799 | len = a.length;
|
800 | if (len !== b.length) {
|
801 | return false;
|
802 | }
|
803 | for (i = 0; i < len; i++) {
|
804 | if ( ! innerEquiv(a[i], b[i])) {
|
805 | return false;
|
806 | }
|
807 | }
|
808 | return true;
|
809 | },
|
810 |
|
811 | "object": function (b, a) {
|
812 | var i;
|
813 | var eq = true;
|
814 | var aProperties = [], bProperties = [];
|
815 |
|
816 |
|
817 | if ( a.constructor !== b.constructor) {
|
818 | return false;
|
819 | }
|
820 |
|
821 |
|
822 | callers.push(a.constructor);
|
823 |
|
824 | for (i in a) {
|
825 |
|
826 | aProperties.push(i);
|
827 |
|
828 | if ( ! innerEquiv(a[i], b[i])) {
|
829 | eq = false;
|
830 | break;
|
831 | }
|
832 | }
|
833 |
|
834 | callers.pop();
|
835 |
|
836 | for (i in b) {
|
837 | bProperties.push(i);
|
838 | }
|
839 |
|
840 |
|
841 | return eq && innerEquiv(aProperties.sort(), bProperties.sort());
|
842 | }
|
843 | };
|
844 | }();
|
845 |
|
846 | innerEquiv = function () {
|
847 | var args = Array.prototype.slice.apply(arguments);
|
848 | if (args.length < 2) {
|
849 | return true;
|
850 | }
|
851 |
|
852 | return (function (a, b) {
|
853 | if (a === b) {
|
854 | return true;
|
855 | } else if (a === null || b === null || typeof a === "undefined" || typeof b === "undefined" || hoozit(a) !== hoozit(b)) {
|
856 | return false;
|
857 | } else {
|
858 | return bindCallbacks(a, callbacks, [b, a]);
|
859 | }
|
860 |
|
861 |
|
862 | })(args[0], args[1]) && arguments.callee.apply(this, args.splice(1, args.length -1));
|
863 | };
|
864 |
|
865 | return innerEquiv;
|
866 |
|
867 | }();
|
868 |
|
869 |
|
870 |
|
871 |
|
872 |
|
873 |
|
874 |
|
875 |
|
876 |
|
877 |
|
878 |
|
879 | QUnit.jsDump = (function() {
|
880 | function quote( str ) {
|
881 | return '"' + str.toString().replace(/"/g, '\\"') + '"';
|
882 | };
|
883 | function literal( o ) {
|
884 | return o + '';
|
885 | };
|
886 | function join( pre, arr, post ) {
|
887 | var s = jsDump.separator(),
|
888 | base = jsDump.indent(),
|
889 | inner = jsDump.indent(1);
|
890 | if ( arr.join )
|
891 | arr = arr.join( ',' + s + inner );
|
892 | if ( !arr )
|
893 | return pre + post;
|
894 | return [ pre, inner + arr, base + post ].join(s);
|
895 | };
|
896 | function array( arr ) {
|
897 | var i = arr.length, ret = Array(i);
|
898 | this.up();
|
899 | while ( i-- )
|
900 | ret[i] = this.parse( arr[i] );
|
901 | this.down();
|
902 | return join( '[', ret, ']' );
|
903 | };
|
904 |
|
905 | var reName = /^function (\w+)/;
|
906 |
|
907 | var jsDump = {
|
908 | parse:function( obj, type ) {
|
909 | var parser = this.parsers[ type || this.typeOf(obj) ];
|
910 | type = typeof parser;
|
911 |
|
912 | return type == 'function' ? parser.call( this, obj ) :
|
913 | type == 'string' ? parser :
|
914 | this.parsers.error;
|
915 | },
|
916 | typeOf:function( obj ) {
|
917 | var type;
|
918 | if ( obj === null ) {
|
919 | type = "null";
|
920 | } else if (typeof obj === "undefined") {
|
921 | type = "undefined";
|
922 | } else if (QUnit.is("RegExp", obj)) {
|
923 | type = "regexp";
|
924 | } else if (QUnit.is("Date", obj)) {
|
925 | type = "date";
|
926 | } else if (QUnit.is("Function", obj)) {
|
927 | type = "function";
|
928 | } else if (QUnit.is("Array", obj)) {
|
929 | type = "array";
|
930 | } else if (QUnit.is("Window", obj) || QUnit.is("global", obj)) {
|
931 | type = "window";
|
932 | } else if (QUnit.is("HTMLDocument", obj)) {
|
933 | type = "document";
|
934 | } else if (QUnit.is("HTMLCollection", obj) || QUnit.is("NodeList", obj)) {
|
935 | type = "nodelist";
|
936 | } else if (/^\[object HTML/.test(Object.prototype.toString.call( obj ))) {
|
937 | type = "node";
|
938 | } else {
|
939 | type = typeof obj;
|
940 | }
|
941 | return type;
|
942 | },
|
943 | separator:function() {
|
944 | return this.multiline ? this.HTML ? '<br />' : '\n' : this.HTML ? ' ' : ' ';
|
945 | },
|
946 | indent:function( extra ) {
|
947 | if ( !this.multiline )
|
948 | return '';
|
949 | var chr = this.indentChar;
|
950 | if ( this.HTML )
|
951 | chr = chr.replace(/\t/g,' ').replace(/ /g,' ');
|
952 | return Array( this._depth_ + (extra||0) ).join(chr);
|
953 | },
|
954 | up:function( a ) {
|
955 | this._depth_ += a || 1;
|
956 | },
|
957 | down:function( a ) {
|
958 | this._depth_ -= a || 1;
|
959 | },
|
960 | setParser:function( name, parser ) {
|
961 | this.parsers[name] = parser;
|
962 | },
|
963 |
|
964 | quote:quote,
|
965 | literal:literal,
|
966 | join:join,
|
967 |
|
968 | _depth_: 1,
|
969 |
|
970 | parsers:{
|
971 | window: '[Window]',
|
972 | document: '[Document]',
|
973 | error:'[ERROR]',
|
974 | unknown: '[Unknown]',
|
975 | 'null':'null',
|
976 | undefined:'undefined',
|
977 | 'function':function( fn ) {
|
978 | var ret = 'function',
|
979 | name = 'name' in fn ? fn.name : (reName.exec(fn)||[])[1];
|
980 | if ( name )
|
981 | ret += ' ' + name;
|
982 | ret += '(';
|
983 |
|
984 | ret = [ ret, this.parse( fn, 'functionArgs' ), '){'].join('');
|
985 | return join( ret, this.parse(fn,'functionCode'), '}' );
|
986 | },
|
987 | array: array,
|
988 | nodelist: array,
|
989 | arguments: array,
|
990 | object:function( map ) {
|
991 | var ret = [ ];
|
992 | this.up();
|
993 | for ( var key in map )
|
994 | ret.push( this.parse(key,'key') + ': ' + this.parse(map[key]) );
|
995 | this.down();
|
996 | return join( '{', ret, '}' );
|
997 | },
|
998 | node:function( node ) {
|
999 | var open = this.HTML ? '<' : '<',
|
1000 | close = this.HTML ? '>' : '>';
|
1001 |
|
1002 | var tag = node.nodeName.toLowerCase(),
|
1003 | ret = open + tag;
|
1004 |
|
1005 | for ( var a in this.DOMAttrs ) {
|
1006 | var val = node[this.DOMAttrs[a]];
|
1007 | if ( val )
|
1008 | ret += ' ' + a + '=' + this.parse( val, 'attribute' );
|
1009 | }
|
1010 | return ret + close + open + '/' + tag + close;
|
1011 | },
|
1012 | functionArgs:function( fn ) {
|
1013 | var l = fn.length;
|
1014 | if ( !l ) return '';
|
1015 |
|
1016 | var args = Array(l);
|
1017 | while ( l-- )
|
1018 | args[l] = String.fromCharCode(97+l);
|
1019 | return ' ' + args.join(', ') + ' ';
|
1020 | },
|
1021 | key:quote,
|
1022 | functionCode:'[code]',
|
1023 | attribute:quote,
|
1024 | string:quote,
|
1025 | date:quote,
|
1026 | regexp:literal,
|
1027 | number:literal,
|
1028 | 'boolean':literal
|
1029 | },
|
1030 | DOMAttrs:{
|
1031 | id:'id',
|
1032 | name:'name',
|
1033 | 'class':'className'
|
1034 | },
|
1035 | HTML:true,
|
1036 | indentChar:' ',
|
1037 | multiline:true
|
1038 | };
|
1039 |
|
1040 | return jsDump;
|
1041 | })();
|
1042 |
|
1043 | })(this);
|