Merge "Added result properties to action=paraminfo"
[lhc/web/wiklou.git] / resources / jquery / jquery.qunit.js
1 /**
2 * QUnit v1.7.0 - A JavaScript Unit Testing Framework
3 *
4 * http://docs.jquery.com/QUnit
5 *
6 * Copyright (c) 2012 John Resig, Jörn Zaefferer
7 * Dual licensed under the MIT (MIT-LICENSE.txt)
8 * or GPL (GPL-LICENSE.txt) licenses.
9 */
10
11 (function( window ) {
12
13 var QUnit,
14 config,
15 testId = 0,
16 fileName = (sourceFromStacktrace( 0 ) || "" ).replace(/(:\d+)+\)?/, "").replace(/.+\//, ""),
17 toString = Object.prototype.toString,
18 hasOwn = Object.prototype.hasOwnProperty,
19 defined = {
20 setTimeout: typeof window.setTimeout !== "undefined",
21 sessionStorage: (function() {
22 var x = "qunit-test-string";
23 try {
24 sessionStorage.setItem( x, x );
25 sessionStorage.removeItem( x );
26 return true;
27 } catch( e ) {
28 return false;
29 }
30 }())
31 };
32
33 function Test( settings ) {
34 extend( this, settings );
35 this.assertions = [];
36 this.testNumber = ++Test.count;
37 }
38
39 Test.count = 0;
40
41 Test.prototype = {
42 init: function() {
43 var a, b, li,
44 tests = id( "qunit-tests" );
45
46 if ( tests ) {
47 b = document.createElement( "strong" );
48 b.innerHTML = this.name;
49
50 // `a` initialized at top of scope
51 a = document.createElement( "a" );
52 a.innerHTML = "Rerun";
53 a.href = QUnit.url({ testNumber: this.testNumber });
54
55 li = document.createElement( "li" );
56 li.appendChild( b );
57 li.appendChild( a );
58 li.className = "running";
59 li.id = this.id = "qunit-test-output" + testId++;
60
61 tests.appendChild( li );
62 }
63 },
64 setup: function() {
65 if ( this.module !== config.previousModule ) {
66 if ( config.previousModule ) {
67 runLoggingCallbacks( "moduleDone", QUnit, {
68 name: config.previousModule,
69 failed: config.moduleStats.bad,
70 passed: config.moduleStats.all - config.moduleStats.bad,
71 total: config.moduleStats.all
72 });
73 }
74 config.previousModule = this.module;
75 config.moduleStats = { all: 0, bad: 0 };
76 runLoggingCallbacks( "moduleStart", QUnit, {
77 name: this.module
78 });
79 } else if ( config.autorun ) {
80 runLoggingCallbacks( "moduleStart", QUnit, {
81 name: this.module
82 });
83 }
84
85 config.current = this;
86
87 this.testEnvironment = extend({
88 setup: function() {},
89 teardown: function() {}
90 }, this.moduleTestEnvironment );
91
92 runLoggingCallbacks( "testStart", QUnit, {
93 name: this.testName,
94 module: this.module
95 });
96
97 // allow utility functions to access the current test environment
98 // TODO why??
99 QUnit.current_testEnvironment = this.testEnvironment;
100
101 if ( !config.pollution ) {
102 saveGlobal();
103 }
104 if ( config.notrycatch ) {
105 this.testEnvironment.setup.call( this.testEnvironment );
106 return;
107 }
108 try {
109 this.testEnvironment.setup.call( this.testEnvironment );
110 } catch( e ) {
111 QUnit.pushFailure( "Setup failed on " + this.testName + ": " + e.message, extractStacktrace( e, 1 ) );
112 }
113 },
114 run: function() {
115 config.current = this;
116
117 var running = id( "qunit-testresult" );
118
119 if ( running ) {
120 running.innerHTML = "Running: <br/>" + this.name;
121 }
122
123 if ( this.async ) {
124 QUnit.stop();
125 }
126
127 if ( config.notrycatch ) {
128 this.callback.call( this.testEnvironment, QUnit.assert );
129 return;
130 }
131
132 try {
133 this.callback.call( this.testEnvironment, QUnit.assert );
134 } catch( e ) {
135 QUnit.pushFailure( "Died on test #" + (this.assertions.length + 1) + " " + this.stack + ": " + e.message, extractStacktrace( e, 0 ) );
136 // else next test will carry the responsibility
137 saveGlobal();
138
139 // Restart the tests if they're blocking
140 if ( config.blocking ) {
141 QUnit.start();
142 }
143 }
144 },
145 teardown: function() {
146 config.current = this;
147 if ( config.notrycatch ) {
148 this.testEnvironment.teardown.call( this.testEnvironment );
149 return;
150 } else {
151 try {
152 this.testEnvironment.teardown.call( this.testEnvironment );
153 } catch( e ) {
154 QUnit.pushFailure( "Teardown failed on " + this.testName + ": " + e.message, extractStacktrace( e, 1 ) );
155 }
156 }
157 checkPollution();
158 },
159 finish: function() {
160 config.current = this;
161 if ( config.requireExpects && this.expected == null ) {
162 QUnit.pushFailure( "Expected number of assertions to be defined, but expect() was not called.", this.stack );
163 } else if ( this.expected != null && this.expected != this.assertions.length ) {
164 QUnit.pushFailure( "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run", this.stack );
165 } else if ( this.expected == null && !this.assertions.length ) {
166 QUnit.pushFailure( "Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.", this.stack );
167 }
168
169 var assertion, a, b, i, li, ol,
170 test = this,
171 good = 0,
172 bad = 0,
173 tests = id( "qunit-tests" );
174
175 config.stats.all += this.assertions.length;
176 config.moduleStats.all += this.assertions.length;
177
178 if ( tests ) {
179 ol = document.createElement( "ol" );
180
181 for ( i = 0; i < this.assertions.length; i++ ) {
182 assertion = this.assertions[i];
183
184 li = document.createElement( "li" );
185 li.className = assertion.result ? "pass" : "fail";
186 li.innerHTML = assertion.message || ( assertion.result ? "okay" : "failed" );
187 ol.appendChild( li );
188
189 if ( assertion.result ) {
190 good++;
191 } else {
192 bad++;
193 config.stats.bad++;
194 config.moduleStats.bad++;
195 }
196 }
197
198 // store result when possible
199 if ( QUnit.config.reorder && defined.sessionStorage ) {
200 if ( bad ) {
201 sessionStorage.setItem( "qunit-test-" + this.module + "-" + this.testName, bad );
202 } else {
203 sessionStorage.removeItem( "qunit-test-" + this.module + "-" + this.testName );
204 }
205 }
206
207 if ( bad === 0 ) {
208 ol.style.display = "none";
209 }
210
211 // `b` initialized at top of scope
212 b = document.createElement( "strong" );
213 b.innerHTML = this.name + " <b class='counts'>(<b class='failed'>" + bad + "</b>, <b class='passed'>" + good + "</b>, " + this.assertions.length + ")</b>";
214
215 addEvent(b, "click", function() {
216 var next = b.nextSibling.nextSibling,
217 display = next.style.display;
218 next.style.display = display === "none" ? "block" : "none";
219 });
220
221 addEvent(b, "dblclick", function( e ) {
222 var target = e && e.target ? e.target : window.event.srcElement;
223 if ( target.nodeName.toLowerCase() == "span" || target.nodeName.toLowerCase() == "b" ) {
224 target = target.parentNode;
225 }
226 if ( window.location && target.nodeName.toLowerCase() === "strong" ) {
227 window.location = QUnit.url({ testNumber: test.testNumber });
228 }
229 });
230
231 // `li` initialized at top of scope
232 li = id( this.id );
233 li.className = bad ? "fail" : "pass";
234 li.removeChild( li.firstChild );
235 a = li.firstChild;
236 li.appendChild( b );
237 li.appendChild ( a );
238 li.appendChild( ol );
239
240 } else {
241 for ( i = 0; i < this.assertions.length; i++ ) {
242 if ( !this.assertions[i].result ) {
243 bad++;
244 config.stats.bad++;
245 config.moduleStats.bad++;
246 }
247 }
248 }
249
250 runLoggingCallbacks( "testDone", QUnit, {
251 name: this.testName,
252 module: this.module,
253 failed: bad,
254 passed: this.assertions.length - bad,
255 total: this.assertions.length
256 });
257
258 QUnit.reset();
259 },
260
261 queue: function() {
262 var bad,
263 test = this;
264
265 synchronize(function() {
266 test.init();
267 });
268 function run() {
269 // each of these can by async
270 synchronize(function() {
271 test.setup();
272 });
273 synchronize(function() {
274 test.run();
275 });
276 synchronize(function() {
277 test.teardown();
278 });
279 synchronize(function() {
280 test.finish();
281 });
282 }
283
284 // `bad` initialized at top of scope
285 // defer when previous test run passed, if storage is available
286 bad = QUnit.config.reorder && defined.sessionStorage &&
287 +sessionStorage.getItem( "qunit-test-" + this.module + "-" + this.testName );
288
289 if ( bad ) {
290 run();
291 } else {
292 synchronize( run, true );
293 }
294 }
295 };
296
297 // Root QUnit object.
298 // `QUnit` initialized at top of scope
299 QUnit = {
300
301 // call on start of module test to prepend name to all tests
302 module: function( name, testEnvironment ) {
303 config.currentModule = name;
304 config.currentModuleTestEnviroment = testEnvironment;
305 },
306
307 asyncTest: function( testName, expected, callback ) {
308 if ( arguments.length === 2 ) {
309 callback = expected;
310 expected = null;
311 }
312
313 QUnit.test( testName, expected, callback, true );
314 },
315
316 test: function( testName, expected, callback, async ) {
317 var test,
318 name = "<span class='test-name'>" + escapeInnerText( testName ) + "</span>";
319
320 if ( arguments.length === 2 ) {
321 callback = expected;
322 expected = null;
323 }
324
325 if ( config.currentModule ) {
326 name = "<span class='module-name'>" + config.currentModule + "</span>: " + name;
327 }
328
329 test = new Test({
330 name: name,
331 testName: testName,
332 expected: expected,
333 async: async,
334 callback: callback,
335 module: config.currentModule,
336 moduleTestEnvironment: config.currentModuleTestEnviroment,
337 stack: sourceFromStacktrace( 2 )
338 });
339
340 if ( !validTest( test ) ) {
341 return;
342 }
343
344 test.queue();
345 },
346
347 // Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through.
348 expect: function( asserts ) {
349 config.current.expected = asserts;
350 },
351
352 start: function( count ) {
353 config.semaphore -= count || 1;
354 // don't start until equal number of stop-calls
355 if ( config.semaphore > 0 ) {
356 return;
357 }
358 // ignore if start is called more often then stop
359 if ( config.semaphore < 0 ) {
360 config.semaphore = 0;
361 }
362 // A slight delay, to avoid any current callbacks
363 if ( defined.setTimeout ) {
364 window.setTimeout(function() {
365 if ( config.semaphore > 0 ) {
366 return;
367 }
368 if ( config.timeout ) {
369 clearTimeout( config.timeout );
370 }
371
372 config.blocking = false;
373 process( true );
374 }, 13);
375 } else {
376 config.blocking = false;
377 process( true );
378 }
379 },
380
381 stop: function( count ) {
382 config.semaphore += count || 1;
383 config.blocking = true;
384
385 if ( config.testTimeout && defined.setTimeout ) {
386 clearTimeout( config.timeout );
387 config.timeout = window.setTimeout(function() {
388 QUnit.ok( false, "Test timed out" );
389 config.semaphore = 1;
390 QUnit.start();
391 }, config.testTimeout );
392 }
393 }
394 };
395
396 // Asssert helpers
397 // All of these must call either QUnit.push() or manually do:
398 // - runLoggingCallbacks( "log", .. );
399 // - config.current.assertions.push({ .. });
400 QUnit.assert = {
401 /**
402 * Asserts rough true-ish result.
403 * @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" );
404 */
405 ok: function( result, msg ) {
406 if ( !config.current ) {
407 throw new Error( "ok() assertion outside test context, was " + sourceFromStacktrace(2) );
408 }
409 result = !!result;
410
411 var source,
412 details = {
413 result: result,
414 message: msg
415 };
416
417 msg = escapeInnerText( msg || (result ? "okay" : "failed" ) );
418 msg = "<span class='test-message'>" + msg + "</span>";
419
420 if ( !result ) {
421 source = sourceFromStacktrace( 2 );
422 if ( source ) {
423 details.source = source;
424 msg += "<table><tr class='test-source'><th>Source: </th><td><pre>" + escapeInnerText( source ) + "</pre></td></tr></table>";
425 }
426 }
427 runLoggingCallbacks( "log", QUnit, details );
428 config.current.assertions.push({
429 result: result,
430 message: msg
431 });
432 },
433
434 /**
435 * Assert that the first two arguments are equal, with an optional message.
436 * Prints out both actual and expected values.
437 * @example equal( format( "Received {0} bytes.", 2), "Received 2 bytes.", "format() replaces {0} with next argument" );
438 */
439 equal: function( actual, expected, message ) {
440 QUnit.push( expected == actual, actual, expected, message );
441 },
442
443 notEqual: function( actual, expected, message ) {
444 QUnit.push( expected != actual, actual, expected, message );
445 },
446
447 deepEqual: function( actual, expected, message ) {
448 QUnit.push( QUnit.equiv(actual, expected), actual, expected, message );
449 },
450
451 notDeepEqual: function( actual, expected, message ) {
452 QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message );
453 },
454
455 strictEqual: function( actual, expected, message ) {
456 QUnit.push( expected === actual, actual, expected, message );
457 },
458
459 notStrictEqual: function( actual, expected, message ) {
460 QUnit.push( expected !== actual, actual, expected, message );
461 },
462
463 raises: function( block, expected, message ) {
464 var actual,
465 ok = false;
466
467 if ( typeof expected === "string" ) {
468 message = expected;
469 expected = null;
470 }
471
472 try {
473 block.call( config.current.testEnvironment );
474 } catch (e) {
475 actual = e;
476 }
477
478 if ( actual ) {
479 // we don't want to validate thrown error
480 if ( !expected ) {
481 ok = true;
482 // expected is a regexp
483 } else if ( QUnit.objectType( expected ) === "regexp" ) {
484 ok = expected.test( actual );
485 // expected is a constructor
486 } else if ( actual instanceof expected ) {
487 ok = true;
488 // expected is a validation function which returns true is validation passed
489 } else if ( expected.call( {}, actual ) === true ) {
490 ok = true;
491 }
492 }
493
494 QUnit.push( ok, actual, null, message );
495 }
496 };
497
498 // @deprecated: Kept assertion helpers in root for backwards compatibility
499 extend( QUnit, QUnit.assert );
500
501 /**
502 * @deprecated: Kept for backwards compatibility
503 * next step: remove entirely
504 */
505 QUnit.equals = function() {
506 QUnit.push( false, false, false, "QUnit.equals has been deprecated since 2009 (e88049a0), use QUnit.equal instead" );
507 };
508 QUnit.same = function() {
509 QUnit.push( false, false, false, "QUnit.same has been deprecated since 2009 (e88049a0), use QUnit.deepEqual instead" );
510 };
511
512 // We want access to the constructor's prototype
513 (function() {
514 function F() {}
515 F.prototype = QUnit;
516 QUnit = new F();
517 // Make F QUnit's constructor so that we can add to the prototype later
518 QUnit.constructor = F;
519 }());
520
521 /**
522 * Config object: Maintain internal state
523 * Later exposed as QUnit.config
524 * `config` initialized at top of scope
525 */
526 config = {
527 // The queue of tests to run
528 queue: [],
529
530 // block until document ready
531 blocking: true,
532
533 // when enabled, show only failing tests
534 // gets persisted through sessionStorage and can be changed in UI via checkbox
535 hidepassed: false,
536
537 // by default, run previously failed tests first
538 // very useful in combination with "Hide passed tests" checked
539 reorder: true,
540
541 // by default, modify document.title when suite is done
542 altertitle: true,
543
544 // when enabled, all tests must call expect()
545 requireExpects: false,
546
547 urlConfig: [ "noglobals", "notrycatch" ],
548
549 // logging callback queues
550 begin: [],
551 done: [],
552 log: [],
553 testStart: [],
554 testDone: [],
555 moduleStart: [],
556 moduleDone: []
557 };
558
559 // Initialize more QUnit.config and QUnit.urlParams
560 (function() {
561 var i,
562 location = window.location || { search: "", protocol: "file:" },
563 params = location.search.slice( 1 ).split( "&" ),
564 length = params.length,
565 urlParams = {},
566 current;
567
568 if ( params[ 0 ] ) {
569 for ( i = 0; i < length; i++ ) {
570 current = params[ i ].split( "=" );
571 current[ 0 ] = decodeURIComponent( current[ 0 ] );
572 // allow just a key to turn on a flag, e.g., test.html?noglobals
573 current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true;
574 urlParams[ current[ 0 ] ] = current[ 1 ];
575 }
576 }
577
578 QUnit.urlParams = urlParams;
579 config.filter = urlParams.filter;
580 config.testNumber = parseInt( urlParams.testNumber, 10 ) || null;
581
582 // Figure out if we're running the tests from a server or not
583 QUnit.isLocal = location.protocol === "file:";
584 }());
585
586 // Export global variables, unless an 'exports' object exists,
587 // in that case we assume we're in CommonJS (dealt with on the bottom of the script)
588 if ( typeof exports === "undefined" ) {
589 extend( window, QUnit );
590
591 // Expose QUnit object
592 window.QUnit = QUnit;
593 }
594
595 // Extend QUnit object,
596 // these after set here because they should not be exposed as global functions
597 extend( QUnit, {
598 config: config,
599
600 // Initialize the configuration options
601 init: function() {
602 extend( config, {
603 stats: { all: 0, bad: 0 },
604 moduleStats: { all: 0, bad: 0 },
605 started: +new Date(),
606 updateRate: 1000,
607 blocking: false,
608 autostart: true,
609 autorun: false,
610 filter: "",
611 queue: [],
612 semaphore: 0
613 });
614
615 var tests, banner, result,
616 qunit = id( "qunit" );
617
618 if ( qunit ) {
619 qunit.innerHTML =
620 "<h1 id='qunit-header'>" + escapeInnerText( document.title ) + "</h1>" +
621 "<h2 id='qunit-banner'></h2>" +
622 "<div id='qunit-testrunner-toolbar'></div>" +
623 "<h2 id='qunit-userAgent'></h2>" +
624 "<ol id='qunit-tests'></ol>";
625 }
626
627 tests = id( "qunit-tests" );
628 banner = id( "qunit-banner" );
629 result = id( "qunit-testresult" );
630
631 if ( tests ) {
632 tests.innerHTML = "";
633 }
634
635 if ( banner ) {
636 banner.className = "";
637 }
638
639 if ( result ) {
640 result.parentNode.removeChild( result );
641 }
642
643 if ( tests ) {
644 result = document.createElement( "p" );
645 result.id = "qunit-testresult";
646 result.className = "result";
647 tests.parentNode.insertBefore( result, tests );
648 result.innerHTML = "Running...<br/>&nbsp;";
649 }
650 },
651
652 // Resets the test setup. Useful for tests that modify the DOM.
653 // If jQuery is available, uses jQuery's html(), otherwise just innerHTML.
654 reset: function() {
655 var fixture;
656
657 if ( window.jQuery ) {
658 jQuery( "#qunit-fixture" ).html( config.fixture );
659 } else {
660 fixture = id( "qunit-fixture" );
661 if ( fixture ) {
662 fixture.innerHTML = config.fixture;
663 }
664 }
665 },
666
667 // Trigger an event on an element.
668 // @example triggerEvent( document.body, "click" );
669 triggerEvent: function( elem, type, event ) {
670 if ( document.createEvent ) {
671 event = document.createEvent( "MouseEvents" );
672 event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView,
673 0, 0, 0, 0, 0, false, false, false, false, 0, null);
674
675 elem.dispatchEvent( event );
676 } else if ( elem.fireEvent ) {
677 elem.fireEvent( "on" + type );
678 }
679 },
680
681 // Safe object type checking
682 is: function( type, obj ) {
683 return QUnit.objectType( obj ) == type;
684 },
685
686 objectType: function( obj ) {
687 if ( typeof obj === "undefined" ) {
688 return "undefined";
689 // consider: typeof null === object
690 }
691 if ( obj === null ) {
692 return "null";
693 }
694
695 var type = toString.call( obj ).match(/^\[object\s(.*)\]$/)[1] || "";
696
697 switch ( type ) {
698 case "Number":
699 if ( isNaN(obj) ) {
700 return "nan";
701 }
702 return "number";
703 case "String":
704 case "Boolean":
705 case "Array":
706 case "Date":
707 case "RegExp":
708 case "Function":
709 return type.toLowerCase();
710 }
711 if ( typeof obj === "object" ) {
712 return "object";
713 }
714 return undefined;
715 },
716
717 push: function( result, actual, expected, message ) {
718 if ( !config.current ) {
719 throw new Error( "assertion outside test context, was " + sourceFromStacktrace() );
720 }
721
722 var output, source,
723 details = {
724 result: result,
725 message: message,
726 actual: actual,
727 expected: expected
728 };
729
730 message = escapeInnerText( message ) || ( result ? "okay" : "failed" );
731 message = "<span class='test-message'>" + message + "</span>";
732 output = message;
733
734 if ( !result ) {
735 expected = escapeInnerText( QUnit.jsDump.parse(expected) );
736 actual = escapeInnerText( QUnit.jsDump.parse(actual) );
737 output += "<table><tr class='test-expected'><th>Expected: </th><td><pre>" + expected + "</pre></td></tr>";
738
739 if ( actual != expected ) {
740 output += "<tr class='test-actual'><th>Result: </th><td><pre>" + actual + "</pre></td></tr>";
741 output += "<tr class='test-diff'><th>Diff: </th><td><pre>" + QUnit.diff( expected, actual ) + "</pre></td></tr>";
742 }
743
744 source = sourceFromStacktrace();
745
746 if ( source ) {
747 details.source = source;
748 output += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeInnerText( source ) + "</pre></td></tr>";
749 }
750
751 output += "</table>";
752 }
753
754 runLoggingCallbacks( "log", QUnit, details );
755
756 config.current.assertions.push({
757 result: !!result,
758 message: output
759 });
760 },
761
762 pushFailure: function( message, source ) {
763 var output,
764 details = {
765 result: false,
766 message: message
767 };
768
769 message = escapeInnerText(message ) || "error";
770 message = "<span class='test-message'>" + message + "</span>";
771 output = message;
772
773 if ( source ) {
774 details.source = source;
775 output += "<table><tr class='test-source'><th>Source: </th><td><pre>" + escapeInnerText( source ) + "</pre></td></tr></table>";
776 }
777
778 runLoggingCallbacks( "log", QUnit, details );
779
780 config.current.assertions.push({
781 result: false,
782 message: output
783 });
784 },
785
786 url: function( params ) {
787 params = extend( extend( {}, QUnit.urlParams ), params );
788 var key,
789 querystring = "?";
790
791 for ( key in params ) {
792 if ( !hasOwn.call( params, key ) ) {
793 continue;
794 }
795 querystring += encodeURIComponent( key ) + "=" +
796 encodeURIComponent( params[ key ] ) + "&";
797 }
798 return window.location.pathname + querystring.slice( 0, -1 );
799 },
800
801 extend: extend,
802 id: id,
803 addEvent: addEvent
804 // load, equiv, jsDump, diff: Attached later
805 });
806
807 /**
808 * @deprecated: Created for backwards compatibility with test runner that set the hook function
809 * into QUnit.{hook}, instead of invoking it and passing the hook function.
810 * QUnit.constructor is set to the empty F() above so that we can add to it's prototype here.
811 * Doing this allows us to tell if the following methods have been overwritten on the actual
812 * QUnit object.
813 */
814 extend( QUnit.constructor.prototype, {
815
816 // Logging callbacks; all receive a single argument with the listed properties
817 // run test/logs.html for any related changes
818 begin: registerLoggingCallback( "begin" ),
819
820 // done: { failed, passed, total, runtime }
821 done: registerLoggingCallback( "done" ),
822
823 // log: { result, actual, expected, message }
824 log: registerLoggingCallback( "log" ),
825
826 // testStart: { name }
827 testStart: registerLoggingCallback( "testStart" ),
828
829 // testDone: { name, failed, passed, total }
830 testDone: registerLoggingCallback( "testDone" ),
831
832 // moduleStart: { name }
833 moduleStart: registerLoggingCallback( "moduleStart" ),
834
835 // moduleDone: { name, failed, passed, total }
836 moduleDone: registerLoggingCallback( "moduleDone" )
837 });
838
839 if ( typeof document === "undefined" || document.readyState === "complete" ) {
840 config.autorun = true;
841 }
842
843 QUnit.load = function() {
844 runLoggingCallbacks( "begin", QUnit, {} );
845
846 // Initialize the config, saving the execution queue
847 var banner, filter, i, label, len, main, ol, toolbar, userAgent, val,
848 urlConfigHtml = "",
849 oldconfig = extend( {}, config );
850
851 QUnit.init();
852 extend(config, oldconfig);
853
854 config.blocking = false;
855
856 len = config.urlConfig.length;
857
858 for ( i = 0; i < len; i++ ) {
859 val = config.urlConfig[i];
860 config[val] = QUnit.urlParams[val];
861 urlConfigHtml += "<label><input name='" + val + "' type='checkbox'" + ( config[val] ? " checked='checked'" : "" ) + ">" + val + "</label>";
862 }
863
864 // `userAgent` initialized at top of scope
865 userAgent = id( "qunit-userAgent" );
866 if ( userAgent ) {
867 userAgent.innerHTML = navigator.userAgent;
868 }
869
870 // `banner` initialized at top of scope
871 banner = id( "qunit-header" );
872 if ( banner ) {
873 banner.innerHTML = "<a href='" + QUnit.url({ filter: undefined }) + "'>" + banner.innerHTML + "</a> " + urlConfigHtml;
874 addEvent( banner, "change", function( event ) {
875 var params = {};
876 params[ event.target.name ] = event.target.checked ? true : undefined;
877 window.location = QUnit.url( params );
878 });
879 }
880
881 // `toolbar` initialized at top of scope
882 toolbar = id( "qunit-testrunner-toolbar" );
883 if ( toolbar ) {
884 // `filter` initialized at top of scope
885 filter = document.createElement( "input" );
886 filter.type = "checkbox";
887 filter.id = "qunit-filter-pass";
888
889 addEvent( filter, "click", function() {
890 var tmp,
891 ol = document.getElementById( "qunit-tests" );
892
893 if ( filter.checked ) {
894 ol.className = ol.className + " hidepass";
895 } else {
896 tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " ";
897 ol.className = tmp.replace( / hidepass /, " " );
898 }
899 if ( defined.sessionStorage ) {
900 if (filter.checked) {
901 sessionStorage.setItem( "qunit-filter-passed-tests", "true" );
902 } else {
903 sessionStorage.removeItem( "qunit-filter-passed-tests" );
904 }
905 }
906 });
907
908 if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem( "qunit-filter-passed-tests" ) ) {
909 filter.checked = true;
910 // `ol` initialized at top of scope
911 ol = document.getElementById( "qunit-tests" );
912 ol.className = ol.className + " hidepass";
913 }
914 toolbar.appendChild( filter );
915
916 // `label` initialized at top of scope
917 label = document.createElement( "label" );
918 label.setAttribute( "for", "qunit-filter-pass" );
919 label.innerHTML = "Hide passed tests";
920 toolbar.appendChild( label );
921 }
922
923 // `main` initialized at top of scope
924 main = id( "qunit-fixture" );
925 if ( main ) {
926 config.fixture = main.innerHTML;
927 }
928
929 if ( config.autostart ) {
930 QUnit.start();
931 }
932 };
933
934 addEvent( window, "load", QUnit.load );
935
936 // addEvent(window, "error" ) gives us a useless event object
937 window.onerror = function( message, file, line ) {
938 if ( QUnit.config.current ) {
939 QUnit.pushFailure( message, file + ":" + line );
940 } else {
941 QUnit.test( "global failure", function() {
942 QUnit.pushFailure( message, file + ":" + line );
943 });
944 }
945 };
946
947 function done() {
948 config.autorun = true;
949
950 // Log the last module results
951 if ( config.currentModule ) {
952 runLoggingCallbacks( "moduleDone", QUnit, {
953 name: config.currentModule,
954 failed: config.moduleStats.bad,
955 passed: config.moduleStats.all - config.moduleStats.bad,
956 total: config.moduleStats.all
957 });
958 }
959
960 var i, key,
961 banner = id( "qunit-banner" ),
962 tests = id( "qunit-tests" ),
963 runtime = +new Date() - config.started,
964 passed = config.stats.all - config.stats.bad,
965 html = [
966 "Tests completed in ",
967 runtime,
968 " milliseconds.<br/>",
969 "<span class='passed'>",
970 passed,
971 "</span> tests of <span class='total'>",
972 config.stats.all,
973 "</span> passed, <span class='failed'>",
974 config.stats.bad,
975 "</span> failed."
976 ].join( "" );
977
978 if ( banner ) {
979 banner.className = ( config.stats.bad ? "qunit-fail" : "qunit-pass" );
980 }
981
982 if ( tests ) {
983 id( "qunit-testresult" ).innerHTML = html;
984 }
985
986 if ( config.altertitle && typeof document !== "undefined" && document.title ) {
987 // show ✖ for good, ✔ for bad suite result in title
988 // use escape sequences in case file gets loaded with non-utf-8-charset
989 document.title = [
990 ( config.stats.bad ? "\u2716" : "\u2714" ),
991 document.title.replace( /^[\u2714\u2716] /i, "" )
992 ].join( " " );
993 }
994
995 // clear own sessionStorage items if all tests passed
996 if ( config.reorder && defined.sessionStorage && config.stats.bad === 0 ) {
997 // `key` & `i` initialized at top of scope
998 for ( i = 0; i < sessionStorage.length; i++ ) {
999 key = sessionStorage.key( i++ );
1000 if ( key.indexOf( "qunit-test-" ) === 0 ) {
1001 sessionStorage.removeItem( key );
1002 }
1003 }
1004 }
1005
1006 runLoggingCallbacks( "done", QUnit, {
1007 failed: config.stats.bad,
1008 passed: passed,
1009 total: config.stats.all,
1010 runtime: runtime
1011 });
1012 }
1013
1014 function validTest( test ) {
1015 var include,
1016 filter = config.filter && config.filter.toLowerCase(),
1017 fullName = (test.module + ": " + test.testName).toLowerCase();
1018
1019 if ( config.testNumber ) {
1020 return test.testNumber === config.testNumber;
1021 }
1022
1023 if ( !filter ) {
1024 return true;
1025 }
1026
1027 include = filter.charAt( 0 ) !== "!";
1028 if ( !include ) {
1029 filter = filter.slice( 1 );
1030 }
1031
1032 // If the filter matches, we need to honour include
1033 if ( fullName.indexOf( filter ) !== -1 ) {
1034 return include;
1035 }
1036
1037 // Otherwise, do the opposite
1038 return !include;
1039 }
1040
1041 // so far supports only Firefox, Chrome and Opera (buggy), Safari (for real exceptions)
1042 // Later Safari and IE10 are supposed to support error.stack as well
1043 // See also https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack
1044 function extractStacktrace( e, offset ) {
1045 offset = offset === undefined ? 3 : offset;
1046
1047 var stack, include, i, regex;
1048
1049 if ( e.stacktrace ) {
1050 // Opera
1051 return e.stacktrace.split( "\n" )[ offset + 3 ];
1052 } else if ( e.stack ) {
1053 // Firefox, Chrome
1054 stack = e.stack.split( "\n" );
1055 if (/^error$/i.test( stack[0] ) ) {
1056 stack.shift();
1057 }
1058 if ( fileName ) {
1059 include = [];
1060 for ( i = offset; i < stack.length; i++ ) {
1061 if ( stack[ i ].indexOf( fileName ) != -1 ) {
1062 break;
1063 }
1064 include.push( stack[ i ] );
1065 }
1066 if ( include.length ) {
1067 return include.join( "\n" );
1068 }
1069 }
1070 return stack[ offset ];
1071 } else if ( e.sourceURL ) {
1072 // Safari, PhantomJS
1073 // hopefully one day Safari provides actual stacktraces
1074 // exclude useless self-reference for generated Error objects
1075 if ( /qunit.js$/.test( e.sourceURL ) ) {
1076 return;
1077 }
1078 // for actual exceptions, this is useful
1079 return e.sourceURL + ":" + e.line;
1080 }
1081 }
1082 function sourceFromStacktrace( offset ) {
1083 try {
1084 throw new Error();
1085 } catch ( e ) {
1086 return extractStacktrace( e, offset );
1087 }
1088 }
1089
1090 function escapeInnerText( s ) {
1091 if ( !s ) {
1092 return "";
1093 }
1094 s = s + "";
1095 return s.replace( /[\&<>]/g, function( s ) {
1096 switch( s ) {
1097 case "&": return "&amp;";
1098 case "<": return "&lt;";
1099 case ">": return "&gt;";
1100 default: return s;
1101 }
1102 });
1103 }
1104
1105 function synchronize( callback, last ) {
1106 config.queue.push( callback );
1107
1108 if ( config.autorun && !config.blocking ) {
1109 process( last );
1110 }
1111 }
1112
1113 function process( last ) {
1114 function next() {
1115 process( last );
1116 }
1117 var start = new Date().getTime();
1118 config.depth = config.depth ? config.depth + 1 : 1;
1119
1120 while ( config.queue.length && !config.blocking ) {
1121 if ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate ) ) {
1122 config.queue.shift()();
1123 } else {
1124 window.setTimeout( next, 13 );
1125 break;
1126 }
1127 }
1128 config.depth--;
1129 if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) {
1130 done();
1131 }
1132 }
1133
1134 function saveGlobal() {
1135 config.pollution = [];
1136
1137 if ( config.noglobals ) {
1138 for ( var key in window ) {
1139 // in Opera sometimes DOM element ids show up here, ignore them
1140 if ( !hasOwn.call( window, key ) || /^qunit-test-output/.test( key ) ) {
1141 continue;
1142 }
1143 config.pollution.push( key );
1144 }
1145 }
1146 }
1147
1148 function checkPollution( name ) {
1149 var newGlobals,
1150 deletedGlobals,
1151 old = config.pollution;
1152
1153 saveGlobal();
1154
1155 newGlobals = diff( config.pollution, old );
1156 if ( newGlobals.length > 0 ) {
1157 QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join(", ") );
1158 }
1159
1160 deletedGlobals = diff( old, config.pollution );
1161 if ( deletedGlobals.length > 0 ) {
1162 QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join(", ") );
1163 }
1164 }
1165
1166 // returns a new Array with the elements that are in a but not in b
1167 function diff( a, b ) {
1168 var i, j,
1169 result = a.slice();
1170
1171 for ( i = 0; i < result.length; i++ ) {
1172 for ( j = 0; j < b.length; j++ ) {
1173 if ( result[i] === b[j] ) {
1174 result.splice( i, 1 );
1175 i--;
1176 break;
1177 }
1178 }
1179 }
1180 return result;
1181 }
1182
1183 function extend( a, b ) {
1184 for ( var prop in b ) {
1185 if ( b[ prop ] === undefined ) {
1186 delete a[ prop ];
1187
1188 // Avoid "Member not found" error in IE8 caused by setting window.constructor
1189 } else if ( prop !== "constructor" || a !== window ) {
1190 a[ prop ] = b[ prop ];
1191 }
1192 }
1193
1194 return a;
1195 }
1196
1197 function addEvent( elem, type, fn ) {
1198 if ( elem.addEventListener ) {
1199 elem.addEventListener( type, fn, false );
1200 } else if ( elem.attachEvent ) {
1201 elem.attachEvent( "on" + type, fn );
1202 } else {
1203 fn();
1204 }
1205 }
1206
1207 function id( name ) {
1208 return !!( typeof document !== "undefined" && document && document.getElementById ) &&
1209 document.getElementById( name );
1210 }
1211
1212 function registerLoggingCallback( key ) {
1213 return function( callback ) {
1214 config[key].push( callback );
1215 };
1216 }
1217
1218 // Supports deprecated method of completely overwriting logging callbacks
1219 function runLoggingCallbacks( key, scope, args ) {
1220 //debugger;
1221 var i, callbacks;
1222 if ( QUnit.hasOwnProperty( key ) ) {
1223 QUnit[ key ].call(scope, args );
1224 } else {
1225 callbacks = config[ key ];
1226 for ( i = 0; i < callbacks.length; i++ ) {
1227 callbacks[ i ].call( scope, args );
1228 }
1229 }
1230 }
1231
1232 // Test for equality any JavaScript type.
1233 // Author: Philippe Rathé <prathe@gmail.com>
1234 QUnit.equiv = (function() {
1235
1236 // Call the o related callback with the given arguments.
1237 function bindCallbacks( o, callbacks, args ) {
1238 var prop = QUnit.objectType( o );
1239 if ( prop ) {
1240 if ( QUnit.objectType( callbacks[ prop ] ) === "function" ) {
1241 return callbacks[ prop ].apply( callbacks, args );
1242 } else {
1243 return callbacks[ prop ]; // or undefined
1244 }
1245 }
1246 }
1247
1248 // the real equiv function
1249 var innerEquiv,
1250 // stack to decide between skip/abort functions
1251 callers = [],
1252 // stack to avoiding loops from circular referencing
1253 parents = [],
1254
1255 getProto = Object.getPrototypeOf || function ( obj ) {
1256 return obj.__proto__;
1257 },
1258 callbacks = (function () {
1259
1260 // for string, boolean, number and null
1261 function useStrictEquality( b, a ) {
1262 if ( b instanceof a.constructor || a instanceof b.constructor ) {
1263 // to catch short annotaion VS 'new' annotation of a
1264 // declaration
1265 // e.g. var i = 1;
1266 // var j = new Number(1);
1267 return a == b;
1268 } else {
1269 return a === b;
1270 }
1271 }
1272
1273 return {
1274 "string": useStrictEquality,
1275 "boolean": useStrictEquality,
1276 "number": useStrictEquality,
1277 "null": useStrictEquality,
1278 "undefined": useStrictEquality,
1279
1280 "nan": function( b ) {
1281 return isNaN( b );
1282 },
1283
1284 "date": function( b, a ) {
1285 return QUnit.objectType( b ) === "date" && a.valueOf() === b.valueOf();
1286 },
1287
1288 "regexp": function( b, a ) {
1289 return QUnit.objectType( b ) === "regexp" &&
1290 // the regex itself
1291 a.source === b.source &&
1292 // and its modifers
1293 a.global === b.global &&
1294 // (gmi) ...
1295 a.ignoreCase === b.ignoreCase &&
1296 a.multiline === b.multiline;
1297 },
1298
1299 // - skip when the property is a method of an instance (OOP)
1300 // - abort otherwise,
1301 // initial === would have catch identical references anyway
1302 "function": function() {
1303 var caller = callers[callers.length - 1];
1304 return caller !== Object && typeof caller !== "undefined";
1305 },
1306
1307 "array": function( b, a ) {
1308 var i, j, len, loop;
1309
1310 // b could be an object literal here
1311 if ( QUnit.objectType( b ) !== "array" ) {
1312 return false;
1313 }
1314
1315 len = a.length;
1316 if ( len !== b.length ) {
1317 // safe and faster
1318 return false;
1319 }
1320
1321 // track reference to avoid circular references
1322 parents.push( a );
1323 for ( i = 0; i < len; i++ ) {
1324 loop = false;
1325 for ( j = 0; j < parents.length; j++ ) {
1326 if ( parents[j] === a[i] ) {
1327 loop = true;// dont rewalk array
1328 }
1329 }
1330 if ( !loop && !innerEquiv(a[i], b[i]) ) {
1331 parents.pop();
1332 return false;
1333 }
1334 }
1335 parents.pop();
1336 return true;
1337 },
1338
1339 "object": function( b, a ) {
1340 var i, j, loop,
1341 // Default to true
1342 eq = true,
1343 aProperties = [],
1344 bProperties = [];
1345
1346 // comparing constructors is more strict than using
1347 // instanceof
1348 if ( a.constructor !== b.constructor ) {
1349 // Allow objects with no prototype to be equivalent to
1350 // objects with Object as their constructor.
1351 if ( !(( getProto(a) === null && getProto(b) === Object.prototype ) ||
1352 ( getProto(b) === null && getProto(a) === Object.prototype ) ) ) {
1353 return false;
1354 }
1355 }
1356
1357 // stack constructor before traversing properties
1358 callers.push( a.constructor );
1359 // track reference to avoid circular references
1360 parents.push( a );
1361
1362 for ( i in a ) { // be strict: don't ensures hasOwnProperty
1363 // and go deep
1364 loop = false;
1365 for ( j = 0; j < parents.length; j++ ) {
1366 if ( parents[j] === a[i] ) {
1367 // don't go down the same path twice
1368 loop = true;
1369 }
1370 }
1371 aProperties.push(i); // collect a's properties
1372
1373 if (!loop && !innerEquiv( a[i], b[i] ) ) {
1374 eq = false;
1375 break;
1376 }
1377 }
1378
1379 callers.pop(); // unstack, we are done
1380 parents.pop();
1381
1382 for ( i in b ) {
1383 bProperties.push( i ); // collect b's properties
1384 }
1385
1386 // Ensures identical properties name
1387 return eq && innerEquiv( aProperties.sort(), bProperties.sort() );
1388 }
1389 };
1390 }());
1391
1392 innerEquiv = function() { // can take multiple arguments
1393 var args = [].slice.apply( arguments );
1394 if ( args.length < 2 ) {
1395 return true; // end transition
1396 }
1397
1398 return (function( a, b ) {
1399 if ( a === b ) {
1400 return true; // catch the most you can
1401 } else if ( a === null || b === null || typeof a === "undefined" ||
1402 typeof b === "undefined" ||
1403 QUnit.objectType(a) !== QUnit.objectType(b) ) {
1404 return false; // don't lose time with error prone cases
1405 } else {
1406 return bindCallbacks(a, callbacks, [ b, a ]);
1407 }
1408
1409 // apply transition with (1..n) arguments
1410 }( args[0], args[1] ) && arguments.callee.apply( this, args.splice(1, args.length - 1 )) );
1411 };
1412
1413 return innerEquiv;
1414 }());
1415
1416 /**
1417 * jsDump Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com |
1418 * http://flesler.blogspot.com Licensed under BSD
1419 * (http://www.opensource.org/licenses/bsd-license.php) Date: 5/15/2008
1420 *
1421 * @projectDescription Advanced and extensible data dumping for Javascript.
1422 * @version 1.0.0
1423 * @author Ariel Flesler
1424 * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html}
1425 */
1426 QUnit.jsDump = (function() {
1427 function quote( str ) {
1428 return '"' + str.toString().replace( /"/g, '\\"' ) + '"';
1429 }
1430 function literal( o ) {
1431 return o + "";
1432 }
1433 function join( pre, arr, post ) {
1434 var s = jsDump.separator(),
1435 base = jsDump.indent(),
1436 inner = jsDump.indent(1);
1437 if ( arr.join ) {
1438 arr = arr.join( "," + s + inner );
1439 }
1440 if ( !arr ) {
1441 return pre + post;
1442 }
1443 return [ pre, inner + arr, base + post ].join(s);
1444 }
1445 function array( arr, stack ) {
1446 var i = arr.length, ret = new Array(i);
1447 this.up();
1448 while ( i-- ) {
1449 ret[i] = this.parse( arr[i] , undefined , stack);
1450 }
1451 this.down();
1452 return join( "[", ret, "]" );
1453 }
1454
1455 var reName = /^function (\w+)/,
1456 jsDump = {
1457 parse: function( obj, type, stack ) { //type is used mostly internally, you can fix a (custom)type in advance
1458 stack = stack || [ ];
1459 var inStack, res,
1460 parser = this.parsers[ type || this.typeOf(obj) ];
1461
1462 type = typeof parser;
1463 inStack = inArray( obj, stack );
1464
1465 if ( inStack != -1 ) {
1466 return "recursion(" + (inStack - stack.length) + ")";
1467 }
1468 //else
1469 if ( type == "function" ) {
1470 stack.push( obj );
1471 res = parser.call( this, obj, stack );
1472 stack.pop();
1473 return res;
1474 }
1475 // else
1476 return ( type == "string" ) ? parser : this.parsers.error;
1477 },
1478 typeOf: function( obj ) {
1479 var type;
1480 if ( obj === null ) {
1481 type = "null";
1482 } else if ( typeof obj === "undefined" ) {
1483 type = "undefined";
1484 } else if ( QUnit.is( "regexp", obj) ) {
1485 type = "regexp";
1486 } else if ( QUnit.is( "date", obj) ) {
1487 type = "date";
1488 } else if ( QUnit.is( "function", obj) ) {
1489 type = "function";
1490 } else if ( typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined" ) {
1491 type = "window";
1492 } else if ( obj.nodeType === 9 ) {
1493 type = "document";
1494 } else if ( obj.nodeType ) {
1495 type = "node";
1496 } else if (
1497 // native arrays
1498 toString.call( obj ) === "[object Array]" ||
1499 // NodeList objects
1500 ( typeof obj.length === "number" && typeof obj.item !== "undefined" && ( obj.length ? obj.item(0) === obj[0] : ( obj.item( 0 ) === null && typeof obj[0] === "undefined" ) ) )
1501 ) {
1502 type = "array";
1503 } else {
1504 type = typeof obj;
1505 }
1506 return type;
1507 },
1508 separator: function() {
1509 return this.multiline ? this.HTML ? "<br />" : "\n" : this.HTML ? "&nbsp;" : " ";
1510 },
1511 indent: function( extra ) {// extra can be a number, shortcut for increasing-calling-decreasing
1512 if ( !this.multiline ) {
1513 return "";
1514 }
1515 var chr = this.indentChar;
1516 if ( this.HTML ) {
1517 chr = chr.replace( /\t/g, " " ).replace( / /g, "&nbsp;" );
1518 }
1519 return new Array( this._depth_ + (extra||0) ).join(chr);
1520 },
1521 up: function( a ) {
1522 this._depth_ += a || 1;
1523 },
1524 down: function( a ) {
1525 this._depth_ -= a || 1;
1526 },
1527 setParser: function( name, parser ) {
1528 this.parsers[name] = parser;
1529 },
1530 // The next 3 are exposed so you can use them
1531 quote: quote,
1532 literal: literal,
1533 join: join,
1534 //
1535 _depth_: 1,
1536 // This is the list of parsers, to modify them, use jsDump.setParser
1537 parsers: {
1538 window: "[Window]",
1539 document: "[Document]",
1540 error: "[ERROR]", //when no parser is found, shouldn"t happen
1541 unknown: "[Unknown]",
1542 "null": "null",
1543 "undefined": "undefined",
1544 "function": function( fn ) {
1545 var ret = "function",
1546 name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1];//functions never have name in IE
1547
1548 if ( name ) {
1549 ret += " " + name;
1550 }
1551 ret += "( ";
1552
1553 ret = [ ret, QUnit.jsDump.parse( fn, "functionArgs" ), "){" ].join( "" );
1554 return join( ret, QUnit.jsDump.parse(fn,"functionCode" ), "}" );
1555 },
1556 array: array,
1557 nodelist: array,
1558 "arguments": array,
1559 object: function( map, stack ) {
1560 var ret = [ ], keys, key, val, i;
1561 QUnit.jsDump.up();
1562 if ( Object.keys ) {
1563 keys = Object.keys( map );
1564 } else {
1565 keys = [];
1566 for ( key in map ) {
1567 keys.push( key );
1568 }
1569 }
1570 keys.sort();
1571 for ( i = 0; i < keys.length; i++ ) {
1572 key = keys[ i ];
1573 val = map[ key ];
1574 ret.push( QUnit.jsDump.parse( key, "key" ) + ": " + QUnit.jsDump.parse( val, undefined, stack ) );
1575 }
1576 QUnit.jsDump.down();
1577 return join( "{", ret, "}" );
1578 },
1579 node: function( node ) {
1580 var a, val,
1581 open = QUnit.jsDump.HTML ? "&lt;" : "<",
1582 close = QUnit.jsDump.HTML ? "&gt;" : ">",
1583 tag = node.nodeName.toLowerCase(),
1584 ret = open + tag;
1585
1586 for ( a in QUnit.jsDump.DOMAttrs ) {
1587 val = node[ QUnit.jsDump.DOMAttrs[a] ];
1588 if ( val ) {
1589 ret += " " + a + "=" + QUnit.jsDump.parse( val, "attribute" );
1590 }
1591 }
1592 return ret + close + open + "/" + tag + close;
1593 },
1594 functionArgs: function( fn ) {//function calls it internally, it's the arguments part of the function
1595 var args,
1596 l = fn.length;
1597
1598 if ( !l ) {
1599 return "";
1600 }
1601
1602 args = new Array(l);
1603 while ( l-- ) {
1604 args[l] = String.fromCharCode(97+l);//97 is 'a'
1605 }
1606 return " " + args.join( ", " ) + " ";
1607 },
1608 key: quote, //object calls it internally, the key part of an item in a map
1609 functionCode: "[code]", //function calls it internally, it's the content of the function
1610 attribute: quote, //node calls it internally, it's an html attribute value
1611 string: quote,
1612 date: quote,
1613 regexp: literal, //regex
1614 number: literal,
1615 "boolean": literal
1616 },
1617 DOMAttrs: {
1618 //attributes to dump from nodes, name=>realName
1619 id: "id",
1620 name: "name",
1621 "class": "className"
1622 },
1623 HTML: false,//if true, entities are escaped ( <, >, \t, space and \n )
1624 indentChar: " ",//indentation unit
1625 multiline: true //if true, items in a collection, are separated by a \n, else just a space.
1626 };
1627
1628 return jsDump;
1629 }());
1630
1631 // from Sizzle.js
1632 function getText( elems ) {
1633 var i, elem,
1634 ret = "";
1635
1636 for ( i = 0; elems[i]; i++ ) {
1637 elem = elems[i];
1638
1639 // Get the text from text nodes and CDATA nodes
1640 if ( elem.nodeType === 3 || elem.nodeType === 4 ) {
1641 ret += elem.nodeValue;
1642
1643 // Traverse everything else, except comment nodes
1644 } else if ( elem.nodeType !== 8 ) {
1645 ret += getText( elem.childNodes );
1646 }
1647 }
1648
1649 return ret;
1650 }
1651
1652 // from jquery.js
1653 function inArray( elem, array ) {
1654 if ( array.indexOf ) {
1655 return array.indexOf( elem );
1656 }
1657
1658 for ( var i = 0, length = array.length; i < length; i++ ) {
1659 if ( array[ i ] === elem ) {
1660 return i;
1661 }
1662 }
1663
1664 return -1;
1665 }
1666
1667 /*
1668 * Javascript Diff Algorithm
1669 * By John Resig (http://ejohn.org/)
1670 * Modified by Chu Alan "sprite"
1671 *
1672 * Released under the MIT license.
1673 *
1674 * More Info:
1675 * http://ejohn.org/projects/javascript-diff-algorithm/
1676 *
1677 * Usage: QUnit.diff(expected, actual)
1678 *
1679 * QUnit.diff( "the quick brown fox jumped over", "the quick fox jumps over" ) == "the quick <del>brown </del> fox <del>jumped </del><ins>jumps </ins> over"
1680 */
1681 QUnit.diff = (function() {
1682 function diff( o, n ) {
1683 var i,
1684 ns = {},
1685 os = {};
1686
1687 for ( i = 0; i < n.length; i++ ) {
1688 if ( ns[ n[i] ] == null ) {
1689 ns[ n[i] ] = {
1690 rows: [],
1691 o: null
1692 };
1693 }
1694 ns[ n[i] ].rows.push( i );
1695 }
1696
1697 for ( i = 0; i < o.length; i++ ) {
1698 if ( os[ o[i] ] == null ) {
1699 os[ o[i] ] = {
1700 rows: [],
1701 n: null
1702 };
1703 }
1704 os[ o[i] ].rows.push( i );
1705 }
1706
1707 for ( i in ns ) {
1708 if ( !hasOwn.call( ns, i ) ) {
1709 continue;
1710 }
1711 if ( ns[i].rows.length == 1 && typeof os[i] != "undefined" && os[i].rows.length == 1 ) {
1712 n[ ns[i].rows[0] ] = {
1713 text: n[ ns[i].rows[0] ],
1714 row: os[i].rows[0]
1715 };
1716 o[ os[i].rows[0] ] = {
1717 text: o[ os[i].rows[0] ],
1718 row: ns[i].rows[0]
1719 };
1720 }
1721 }
1722
1723 for ( i = 0; i < n.length - 1; i++ ) {
1724 if ( n[i].text != null && n[ i + 1 ].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null &&
1725 n[ i + 1 ] == o[ n[i].row + 1 ] ) {
1726
1727 n[ i + 1 ] = {
1728 text: n[ i + 1 ],
1729 row: n[i].row + 1
1730 };
1731 o[ n[i].row + 1 ] = {
1732 text: o[ n[i].row + 1 ],
1733 row: i + 1
1734 };
1735 }
1736 }
1737
1738 for ( i = n.length - 1; i > 0; i-- ) {
1739 if ( n[i].text != null && n[ i - 1 ].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null &&
1740 n[ i - 1 ] == o[ n[i].row - 1 ]) {
1741
1742 n[ i - 1 ] = {
1743 text: n[ i - 1 ],
1744 row: n[i].row - 1
1745 };
1746 o[ n[i].row - 1 ] = {
1747 text: o[ n[i].row - 1 ],
1748 row: i - 1
1749 };
1750 }
1751 }
1752
1753 return {
1754 o: o,
1755 n: n
1756 };
1757 }
1758
1759 return function( o, n ) {
1760 o = o.replace( /\s+$/, "" );
1761 n = n.replace( /\s+$/, "" );
1762
1763 var i, pre,
1764 str = "",
1765 out = diff( o === "" ? [] : o.split(/\s+/), n === "" ? [] : n.split(/\s+/) ),
1766 oSpace = o.match(/\s+/g),
1767 nSpace = n.match(/\s+/g);
1768
1769 if ( oSpace == null ) {
1770 oSpace = [ " " ];
1771 }
1772 else {
1773 oSpace.push( " " );
1774 }
1775
1776 if ( nSpace == null ) {
1777 nSpace = [ " " ];
1778 }
1779 else {
1780 nSpace.push( " " );
1781 }
1782
1783 if ( out.n.length === 0 ) {
1784 for ( i = 0; i < out.o.length; i++ ) {
1785 str += "<del>" + out.o[i] + oSpace[i] + "</del>";
1786 }
1787 }
1788 else {
1789 if ( out.n[0].text == null ) {
1790 for ( n = 0; n < out.o.length && out.o[n].text == null; n++ ) {
1791 str += "<del>" + out.o[n] + oSpace[n] + "</del>";
1792 }
1793 }
1794
1795 for ( i = 0; i < out.n.length; i++ ) {
1796 if (out.n[i].text == null) {
1797 str += "<ins>" + out.n[i] + nSpace[i] + "</ins>";
1798 }
1799 else {
1800 // `pre` initialized at top of scope
1801 pre = "";
1802
1803 for ( n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) {
1804 pre += "<del>" + out.o[n] + oSpace[n] + "</del>";
1805 }
1806 str += " " + out.n[i].text + nSpace[i] + pre;
1807 }
1808 }
1809 }
1810
1811 return str;
1812 };
1813 }());
1814
1815 // for CommonJS enviroments, export everything
1816 if ( typeof exports !== "undefined" ) {
1817 extend(exports, QUnit);
1818 }
1819
1820 // get at whatever the global object is, like window in browsers
1821 }( (function() {return this;}.call()) ));