Home page Forum Wiki Mail Jabber Devel NIX-FILES

AltLUG Git

Git-repositories of Altai Linux User Group

Modify document.title when suite is done to show success/failure in tab,
[qunit.git] / qunit / qunit.js
1 /**
2  * QUnit - A JavaScript Unit Testing Framework
3  * 
4  * http://docs.jquery.com/QUnit
5  *
6  * Copyright (c) 2011 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 defined = {
14         setTimeout: typeof window.setTimeout !== "undefined",
15         sessionStorage: (function() {
16                 try {
17                         return !!sessionStorage.getItem;
18                 } catch(e){
19                         return false;
20                 }
21   })()
22 };
23
24 var testId = 0;
25
26 var Test = function(name, testName, expected, testEnvironmentArg, async, callback) {
27         this.name = name;
28         this.testName = testName;
29         this.expected = expected;
30         this.testEnvironmentArg = testEnvironmentArg;
31         this.async = async;
32         this.callback = callback;
33         this.assertions = [];
34 };
35 Test.prototype = {
36         init: function() {
37                 var tests = id("qunit-tests");
38                 if (tests) {
39                         var b = document.createElement("strong");
40                                 b.innerHTML = "Running " + this.name;
41                         var li = document.createElement("li");
42                                 li.appendChild( b );
43                                 li.className = "running";
44                                 li.id = this.id = "test-output" + testId++;
45                         tests.appendChild( li );
46                 }
47         },
48         setup: function() {
49                 if (this.module != config.previousModule) {
50                         if ( config.previousModule ) {
51                                 QUnit.moduleDone( {
52                                         name: config.previousModule,
53                                         failed: config.moduleStats.bad,
54                                         passed: config.moduleStats.all - config.moduleStats.bad,
55                                         total: config.moduleStats.all
56                                 } );
57                         }
58                         config.previousModule = this.module;
59                         config.moduleStats = { all: 0, bad: 0 };
60                         QUnit.moduleStart( {
61                                 name: this.module
62                         } );
63                 }
64
65                 config.current = this;
66                 this.testEnvironment = extend({
67                         setup: function() {},
68                         teardown: function() {}
69                 }, this.moduleTestEnvironment);
70                 if (this.testEnvironmentArg) {
71                         extend(this.testEnvironment, this.testEnvironmentArg);
72                 }
73
74                 QUnit.testStart( {
75                         name: this.testName
76                 } );
77
78                 // allow utility functions to access the current test environment
79                 // TODO why??
80                 QUnit.current_testEnvironment = this.testEnvironment;
81                 
82                 try {
83                         if ( !config.pollution ) {
84                                 saveGlobal();
85                         }
86
87                         this.testEnvironment.setup.call(this.testEnvironment);
88                 } catch(e) {
89                         QUnit.ok( false, "Setup failed on " + this.testName + ": " + e.message );
90                 }
91         },
92         run: function() {
93                 if ( this.async ) {
94                         QUnit.stop();
95                 }
96
97                 if ( config.notrycatch ) {
98                         this.callback.call(this.testEnvironment);
99                         return;
100                 }
101                 try {
102                         this.callback.call(this.testEnvironment);
103                 } catch(e) {
104                         fail("Test " + this.testName + " died, exception and test follows", e, this.callback);
105                         QUnit.ok( false, "Died on test #" + (this.assertions.length + 1) + ": " + e.message + " - " + QUnit.jsDump.parse(e) );
106                         // else next test will carry the responsibility
107                         saveGlobal();
108
109                         // Restart the tests if they're blocking
110                         if ( config.blocking ) {
111                                 start();
112                         }
113                 }
114         },
115         teardown: function() {
116                 try {
117                         checkPollution();
118                         this.testEnvironment.teardown.call(this.testEnvironment);
119                 } catch(e) {
120                         QUnit.ok( false, "Teardown failed on " + this.testName + ": " + e.message );
121                 }
122         },
123         finish: function() {
124                 if ( this.expected && this.expected != this.assertions.length ) {
125                         QUnit.ok( false, "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run" );
126                 }
127                 
128                 var good = 0, bad = 0,
129                         tests = id("qunit-tests");
130
131                 config.stats.all += this.assertions.length;
132                 config.moduleStats.all += this.assertions.length;
133
134                 if ( tests ) {
135                         var ol  = document.createElement("ol");
136
137                         for ( var i = 0; i < this.assertions.length; i++ ) {
138                                 var assertion = this.assertions[i];
139
140                                 var li = document.createElement("li");
141                                 li.className = assertion.result ? "pass" : "fail";
142                                 li.innerHTML = assertion.message || (assertion.result ? "okay" : "failed");
143                                 ol.appendChild( li );
144
145                                 if ( assertion.result ) {
146                                         good++;
147                                 } else {
148                                         bad++;
149                                         config.stats.bad++;
150                                         config.moduleStats.bad++;
151                                 }
152                         }
153
154                         // store result when possible
155                         if ( QUnit.config.reorder && defined.sessionStorage ) {
156                                 if (bad) {
157                                         sessionStorage.setItem("qunit-" + this.module + "-" + this.testName, bad);
158                                 } else {
159                                         sessionStorage.removeItem("qunit-" + this.module + "-" + this.testName);
160                                 }
161                         }
162
163                         if (bad == 0) {
164                                 ol.style.display = "none";
165                         }
166
167                         var b = document.createElement("strong");
168                         b.innerHTML = this.name + " <b class='counts'>(<b class='failed'>" + bad + "</b>, <b class='passed'>" + good + "</b>, " + this.assertions.length + ")</b>";
169                         
170                         var a = document.createElement("a");
171                         a.innerHTML = "Rerun";
172                         a.href = QUnit.url({ filter: getText([b]).replace(/\([^)]+\)$/, "").replace(/(^\s*|\s*$)/g, "") });
173                         
174                         addEvent(b, "click", function() {
175                                 var next = b.nextSibling.nextSibling,
176                                         display = next.style.display;
177                                 next.style.display = display === "none" ? "block" : "none";
178                         });
179                         
180                         addEvent(b, "dblclick", function(e) {
181                                 var target = e && e.target ? e.target : window.event.srcElement;
182                                 if ( target.nodeName.toLowerCase() == "span" || target.nodeName.toLowerCase() == "b" ) {
183                                         target = target.parentNode;
184                                 }
185                                 if ( window.location && target.nodeName.toLowerCase() === "strong" ) {
186                                         window.location = QUnit.url({ filter: getText([target]).replace(/\([^)]+\)$/, "").replace(/(^\s*|\s*$)/g, "") });
187                                 }
188                         });
189
190                         var li = id(this.id);
191                         li.className = bad ? "fail" : "pass";
192                         li.removeChild( li.firstChild );
193                         li.appendChild( b );
194                         li.appendChild( a );
195                         li.appendChild( ol );
196
197                 } else {
198                         for ( var i = 0; i < this.assertions.length; i++ ) {
199                                 if ( !this.assertions[i].result ) {
200                                         bad++;
201                                         config.stats.bad++;
202                                         config.moduleStats.bad++;
203                                 }
204                         }
205                 }
206
207                 try {
208                         QUnit.reset();
209                 } catch(e) {
210                         fail("reset() failed, following Test " + this.testName + ", exception and reset fn follows", e, QUnit.reset);
211                 }
212
213                 QUnit.testDone( {
214                         name: this.testName,
215                         failed: bad,
216                         passed: this.assertions.length - bad,
217                         total: this.assertions.length
218                 } );
219         },
220         
221         queue: function() {
222                 var test = this;
223                 synchronize(function() {
224                         test.init();
225                 });
226                 function run() {
227                         // each of these can by async
228                         synchronize(function() {
229                                 test.setup();
230                         });
231                         synchronize(function() {
232                                 test.run();
233                         });
234                         synchronize(function() {
235                                 test.teardown();
236                         });
237                         synchronize(function() {
238                                 test.finish();
239                         });
240                 }
241                 // defer when previous test run passed, if storage is available
242                 var bad = QUnit.config.reorder && defined.sessionStorage && +sessionStorage.getItem("qunit-" + this.module + "-" + this.testName);
243                 if (bad) {
244                         run();
245                 } else {
246                         synchronize(run);
247                 };
248         }
249         
250 };
251
252 var QUnit = {
253
254         // call on start of module test to prepend name to all tests
255         module: function(name, testEnvironment) {
256                 config.currentModule = name;
257                 config.currentModuleTestEnviroment = testEnvironment;
258         },
259
260         asyncTest: function(testName, expected, callback) {
261                 if ( arguments.length === 2 ) {
262                         callback = expected;
263                         expected = 0;
264                 }
265
266                 QUnit.test(testName, expected, callback, true);
267         },
268         
269         test: function(testName, expected, callback, async) {
270                 var name = '<span class="test-name">' + testName + '</span>', testEnvironmentArg;
271
272                 if ( arguments.length === 2 ) {
273                         callback = expected;
274                         expected = null;
275                 }
276                 // is 2nd argument a testEnvironment?
277                 if ( expected && typeof expected === 'object') {
278                         testEnvironmentArg =  expected;
279                         expected = null;
280                 }
281
282                 if ( config.currentModule ) {
283                         name = '<span class="module-name">' + config.currentModule + "</span>: " + name;
284                 }
285
286                 if ( !validTest(config.currentModule + ": " + testName) ) {
287                         return;
288                 }
289                 
290                 var test = new Test(name, testName, expected, testEnvironmentArg, async, callback);
291                 test.module = config.currentModule;
292                 test.moduleTestEnvironment = config.currentModuleTestEnviroment;
293                 test.queue();
294         },
295         
296         /**
297          * Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through.
298          */
299         expect: function(asserts) {
300                 config.current.expected = asserts;
301         },
302
303         /**
304          * Asserts true.
305          * @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" );
306          */
307         ok: function(a, msg) {
308                 a = !!a;
309                 var details = {
310                         result: a,
311                         message: msg
312                 };
313                 msg = escapeHtml(msg);
314                 QUnit.log(details);
315                 config.current.assertions.push({
316                         result: a,
317                         message: msg
318                 });
319         },
320
321         /**
322          * Checks that the first two arguments are equal, with an optional message.
323          * Prints out both actual and expected values.
324          *
325          * Prefered to ok( actual == expected, message )
326          *
327          * @example equal( format("Received {0} bytes.", 2), "Received 2 bytes." );
328          *
329          * @param Object actual
330          * @param Object expected
331          * @param String message (optional)
332          */
333         equal: function(actual, expected, message) {
334                 QUnit.push(expected == actual, actual, expected, message);
335         },
336
337         notEqual: function(actual, expected, message) {
338                 QUnit.push(expected != actual, actual, expected, message);
339         },
340         
341         deepEqual: function(actual, expected, message) {
342                 QUnit.push(QUnit.equiv(actual, expected), actual, expected, message);
343         },
344
345         notDeepEqual: function(actual, expected, message) {
346                 QUnit.push(!QUnit.equiv(actual, expected), actual, expected, message);
347         },
348
349         strictEqual: function(actual, expected, message) {
350                 QUnit.push(expected === actual, actual, expected, message);
351         },
352
353         notStrictEqual: function(actual, expected, message) {
354                 QUnit.push(expected !== actual, actual, expected, message);
355         },
356
357         raises: function(block, expected, message) {
358                 var actual, ok = false;
359         
360                 if (typeof expected === 'string') {
361                         message = expected;
362                         expected = null;
363                 }
364         
365                 try {
366                         block();
367                 } catch (e) {
368                         actual = e;
369                 }
370         
371                 if (actual) {
372                         // we don't want to validate thrown error
373                         if (!expected) {
374                                 ok = true;
375                         // expected is a regexp 
376                         } else if (QUnit.objectType(expected) === "regexp") {
377                                 ok = expected.test(actual);
378                         // expected is a constructor    
379                         } else if (actual instanceof expected) {
380                                 ok = true;
381                         // expected is a validation function which returns true is validation passed    
382                         } else if (expected.call({}, actual) === true) {
383                                 ok = true;
384                         }
385                 }
386                         
387                 QUnit.ok(ok, message);
388         },
389
390         start: function() {
391                 config.semaphore--;
392                 if (config.semaphore > 0) {
393                         // don't start until equal number of stop-calls
394                         return;
395                 }
396                 if (config.semaphore < 0) {
397                         // ignore if start is called more often then stop
398                         config.semaphore = 0;
399                 }
400                 // A slight delay, to avoid any current callbacks
401                 if ( defined.setTimeout ) {
402                         window.setTimeout(function() {
403                                 if ( config.timeout ) {
404                                         clearTimeout(config.timeout);
405                                 }
406
407                                 config.blocking = false;
408                                 process();
409                         }, 13);
410                 } else {
411                         config.blocking = false;
412                         process();
413                 }
414         },
415         
416         stop: function(timeout) {
417                 config.semaphore++;
418                 config.blocking = true;
419
420                 if ( timeout && defined.setTimeout ) {
421                         clearTimeout(config.timeout);
422                         config.timeout = window.setTimeout(function() {
423                                 QUnit.ok( false, "Test timed out" );
424                                 QUnit.start();
425                         }, timeout);
426                 }
427         }
428 };
429
430 // Backwards compatibility, deprecated
431 QUnit.equals = QUnit.equal;
432 QUnit.same = QUnit.deepEqual;
433
434 // Maintain internal state
435 var config = {
436         // The queue of tests to run
437         queue: [],
438
439         // block until document ready
440         blocking: true,
441         
442         // by default, run previously failed tests first
443         // very useful in combination with "Hide passed tests" checked
444         reorder: true,
445
446         noglobals: false,
447         notrycatch: false
448 };
449
450 // Load paramaters
451 (function() {
452         var location = window.location || { search: "", protocol: "file:" },
453                 params = location.search.slice( 1 ).split( "&" ),
454                 length = params.length,
455                 urlParams = {},
456                 current;
457
458         if ( params[ 0 ] ) {
459                 for ( var i = 0; i < length; i++ ) {
460                         current = params[ i ].split( "=" );
461                         current[ 0 ] = decodeURIComponent( current[ 0 ] );
462                         // allow just a key to turn on a flag, e.g., test.html?noglobals
463                         current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true;
464                         urlParams[ current[ 0 ] ] = current[ 1 ];
465                         if ( current[ 0 ] in config ) {
466                                 config[ current[ 0 ] ] = current[ 1 ];
467                         }
468                 }
469         }
470
471         QUnit.urlParams = urlParams;
472         config.filter = urlParams.filter;
473
474         // Figure out if we're running the tests from a server or not
475         QUnit.isLocal = !!(location.protocol === 'file:');
476 })();
477
478 // Expose the API as global variables, unless an 'exports'
479 // object exists, in that case we assume we're in CommonJS
480 if ( typeof exports === "undefined" || typeof require === "undefined" ) {
481         extend(window, QUnit);
482         window.QUnit = QUnit;
483 } else {
484         extend(exports, QUnit);
485         exports.QUnit = QUnit;
486 }
487
488 // define these after exposing globals to keep them in these QUnit namespace only
489 extend(QUnit, {
490         config: config,
491
492         // Initialize the configuration options
493         init: function() {
494                 extend(config, {
495                         stats: { all: 0, bad: 0 },
496                         moduleStats: { all: 0, bad: 0 },
497                         started: +new Date,
498                         updateRate: 1000,
499                         blocking: false,
500                         autostart: true,
501                         autorun: false,
502                         filter: "",
503                         queue: [],
504                         semaphore: 0
505                 });
506
507                 var tests = id( "qunit-tests" ),
508                         banner = id( "qunit-banner" ),
509                         result = id( "qunit-testresult" );
510
511                 if ( tests ) {
512                         tests.innerHTML = "";
513                 }
514
515                 if ( banner ) {
516                         banner.className = "";
517                 }
518
519                 if ( result ) {
520                         result.parentNode.removeChild( result );
521                 }
522                 
523                 if ( tests ) {
524                         result = document.createElement( "p" );
525                         result.id = "qunit-testresult";
526                         result.className = "result";
527                         tests.parentNode.insertBefore( result, tests );
528                         result.innerHTML = 'Running...<br/>&nbsp;';
529                 }
530         },
531         
532         /**
533          * Resets the test setup. Useful for tests that modify the DOM.
534          * 
535          * If jQuery is available, uses jQuery's html(), otherwise just innerHTML.
536          */
537         reset: function() {
538                 if ( window.jQuery ) {
539                         jQuery( "#qunit-fixture" ).html( config.fixture );
540                 } else {
541                         var main = id( 'qunit-fixture' );
542                         if ( main ) {
543                                 main.innerHTML = config.fixture;
544                         }
545                 }
546         },
547         
548         /**
549          * Trigger an event on an element.
550          *
551          * @example triggerEvent( document.body, "click" );
552          *
553          * @param DOMElement elem
554          * @param String type
555          */
556         triggerEvent: function( elem, type, event ) {
557                 if ( document.createEvent ) {
558                         event = document.createEvent("MouseEvents");
559                         event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView,
560                                 0, 0, 0, 0, 0, false, false, false, false, 0, null);
561                         elem.dispatchEvent( event );
562
563                 } else if ( elem.fireEvent ) {
564                         elem.fireEvent("on"+type);
565                 }
566         },
567         
568         // Safe object type checking
569         is: function( type, obj ) {
570                 return QUnit.objectType( obj ) == type;
571         },
572         
573         objectType: function( obj ) {
574                 if (typeof obj === "undefined") {
575                                 return "undefined";
576
577                 // consider: typeof null === object
578                 }
579                 if (obj === null) {
580                                 return "null";
581                 }
582
583                 var type = Object.prototype.toString.call( obj )
584                         .match(/^\[object\s(.*)\]$/)[1] || '';
585
586                 switch (type) {
587                                 case 'Number':
588                                                 if (isNaN(obj)) {
589                                                                 return "nan";
590                                                 } else {
591                                                                 return "number";
592                                                 }
593                                 case 'String':
594                                 case 'Boolean':
595                                 case 'Array':
596                                 case 'Date':
597                                 case 'RegExp':
598                                 case 'Function':
599                                                 return type.toLowerCase();
600                 }
601                 if (typeof obj === "object") {
602                                 return "object";
603                 }
604                 return undefined;
605         },
606         
607         push: function(result, actual, expected, message) {
608                 var details = {
609                         result: result,
610                         message: message,
611                         actual: actual,
612                         expected: expected
613                 };
614                 
615                 message = escapeHtml(message) || (result ? "okay" : "failed");
616                 message = '<span class="test-message">' + message + "</span>";
617                 expected = escapeHtml(QUnit.jsDump.parse(expected));
618                 actual = escapeHtml(QUnit.jsDump.parse(actual));
619                 var output = message + '<table><tr class="test-expected"><th>Expected: </th><td><pre>' + expected + '</pre></td></tr>';
620                 if (actual != expected) {
621                         output += '<tr class="test-actual"><th>Result: </th><td><pre>' + actual + '</pre></td></tr>';
622                         output += '<tr class="test-diff"><th>Diff: </th><td><pre>' + QUnit.diff(expected, actual) +'</pre></td></tr>';
623                 }
624                 if (!result) {
625                         var source = sourceFromStacktrace();
626                         if (source) {
627                                 details.source = source;
628                                 output += '<tr class="test-source"><th>Source: </th><td><pre>' + source +'</pre></td></tr>';
629                         }
630                 }
631                 output += "</table>";
632                 
633                 QUnit.log(details);
634                 
635                 config.current.assertions.push({
636                         result: !!result,
637                         message: output
638                 });
639         },
640         
641         url: function( params ) {
642                 params = extend( extend( {}, QUnit.urlParams ), params );
643                 var querystring = "?",
644                         key;
645                 for ( key in params ) {
646                         querystring += encodeURIComponent( key ) + "=" +
647                                 encodeURIComponent( params[ key ] ) + "&";
648                 }
649                 return window.location.pathname + querystring.slice( 0, -1 );
650         },
651         
652         // Logging callbacks; all receive a single argument with the listed properties
653         // run test/logs.html for any related changes
654         begin: function() {},
655         // done: { failed, passed, total, runtime }
656         done: function() {},
657         // log: { result, actual, expected, message }
658         log: function() {},
659         // testStart: { name }
660         testStart: function() {},
661         // testDone: { name, failed, passed, total }
662         testDone: function() {},
663         // moduleStart: { name }
664         moduleStart: function() {},
665         // moduleDone: { name, failed, passed, total }
666         moduleDone: function() {}
667 });
668
669 if ( typeof document === "undefined" || document.readyState === "complete" ) {
670         config.autorun = true;
671 }
672
673 addEvent(window, "load", function() {
674         QUnit.begin({});
675         
676         // Initialize the config, saving the execution queue
677         var oldconfig = extend({}, config);
678         QUnit.init();
679         extend(config, oldconfig);
680
681         config.blocking = false;
682
683         var userAgent = id("qunit-userAgent");
684         if ( userAgent ) {
685                 userAgent.innerHTML = navigator.userAgent;
686         }
687         var banner = id("qunit-header");
688         if ( banner ) {
689                 banner.innerHTML = '<a href="' + QUnit.url({ filter: undefined }) + '"> ' + banner.innerHTML + '</a> ' +
690                         '<label><input name="noglobals" type="checkbox"' + ( config.noglobals ? ' checked="checked"' : '' ) + '>noglobals</label>' +
691                         '<label><input name="notrycatch" type="checkbox"' + ( config.notrycatch ? ' checked="checked"' : '' ) + '>notrycatch</label>';
692                 addEvent( banner, "change", function( event ) {
693                         var params = {};
694                         params[ event.target.name ] = event.target.checked ? true : undefined;
695                         window.location = QUnit.url( params );
696                 });
697         }
698         
699         var toolbar = id("qunit-testrunner-toolbar");
700         if ( toolbar ) {
701                 var filter = document.createElement("input");
702                 filter.type = "checkbox";
703                 filter.id = "qunit-filter-pass";
704                 addEvent( filter, "click", function() {
705                         var ol = document.getElementById("qunit-tests");
706                         if ( filter.checked ) {
707                                 ol.className = ol.className + " hidepass";
708                         } else {
709                                 var tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " ";
710                                 ol.className = tmp.replace(/ hidepass /, " ");
711                         }
712                         if ( defined.sessionStorage ) {
713                                 if (filter.checked) {
714                                         sessionStorage.setItem("qunit-filter-passed-tests",  "true");
715                                 } else {
716                                         sessionStorage.removeItem("qunit-filter-passed-tests");
717                                 }
718                         }
719                 });
720                 if ( defined.sessionStorage && sessionStorage.getItem("qunit-filter-passed-tests") ) {
721                         filter.checked = true;
722                         var ol = document.getElementById("qunit-tests");
723                         ol.className = ol.className + " hidepass";
724                 }
725                 toolbar.appendChild( filter );
726
727                 var label = document.createElement("label");
728                 label.setAttribute("for", "qunit-filter-pass");
729                 label.innerHTML = "Hide passed tests";
730                 toolbar.appendChild( label );
731         }
732
733         var main = id('qunit-fixture');
734         if ( main ) {
735                 config.fixture = main.innerHTML;
736         }
737
738         if (config.autostart) {
739                 QUnit.start();
740         }
741 });
742
743 function done() {
744         config.autorun = true;
745
746         // Log the last module results
747         if ( config.currentModule ) {
748                 QUnit.moduleDone( {
749                         name: config.currentModule,
750                         failed: config.moduleStats.bad,
751                         passed: config.moduleStats.all - config.moduleStats.bad,
752                         total: config.moduleStats.all
753                 } );
754         }
755
756         var banner = id("qunit-banner"),
757                 tests = id("qunit-tests"),
758                 runtime = +new Date - config.started,
759                 passed = config.stats.all - config.stats.bad,
760                 html = [
761                         'Tests completed in ',
762                         runtime,
763                         ' milliseconds.<br/>',
764                         '<span class="passed">',
765                         passed,
766                         '</span> tests of <span class="total">',
767                         config.stats.all,
768                         '</span> passed, <span class="failed">',
769                         config.stats.bad,
770                         '</span> failed.'
771                 ].join('');
772
773         if ( banner ) {
774                 banner.className = (config.stats.bad ? "qunit-fail" : "qunit-pass");
775         }
776
777         if ( tests ) {  
778                 id( "qunit-testresult" ).innerHTML = html;
779         }
780
781         if ( typeof document !== "undefined" && document.title ) {
782                 // TODO what are the unicode codes for these? as-is fails if qunit.js isn't served with the right mimetype/charset
783                 document.title = (config.stats.bad ? "✖" : "✔") + " " + document.title;
784         }
785
786         QUnit.done( {
787                 failed: config.stats.bad,
788                 passed: passed, 
789                 total: config.stats.all,
790                 runtime: runtime
791         } );
792 }
793
794 function validTest( name ) {
795         var filter = config.filter,
796                 run = false;
797
798         if ( !filter ) {
799                 return true;
800         }
801
802         not = filter.charAt( 0 ) === "!";
803         if ( not ) {
804                 filter = filter.slice( 1 );
805         }
806
807         if ( name.indexOf( filter ) !== -1 ) {
808                 return !not;
809         }
810
811         if ( not ) {
812                 run = true;
813         }
814
815         return run;
816 }
817
818 // so far supports only Firefox, Chrome and Opera (buggy)
819 // could be extended in the future to use something like https://github.com/csnover/TraceKit
820 function sourceFromStacktrace() {
821         try {
822                 throw new Error();
823         } catch ( e ) {
824                 if (e.stacktrace) {
825                         // Opera
826                         return e.stacktrace.split("\n")[6];
827                 } else if (e.stack) {
828                         // Firefox, Chrome
829                         return e.stack.split("\n")[4];
830                 }
831         }
832 }
833
834 function escapeHtml(s) {
835         if (!s) {
836                 return "";
837         }
838         s = s + "";
839         return s.replace(/[\&"<>\\]/g, function(s) {
840                 switch(s) {
841                         case "&": return "&amp;";
842                         case "\\": return "\\\\";
843                         case '"': return '\"';
844                         case "<": return "&lt;";
845                         case ">": return "&gt;";
846                         default: return s;
847                 }
848         });
849 }
850
851 function synchronize( callback ) {
852         config.queue.push( callback );
853
854         if ( config.autorun && !config.blocking ) {
855                 process();
856         }
857 }
858
859 function process() {
860         var start = (new Date()).getTime();
861
862         while ( config.queue.length && !config.blocking ) {
863                 if ( config.updateRate <= 0 || (((new Date()).getTime() - start) < config.updateRate) ) {
864                         config.queue.shift()();
865                 } else {
866                         window.setTimeout( process, 13 );
867                         break;
868                 }
869         }
870   if (!config.blocking && !config.queue.length) {
871     done();
872   }
873 }
874
875 function saveGlobal() {
876         config.pollution = [];
877         
878         if ( config.noglobals ) {
879                 for ( var key in window ) {
880                         config.pollution.push( key );
881                 }
882         }
883 }
884
885 function checkPollution( name ) {
886         var old = config.pollution;
887         saveGlobal();
888         
889         var newGlobals = diff( config.pollution, old );
890         if ( newGlobals.length > 0 ) {
891                 ok( false, "Introduced global variable(s): " + newGlobals.join(", ") );
892         }
893
894         var deletedGlobals = diff( old, config.pollution );
895         if ( deletedGlobals.length > 0 ) {
896                 ok( false, "Deleted global variable(s): " + deletedGlobals.join(", ") );
897         }
898 }
899
900 // returns a new Array with the elements that are in a but not in b
901 function diff( a, b ) {
902         var result = a.slice();
903         for ( var i = 0; i < result.length; i++ ) {
904                 for ( var j = 0; j < b.length; j++ ) {
905                         if ( result[i] === b[j] ) {
906                                 result.splice(i, 1);
907                                 i--;
908                                 break;
909                         }
910                 }
911         }
912         return result;
913 }
914
915 function fail(message, exception, callback) {
916         if ( typeof console !== "undefined" && console.error && console.warn ) {
917                 console.error(message);
918                 console.error(exception);
919                 console.warn(callback.toString());
920
921         } else if ( window.opera && opera.postError ) {
922                 opera.postError(message, exception, callback.toString);
923         }
924 }
925
926 function extend(a, b) {
927         for ( var prop in b ) {
928                 if ( b[prop] === undefined ) {
929                         delete a[prop];
930                 } else {
931                         a[prop] = b[prop];
932                 }
933         }
934
935         return a;
936 }
937
938 function addEvent(elem, type, fn) {
939         if ( elem.addEventListener ) {
940                 elem.addEventListener( type, fn, false );
941         } else if ( elem.attachEvent ) {
942                 elem.attachEvent( "on" + type, fn );
943         } else {
944                 fn();
945         }
946 }
947
948 function id(name) {
949         return !!(typeof document !== "undefined" && document && document.getElementById) &&
950                 document.getElementById( name );
951 }
952
953 // Test for equality any JavaScript type.
954 // Discussions and reference: http://philrathe.com/articles/equiv
955 // Test suites: http://philrathe.com/tests/equiv
956 // Author: Philippe Rathé <prathe@gmail.com>
957 QUnit.equiv = function () {
958
959     var innerEquiv; // the real equiv function
960     var callers = []; // stack to decide between skip/abort functions
961     var parents = []; // stack to avoiding loops from circular referencing
962
963     // Call the o related callback with the given arguments.
964     function bindCallbacks(o, callbacks, args) {
965         var prop = QUnit.objectType(o);
966         if (prop) {
967             if (QUnit.objectType(callbacks[prop]) === "function") {
968                 return callbacks[prop].apply(callbacks, args);
969             } else {
970                 return callbacks[prop]; // or undefined
971             }
972         }
973     }
974     
975     var callbacks = function () {
976
977         // for string, boolean, number and null
978         function useStrictEquality(b, a) {
979             if (b instanceof a.constructor || a instanceof b.constructor) {
980                 // to catch short annotaion VS 'new' annotation of a declaration
981                 // e.g. var i = 1;
982                 //      var j = new Number(1);
983                 return a == b;
984             } else {
985                 return a === b;
986             }
987         }
988
989         return {
990             "string": useStrictEquality,
991             "boolean": useStrictEquality,
992             "number": useStrictEquality,
993             "null": useStrictEquality,
994             "undefined": useStrictEquality,
995
996             "nan": function (b) {
997                 return isNaN(b);
998             },
999
1000             "date": function (b, a) {
1001                 return QUnit.objectType(b) === "date" && a.valueOf() === b.valueOf();
1002             },
1003
1004             "regexp": function (b, a) {
1005                 return QUnit.objectType(b) === "regexp" &&
1006                     a.source === b.source && // the regex itself
1007                     a.global === b.global && // and its modifers (gmi) ...
1008                     a.ignoreCase === b.ignoreCase &&
1009                     a.multiline === b.multiline;
1010             },
1011
1012             // - skip when the property is a method of an instance (OOP)
1013             // - abort otherwise,
1014             //   initial === would have catch identical references anyway
1015             "function": function () {
1016                 var caller = callers[callers.length - 1];
1017                 return caller !== Object &&
1018                         typeof caller !== "undefined";
1019             },
1020
1021             "array": function (b, a) {
1022                 var i, j, loop;
1023                 var len;
1024
1025                 // b could be an object literal here
1026                 if ( ! (QUnit.objectType(b) === "array")) {
1027                     return false;
1028                 }   
1029                 
1030                 len = a.length;
1031                 if (len !== b.length) { // safe and faster
1032                     return false;
1033                 }
1034                 
1035                 //track reference to avoid circular references
1036                 parents.push(a);
1037                 for (i = 0; i < len; i++) {
1038                     loop = false;
1039                     for(j=0;j<parents.length;j++){
1040                         if(parents[j] === a[i]){
1041                             loop = true;//dont rewalk array
1042                         }
1043                     }
1044                     if (!loop && ! innerEquiv(a[i], b[i])) {
1045                         parents.pop();
1046                         return false;
1047                     }
1048                 }
1049                 parents.pop();
1050                 return true;
1051             },
1052
1053             "object": function (b, a) {
1054                 var i, j, loop;
1055                 var eq = true; // unless we can proove it
1056                 var aProperties = [], bProperties = []; // collection of strings
1057
1058                 // comparing constructors is more strict than using instanceof
1059                 if ( a.constructor !== b.constructor) {
1060                     return false;
1061                 }
1062
1063                 // stack constructor before traversing properties
1064                 callers.push(a.constructor);
1065                 //track reference to avoid circular references
1066                 parents.push(a);
1067                 
1068                 for (i in a) { // be strict: don't ensures hasOwnProperty and go deep
1069                     loop = false;
1070                     for(j=0;j<parents.length;j++){
1071                         if(parents[j] === a[i])
1072                             loop = true; //don't go down the same path twice
1073                     }
1074                     aProperties.push(i); // collect a's properties
1075
1076                     if (!loop && ! innerEquiv(a[i], b[i])) {
1077                         eq = false;
1078                         break;
1079                     }
1080                 }
1081
1082                 callers.pop(); // unstack, we are done
1083                 parents.pop();
1084
1085                 for (i in b) {
1086                     bProperties.push(i); // collect b's properties
1087                 }
1088
1089                 // Ensures identical properties name
1090                 return eq && innerEquiv(aProperties.sort(), bProperties.sort());
1091             }
1092         };
1093     }();
1094
1095     innerEquiv = function () { // can take multiple arguments
1096         var args = Array.prototype.slice.apply(arguments);
1097         if (args.length < 2) {
1098             return true; // end transition
1099         }
1100
1101         return (function (a, b) {
1102             if (a === b) {
1103                 return true; // catch the most you can
1104             } else if (a === null || b === null || typeof a === "undefined" || typeof b === "undefined" || QUnit.objectType(a) !== QUnit.objectType(b)) {
1105                 return false; // don't lose time with error prone cases
1106             } else {
1107                 return bindCallbacks(a, callbacks, [b, a]);
1108             }
1109
1110         // apply transition with (1..n) arguments
1111         })(args[0], args[1]) && arguments.callee.apply(this, args.splice(1, args.length -1));
1112     };
1113
1114     return innerEquiv;
1115
1116 }();
1117
1118 /**
1119  * jsDump
1120  * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
1121  * Licensed under BSD (http://www.opensource.org/licenses/bsd-license.php)
1122  * Date: 5/15/2008
1123  * @projectDescription Advanced and extensible data dumping for Javascript.
1124  * @version 1.0.0
1125  * @author Ariel Flesler
1126  * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html}
1127  */
1128 QUnit.jsDump = (function() {
1129         function quote( str ) {
1130                 return '"' + str.toString().replace(/"/g, '\\"') + '"';
1131         };
1132         function literal( o ) {
1133                 return o + '';  
1134         };
1135         function join( pre, arr, post ) {
1136                 var s = jsDump.separator(),
1137                         base = jsDump.indent(),
1138                         inner = jsDump.indent(1);
1139                 if ( arr.join )
1140                         arr = arr.join( ',' + s + inner );
1141                 if ( !arr )
1142                         return pre + post;
1143                 return [ pre, inner + arr, base + post ].join(s);
1144         };
1145         function array( arr ) {
1146                 var i = arr.length,     ret = Array(i);                                 
1147                 this.up();
1148                 while ( i-- )
1149                         ret[i] = this.parse( arr[i] );                          
1150                 this.down();
1151                 return join( '[', ret, ']' );
1152         };
1153         
1154         var reName = /^function (\w+)/;
1155         
1156         var jsDump = {
1157                 parse:function( obj, type ) { //type is used mostly internally, you can fix a (custom)type in advance
1158                         var     parser = this.parsers[ type || this.typeOf(obj) ];
1159                         type = typeof parser;                   
1160                         
1161                         return type == 'function' ? parser.call( this, obj ) :
1162                                    type == 'string' ? parser :
1163                                    this.parsers.error;
1164                 },
1165                 typeOf:function( obj ) {
1166                         var type;
1167                         if ( obj === null ) {
1168                                 type = "null";
1169                         } else if (typeof obj === "undefined") {
1170                                 type = "undefined";
1171                         } else if (QUnit.is("RegExp", obj)) {
1172                                 type = "regexp";
1173                         } else if (QUnit.is("Date", obj)) {
1174                                 type = "date";
1175                         } else if (QUnit.is("Function", obj)) {
1176                                 type = "function";
1177                         } else if (typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined") {
1178                                 type = "window";
1179                         } else if (obj.nodeType === 9) {
1180                                 type = "document";
1181                         } else if (obj.nodeType) {
1182                                 type = "node";
1183                         } else if (typeof obj === "object" && typeof obj.length === "number" && obj.length >= 0) {
1184                                 type = "array";
1185                         } else {
1186                                 type = typeof obj;
1187                         }
1188                         return type;
1189                 },
1190                 separator:function() {
1191                         return this.multiline ? this.HTML ? '<br />' : '\n' : this.HTML ? '&nbsp;' : ' ';
1192                 },
1193                 indent:function( extra ) {// extra can be a number, shortcut for increasing-calling-decreasing
1194                         if ( !this.multiline )
1195                                 return '';
1196                         var chr = this.indentChar;
1197                         if ( this.HTML )
1198                                 chr = chr.replace(/\t/g,'   ').replace(/ /g,'&nbsp;');
1199                         return Array( this._depth_ + (extra||0) ).join(chr);
1200                 },
1201                 up:function( a ) {
1202                         this._depth_ += a || 1;
1203                 },
1204                 down:function( a ) {
1205                         this._depth_ -= a || 1;
1206                 },
1207                 setParser:function( name, parser ) {
1208                         this.parsers[name] = parser;
1209                 },
1210                 // The next 3 are exposed so you can use them
1211                 quote:quote, 
1212                 literal:literal,
1213                 join:join,
1214                 //
1215                 _depth_: 1,
1216                 // This is the list of parsers, to modify them, use jsDump.setParser
1217                 parsers:{
1218                         window: '[Window]',
1219                         document: '[Document]',
1220                         error:'[ERROR]', //when no parser is found, shouldn't happen
1221                         unknown: '[Unknown]',
1222                         'null':'null',
1223                         'undefined':'undefined',
1224                         'function':function( fn ) {
1225                                 var ret = 'function',
1226                                         name = 'name' in fn ? fn.name : (reName.exec(fn)||[])[1];//functions never have name in IE
1227                                 if ( name )
1228                                         ret += ' ' + name;
1229                                 ret += '(';
1230                                 
1231                                 ret = [ ret, QUnit.jsDump.parse( fn, 'functionArgs' ), '){'].join('');
1232                                 return join( ret, QUnit.jsDump.parse(fn,'functionCode'), '}' );
1233                         },
1234                         array: array,
1235                         nodelist: array,
1236                         arguments: array,
1237                         object:function( map ) {
1238                                 var ret = [ ];
1239                                 QUnit.jsDump.up();
1240                                 for ( var key in map )
1241                                         ret.push( QUnit.jsDump.parse(key,'key') + ': ' + QUnit.jsDump.parse(map[key]) );
1242                                 QUnit.jsDump.down();
1243                                 return join( '{', ret, '}' );
1244                         },
1245                         node:function( node ) {
1246                                 var open = QUnit.jsDump.HTML ? '&lt;' : '<',
1247                                         close = QUnit.jsDump.HTML ? '&gt;' : '>';
1248                                         
1249                                 var tag = node.nodeName.toLowerCase(),
1250                                         ret = open + tag;
1251                                         
1252                                 for ( var a in QUnit.jsDump.DOMAttrs ) {
1253                                         var val = node[QUnit.jsDump.DOMAttrs[a]];
1254                                         if ( val )
1255                                                 ret += ' ' + a + '=' + QUnit.jsDump.parse( val, 'attribute' );
1256                                 }
1257                                 return ret + close + open + '/' + tag + close;
1258                         },
1259                         functionArgs:function( fn ) {//function calls it internally, it's the arguments part of the function
1260                                 var l = fn.length;
1261                                 if ( !l ) return '';                            
1262                                 
1263                                 var args = Array(l);
1264                                 while ( l-- )
1265                                         args[l] = String.fromCharCode(97+l);//97 is 'a'
1266                                 return ' ' + args.join(', ') + ' ';
1267                         },
1268                         key:quote, //object calls it internally, the key part of an item in a map
1269                         functionCode:'[code]', //function calls it internally, it's the content of the function
1270                         attribute:quote, //node calls it internally, it's an html attribute value
1271                         string:quote,
1272                         date:quote,
1273                         regexp:literal, //regex
1274                         number:literal,
1275                         'boolean':literal
1276                 },
1277                 DOMAttrs:{//attributes to dump from nodes, name=>realName
1278                         id:'id',
1279                         name:'name',
1280                         'class':'className'
1281                 },
1282                 HTML:false,//if true, entities are escaped ( <, >, \t, space and \n )
1283                 indentChar:'  ',//indentation unit
1284                 multiline:true //if true, items in a collection, are separated by a \n, else just a space.
1285         };
1286
1287         return jsDump;
1288 })();
1289
1290 // from Sizzle.js
1291 function getText( elems ) {
1292         var ret = "", elem;
1293
1294         for ( var i = 0; elems[i]; i++ ) {
1295                 elem = elems[i];
1296
1297                 // Get the text from text nodes and CDATA nodes
1298                 if ( elem.nodeType === 3 || elem.nodeType === 4 ) {
1299                         ret += elem.nodeValue;
1300
1301                 // Traverse everything else, except comment nodes
1302                 } else if ( elem.nodeType !== 8 ) {
1303                         ret += getText( elem.childNodes );
1304                 }
1305         }
1306
1307         return ret;
1308 };
1309
1310 /*
1311  * Javascript Diff Algorithm
1312  *  By John Resig (http://ejohn.org/)
1313  *  Modified by Chu Alan "sprite"
1314  *
1315  * Released under the MIT license.
1316  *
1317  * More Info:
1318  *  http://ejohn.org/projects/javascript-diff-algorithm/
1319  *  
1320  * Usage: QUnit.diff(expected, actual)
1321  * 
1322  * 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"
1323  */
1324 QUnit.diff = (function() {
1325         function diff(o, n){
1326                 var ns = new Object();
1327                 var os = new Object();
1328                 
1329                 for (var i = 0; i < n.length; i++) {
1330                         if (ns[n[i]] == null) 
1331                                 ns[n[i]] = {
1332                                         rows: new Array(),
1333                                         o: null
1334                                 };
1335                         ns[n[i]].rows.push(i);
1336                 }
1337                 
1338                 for (var i = 0; i < o.length; i++) {
1339                         if (os[o[i]] == null) 
1340                                 os[o[i]] = {
1341                                         rows: new Array(),
1342                                         n: null
1343                                 };
1344                         os[o[i]].rows.push(i);
1345                 }
1346                 
1347                 for (var i in ns) {
1348                         if (ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1) {
1349                                 n[ns[i].rows[0]] = {
1350                                         text: n[ns[i].rows[0]],
1351                                         row: os[i].rows[0]
1352                                 };
1353                                 o[os[i].rows[0]] = {
1354                                         text: o[os[i].rows[0]],
1355                                         row: ns[i].rows[0]
1356                                 };
1357                         }
1358                 }
1359                 
1360                 for (var i = 0; i < n.length - 1; i++) {
1361                         if (n[i].text != null && n[i + 1].text == null && n[i].row + 1 < o.length && o[n[i].row + 1].text == null &&
1362                         n[i + 1] == o[n[i].row + 1]) {
1363                                 n[i + 1] = {
1364                                         text: n[i + 1],
1365                                         row: n[i].row + 1
1366                                 };
1367                                 o[n[i].row + 1] = {
1368                                         text: o[n[i].row + 1],
1369                                         row: i + 1
1370                                 };
1371                         }
1372                 }
1373                 
1374                 for (var i = n.length - 1; i > 0; i--) {
1375                         if (n[i].text != null && n[i - 1].text == null && n[i].row > 0 && o[n[i].row - 1].text == null &&
1376                         n[i - 1] == o[n[i].row - 1]) {
1377                                 n[i - 1] = {
1378                                         text: n[i - 1],
1379                                         row: n[i].row - 1
1380                                 };
1381                                 o[n[i].row - 1] = {
1382                                         text: o[n[i].row - 1],
1383                                         row: i - 1
1384                                 };
1385                         }
1386                 }
1387                 
1388                 return {
1389                         o: o,
1390                         n: n
1391                 };
1392         }
1393         
1394         return function(o, n){
1395                 o = o.replace(/\s+$/, '');
1396                 n = n.replace(/\s+$/, '');
1397                 var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/));
1398
1399                 var str = "";
1400                 
1401                 var oSpace = o.match(/\s+/g);
1402                 if (oSpace == null) {
1403                         oSpace = [" "];
1404                 }
1405                 else {
1406                         oSpace.push(" ");
1407                 }
1408                 var nSpace = n.match(/\s+/g);
1409                 if (nSpace == null) {
1410                         nSpace = [" "];
1411                 }
1412                 else {
1413                         nSpace.push(" ");
1414                 }
1415                 
1416                 if (out.n.length == 0) {
1417                         for (var i = 0; i < out.o.length; i++) {
1418                                 str += '<del>' + out.o[i] + oSpace[i] + "</del>";
1419                         }
1420                 }
1421                 else {
1422                         if (out.n[0].text == null) {
1423                                 for (n = 0; n < out.o.length && out.o[n].text == null; n++) {
1424                                         str += '<del>' + out.o[n] + oSpace[n] + "</del>";
1425                                 }
1426                         }
1427                         
1428                         for (var i = 0; i < out.n.length; i++) {
1429                                 if (out.n[i].text == null) {
1430                                         str += '<ins>' + out.n[i] + nSpace[i] + "</ins>";
1431                                 }
1432                                 else {
1433                                         var pre = "";
1434                                         
1435                                         for (n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++) {
1436                                                 pre += '<del>' + out.o[n] + oSpace[n] + "</del>";
1437                                         }
1438                                         str += " " + out.n[i].text + nSpace[i] + pre;
1439                                 }
1440                         }
1441                 }
1442                 
1443                 return str;
1444         };
1445 })();
1446
1447 })(this);

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