Home page Forum Wiki Mail Jabber Devel NIX-FILES

AltLUG Git

Git-repositories of Altai Linux User Group

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