Home page Forum Wiki Mail Jabber Devel NIX-FILES

AltLUG Git

Git-repositories of Altai Linux User Group

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