Home page Forum Wiki Mail Jabber Devel NIX-FILES

AltLUG Git

Git-repositories of Altai Linux User Group

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

Hosting is provided AltSPAHow to use Git
Please direct any questions on jabber alex.wolf@jabber.ru

Valid HTML 4.0 Transitional Valid CSS!

Designer Alexander Wolf