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