2
* QUnit v1.11.0 - A JavaScript Unit Testing Framework
6
* Copyright 2012 jQuery Foundation and other contributors
7
* Released under the MIT license.
8
* http://jquery.org/license
18
fileName = (sourceFromStacktrace( 0 ) || "" ).replace(/(:\d+)+\)?/, "").replace(/.+\//, ""),
19
toString = Object.prototype.toString,
20
hasOwn = Object.prototype.hasOwnProperty,
21
// Keep a local reference to Date (GH-283)
24
setTimeout: typeof window.setTimeout !== "undefined",
25
sessionStorage: (function() {
26
var x = "qunit-test-string";
28
sessionStorage.setItem( x, x );
29
sessionStorage.removeItem( x );
37
* Provides a normalized error string, correcting an issue
38
* with IE 7 (and prior) where Error.prototype.toString is
39
* not properly implemented
41
* Based on http://es5.github.com/#x15.11.4.4
43
* @param {String|Error} error
44
* @return {String} error message
46
errorString = function( error ) {
48
errorString = error.toString();
49
if ( errorString.substring( 0, 7 ) === "[object" ) {
50
name = error.name ? error.name.toString() : "Error";
51
message = error.message ? error.message.toString() : "";
52
if ( name && message ) {
53
return name + ": " + message;
56
} else if ( message ) {
66
* Makes a clone of an object using only Array or Object as base,
67
* and copies over the own enumerable properties.
70
* @return {Object} New object with only the own properties (recursively).
72
objectValues = function( obj ) {
73
// Grunt 0.3.x uses an older version of jshint that still has jshint/jshint#392.
74
/*jshint newcap: false */
76
vals = QUnit.is( "array", obj ) ? [] : {};
78
if ( hasOwn.call( obj, key ) ) {
80
vals[key] = val === Object(val) ? objectValues(val) : val;
86
function Test( settings ) {
87
extend( this, settings );
89
this.testNumber = ++Test.count;
97
tests = id( "qunit-tests" );
100
b = document.createElement( "strong" );
101
b.innerHTML = this.nameHtml;
103
// `a` initialized at top of scope
104
a = document.createElement( "a" );
105
a.innerHTML = "Rerun";
106
a.href = QUnit.url({ testNumber: this.testNumber });
108
li = document.createElement( "li" );
111
li.className = "running";
112
li.id = this.id = "qunit-test-output" + testId++;
114
tests.appendChild( li );
118
if ( this.module !== config.previousModule ) {
119
if ( config.previousModule ) {
120
runLoggingCallbacks( "moduleDone", QUnit, {
121
name: config.previousModule,
122
failed: config.moduleStats.bad,
123
passed: config.moduleStats.all - config.moduleStats.bad,
124
total: config.moduleStats.all
127
config.previousModule = this.module;
128
config.moduleStats = { all: 0, bad: 0 };
129
runLoggingCallbacks( "moduleStart", QUnit, {
132
} else if ( config.autorun ) {
133
runLoggingCallbacks( "moduleStart", QUnit, {
138
config.current = this;
140
this.testEnvironment = extend({
141
setup: function() {},
142
teardown: function() {}
143
}, this.moduleTestEnvironment );
145
this.started = +new Date();
146
runLoggingCallbacks( "testStart", QUnit, {
151
// allow utility functions to access the current test environment
153
QUnit.current_testEnvironment = this.testEnvironment;
155
if ( !config.pollution ) {
158
if ( config.notrycatch ) {
159
this.testEnvironment.setup.call( this.testEnvironment );
163
this.testEnvironment.setup.call( this.testEnvironment );
165
QUnit.pushFailure( "Setup failed on " + this.testName + ": " + ( e.message || e ), extractStacktrace( e, 1 ) );
169
config.current = this;
171
var running = id( "qunit-testresult" );
174
running.innerHTML = "Running: <br/>" + this.nameHtml;
181
this.callbackStarted = +new Date();
183
if ( config.notrycatch ) {
184
this.callback.call( this.testEnvironment, QUnit.assert );
185
this.callbackRuntime = +new Date() - this.callbackStarted;
190
this.callback.call( this.testEnvironment, QUnit.assert );
191
this.callbackRuntime = +new Date() - this.callbackStarted;
193
this.callbackRuntime = +new Date() - this.callbackStarted;
195
QUnit.pushFailure( "Died on test #" + (this.assertions.length + 1) + " " + this.stack + ": " + ( e.message || e ), extractStacktrace( e, 0 ) );
196
// else next test will carry the responsibility
199
// Restart the tests if they're blocking
200
if ( config.blocking ) {
205
teardown: function() {
206
config.current = this;
207
if ( config.notrycatch ) {
208
if ( typeof this.callbackRuntime === "undefined" ) {
209
this.callbackRuntime = +new Date() - this.callbackStarted;
211
this.testEnvironment.teardown.call( this.testEnvironment );
215
this.testEnvironment.teardown.call( this.testEnvironment );
217
QUnit.pushFailure( "Teardown failed on " + this.testName + ": " + ( e.message || e ), extractStacktrace( e, 1 ) );
223
config.current = this;
224
if ( config.requireExpects && this.expected === null ) {
225
QUnit.pushFailure( "Expected number of assertions to be defined, but expect() was not called.", this.stack );
226
} else if ( this.expected !== null && this.expected !== this.assertions.length ) {
227
QUnit.pushFailure( "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run", this.stack );
228
} else if ( this.expected === null && !this.assertions.length ) {
229
QUnit.pushFailure( "Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.", this.stack );
232
var i, assertion, a, b, time, li, ol,
236
tests = id( "qunit-tests" );
238
this.runtime = +new Date() - this.started;
239
config.stats.all += this.assertions.length;
240
config.moduleStats.all += this.assertions.length;
243
ol = document.createElement( "ol" );
244
ol.className = "qunit-assert-list";
246
for ( i = 0; i < this.assertions.length; i++ ) {
247
assertion = this.assertions[i];
249
li = document.createElement( "li" );
250
li.className = assertion.result ? "pass" : "fail";
251
li.innerHTML = assertion.message || ( assertion.result ? "okay" : "failed" );
252
ol.appendChild( li );
254
if ( assertion.result ) {
259
config.moduleStats.bad++;
263
// store result when possible
264
if ( QUnit.config.reorder && defined.sessionStorage ) {
266
sessionStorage.setItem( "qunit-test-" + this.module + "-" + this.testName, bad );
268
sessionStorage.removeItem( "qunit-test-" + this.module + "-" + this.testName );
273
addClass( ol, "qunit-collapsed" );
276
// `b` initialized at top of scope
277
b = document.createElement( "strong" );
278
b.innerHTML = this.nameHtml + " <b class='counts'>(<b class='failed'>" + bad + "</b>, <b class='passed'>" + good + "</b>, " + this.assertions.length + ")</b>";
280
addEvent(b, "click", function() {
281
var next = b.parentNode.lastChild,
282
collapsed = hasClass( next, "qunit-collapsed" );
283
( collapsed ? removeClass : addClass )( next, "qunit-collapsed" );
286
addEvent(b, "dblclick", function( e ) {
287
var target = e && e.target ? e.target : window.event.srcElement;
288
if ( target.nodeName.toLowerCase() === "span" || target.nodeName.toLowerCase() === "b" ) {
289
target = target.parentNode;
291
if ( window.location && target.nodeName.toLowerCase() === "strong" ) {
292
window.location = QUnit.url({ testNumber: test.testNumber });
296
// `time` initialized at top of scope
297
time = document.createElement( "span" );
298
time.className = "runtime";
299
time.innerHTML = this.runtime + " ms";
301
// `li` initialized at top of scope
303
li.className = bad ? "fail" : "pass";
304
li.removeChild( li.firstChild );
308
li.appendChild( time );
309
li.appendChild( ol );
312
for ( i = 0; i < this.assertions.length; i++ ) {
313
if ( !this.assertions[i].result ) {
316
config.moduleStats.bad++;
321
runLoggingCallbacks( "testDone", QUnit, {
325
passed: this.assertions.length - bad,
326
total: this.assertions.length,
327
duration: this.runtime
332
config.current = undefined;
339
synchronize(function() {
343
// each of these can by async
344
synchronize(function() {
347
synchronize(function() {
350
synchronize(function() {
353
synchronize(function() {
358
// `bad` initialized at top of scope
359
// defer when previous test run passed, if storage is available
360
bad = QUnit.config.reorder && defined.sessionStorage &&
361
+sessionStorage.getItem( "qunit-test-" + this.module + "-" + this.testName );
366
synchronize( run, true );
371
// Root QUnit object.
372
// `QUnit` initialized at top of scope
375
// call on start of module test to prepend name to all tests
376
module: function( name, testEnvironment ) {
377
config.currentModule = name;
378
config.currentModuleTestEnvironment = testEnvironment;
379
config.modules[name] = true;
382
asyncTest: function( testName, expected, callback ) {
383
if ( arguments.length === 2 ) {
388
QUnit.test( testName, expected, callback, true );
391
test: function( testName, expected, callback, async ) {
393
nameHtml = "<span class='test-name'>" + escapeText( testName ) + "</span>";
395
if ( arguments.length === 2 ) {
400
if ( config.currentModule ) {
401
nameHtml = "<span class='module-name'>" + escapeText( config.currentModule ) + "</span>: " + nameHtml;
410
module: config.currentModule,
411
moduleTestEnvironment: config.currentModuleTestEnvironment,
412
stack: sourceFromStacktrace( 2 )
415
if ( !validTest( test ) ) {
422
// Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through.
423
expect: function( asserts ) {
424
if (arguments.length === 1) {
425
config.current.expected = asserts;
427
return config.current.expected;
431
start: function( count ) {
432
// QUnit hasn't been initialized yet.
433
// Note: RequireJS (et al) may delay onLoad
434
if ( config.semaphore === undefined ) {
435
QUnit.begin(function() {
436
// This is triggered at the top of QUnit.load, push start() to the event loop, to allow QUnit.load to finish first
437
setTimeout(function() {
438
QUnit.start( count );
444
config.semaphore -= count || 1;
445
// don't start until equal number of stop-calls
446
if ( config.semaphore > 0 ) {
449
// ignore if start is called more often then stop
450
if ( config.semaphore < 0 ) {
451
config.semaphore = 0;
452
QUnit.pushFailure( "Called start() while already started (QUnit.config.semaphore was 0 already)", null, sourceFromStacktrace(2) );
455
// A slight delay, to avoid any current callbacks
456
if ( defined.setTimeout ) {
457
window.setTimeout(function() {
458
if ( config.semaphore > 0 ) {
461
if ( config.timeout ) {
462
clearTimeout( config.timeout );
465
config.blocking = false;
469
config.blocking = false;
474
stop: function( count ) {
475
config.semaphore += count || 1;
476
config.blocking = true;
478
if ( config.testTimeout && defined.setTimeout ) {
479
clearTimeout( config.timeout );
480
config.timeout = window.setTimeout(function() {
481
QUnit.ok( false, "Test timed out" );
482
config.semaphore = 1;
484
}, config.testTimeout );
489
// `assert` initialized at top of scope
491
// All of these must either call QUnit.push() or manually do:
492
// - runLoggingCallbacks( "log", .. );
493
// - config.current.assertions.push({ .. });
494
// We attach it to the QUnit object *after* we expose the public API,
495
// otherwise `assert` will become a global variable in browsers (#341).
498
* Asserts rough true-ish result.
501
* @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" );
503
ok: function( result, msg ) {
504
if ( !config.current ) {
505
throw new Error( "ok() assertion outside test context, was " + sourceFromStacktrace(2) );
511
module: config.current.module,
512
name: config.current.testName,
517
msg = escapeText( msg || (result ? "okay" : "failed" ) );
518
msg = "<span class='test-message'>" + msg + "</span>";
521
source = sourceFromStacktrace( 2 );
523
details.source = source;
524
msg += "<table><tr class='test-source'><th>Source: </th><td><pre>" + escapeText( source ) + "</pre></td></tr></table>";
527
runLoggingCallbacks( "log", QUnit, details );
528
config.current.assertions.push({
535
* Assert that the first two arguments are equal, with an optional message.
536
* Prints out both actual and expected values.
539
* @example equal( format( "Received {0} bytes.", 2), "Received 2 bytes.", "format() replaces {0} with next argument" );
541
equal: function( actual, expected, message ) {
542
/*jshint eqeqeq:false */
543
QUnit.push( expected == actual, actual, expected, message );
550
notEqual: function( actual, expected, message ) {
551
/*jshint eqeqeq:false */
552
QUnit.push( expected != actual, actual, expected, message );
559
propEqual: function( actual, expected, message ) {
560
actual = objectValues(actual);
561
expected = objectValues(expected);
562
QUnit.push( QUnit.equiv(actual, expected), actual, expected, message );
569
notPropEqual: function( actual, expected, message ) {
570
actual = objectValues(actual);
571
expected = objectValues(expected);
572
QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message );
579
deepEqual: function( actual, expected, message ) {
580
QUnit.push( QUnit.equiv(actual, expected), actual, expected, message );
587
notDeepEqual: function( actual, expected, message ) {
588
QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message );
595
strictEqual: function( actual, expected, message ) {
596
QUnit.push( expected === actual, actual, expected, message );
600
* @name notStrictEqual
603
notStrictEqual: function( actual, expected, message ) {
604
QUnit.push( expected !== actual, actual, expected, message );
607
"throws": function( block, expected, message ) {
609
expectedOutput = expected,
612
// 'expected' is optional
613
if ( typeof expected === "string" ) {
618
config.current.ignoreGlobalErrors = true;
620
block.call( config.current.testEnvironment );
624
config.current.ignoreGlobalErrors = false;
627
// we don't want to validate thrown error
630
expectedOutput = null;
631
// expected is a regexp
632
} else if ( QUnit.objectType( expected ) === "regexp" ) {
633
ok = expected.test( errorString( actual ) );
634
// expected is a constructor
635
} else if ( actual instanceof expected ) {
637
// expected is a validation function which returns true is validation passed
638
} else if ( expected.call( {}, actual ) === true ) {
639
expectedOutput = null;
643
QUnit.push( ok, actual, expectedOutput, message );
645
QUnit.pushFailure( message, null, 'No exception was thrown.' );
651
* @deprecate since 1.8.0
652
* Kept assertion helpers in root for backwards compatibility.
654
extend( QUnit, assert );
657
* @deprecated since 1.9.0
658
* Kept root "raises()" for backwards compatibility.
659
* (Note that we don't introduce assert.raises).
661
QUnit.raises = assert[ "throws" ];
664
* @deprecated since 1.0.0, replaced with error pushes since 1.3.0
665
* Kept to avoid TypeErrors for undefined methods.
667
QUnit.equals = function() {
668
QUnit.push( false, false, false, "QUnit.equals has been deprecated since 2009 (e88049a0), use QUnit.equal instead" );
670
QUnit.same = function() {
671
QUnit.push( false, false, false, "QUnit.same has been deprecated since 2009 (e88049a0), use QUnit.deepEqual instead" );
674
// We want access to the constructor's prototype
679
// Make F QUnit's constructor so that we can add to the prototype later
680
QUnit.constructor = F;
684
* Config object: Maintain internal state
685
* Later exposed as QUnit.config
686
* `config` initialized at top of scope
689
// The queue of tests to run
692
// block until document ready
695
// when enabled, show only failing tests
696
// gets persisted through sessionStorage and can be changed in UI via checkbox
699
// by default, run previously failed tests first
700
// very useful in combination with "Hide passed tests" checked
703
// by default, modify document.title when suite is done
706
// when enabled, all tests must call expect()
707
requireExpects: false,
709
// add checkboxes that are persisted in the query-string
710
// when enabled, the id is set to `true` as a `QUnit.config` property
714
label: "Check for Globals",
715
tooltip: "Enabling this will test if any test introduces new properties on the `window` object. Stored as query-strings."
719
label: "No try-catch",
720
tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging exceptions in IE reasonable. Stored as query-strings."
724
// Set of all modules.
727
// logging callback queues
737
// Export global variables, unless an 'exports' object exists,
738
// in that case we assume we're in CommonJS (dealt with on the bottom of the script)
739
if ( typeof exports === "undefined" ) {
740
extend( window, QUnit );
742
// Expose QUnit object
743
window.QUnit = QUnit;
746
// Initialize more QUnit.config and QUnit.urlParams
749
location = window.location || { search: "", protocol: "file:" },
750
params = location.search.slice( 1 ).split( "&" ),
751
length = params.length,
756
for ( i = 0; i < length; i++ ) {
757
current = params[ i ].split( "=" );
758
current[ 0 ] = decodeURIComponent( current[ 0 ] );
759
// allow just a key to turn on a flag, e.g., test.html?noglobals
760
current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true;
761
urlParams[ current[ 0 ] ] = current[ 1 ];
765
QUnit.urlParams = urlParams;
767
// String search anywhere in moduleName+testName
768
config.filter = urlParams.filter;
770
// Exact match of the module name
771
config.module = urlParams.module;
773
config.testNumber = parseInt( urlParams.testNumber, 10 ) || null;
775
// Figure out if we're running the tests from a server or not
776
QUnit.isLocal = location.protocol === "file:";
779
// Extend QUnit object,
780
// these after set here because they should not be exposed as global functions
786
// Initialize the configuration options
789
stats: { all: 0, bad: 0 },
790
moduleStats: { all: 0, bad: 0 },
791
started: +new Date(),
801
var tests, banner, result,
802
qunit = id( "qunit" );
806
"<h1 id='qunit-header'>" + escapeText( document.title ) + "</h1>" +
807
"<h2 id='qunit-banner'></h2>" +
808
"<div id='qunit-testrunner-toolbar'></div>" +
809
"<h2 id='qunit-userAgent'></h2>" +
810
"<ol id='qunit-tests'></ol>";
813
tests = id( "qunit-tests" );
814
banner = id( "qunit-banner" );
815
result = id( "qunit-testresult" );
818
tests.innerHTML = "";
822
banner.className = "";
826
result.parentNode.removeChild( result );
830
result = document.createElement( "p" );
831
result.id = "qunit-testresult";
832
result.className = "result";
833
tests.parentNode.insertBefore( result, tests );
834
result.innerHTML = "Running...<br/> ";
838
// Resets the test setup. Useful for tests that modify the DOM.
840
var fixture = id( "qunit-fixture" );
842
fixture.innerHTML = config.fixture;
846
// Trigger an event on an element.
847
// @example triggerEvent( document.body, "click" );
848
triggerEvent: function( elem, type, event ) {
849
if ( document.createEvent ) {
850
event = document.createEvent( "MouseEvents" );
851
event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView,
852
0, 0, 0, 0, 0, false, false, false, false, 0, null);
854
elem.dispatchEvent( event );
855
} else if ( elem.fireEvent ) {
856
elem.fireEvent( "on" + type );
860
// Safe object type checking
861
is: function( type, obj ) {
862
return QUnit.objectType( obj ) === type;
865
objectType: function( obj ) {
866
if ( typeof obj === "undefined" ) {
868
// consider: typeof null === object
870
if ( obj === null ) {
874
var match = toString.call( obj ).match(/^\[object\s(.*)\]$/),
875
type = match && match[1] || "";
889
return type.toLowerCase();
891
if ( typeof obj === "object" ) {
897
push: function( result, actual, expected, message ) {
898
if ( !config.current ) {
899
throw new Error( "assertion outside test context, was " + sourceFromStacktrace() );
904
module: config.current.module,
905
name: config.current.testName,
912
message = escapeText( message ) || ( result ? "okay" : "failed" );
913
message = "<span class='test-message'>" + message + "</span>";
917
expected = escapeText( QUnit.jsDump.parse(expected) );
918
actual = escapeText( QUnit.jsDump.parse(actual) );
919
output += "<table><tr class='test-expected'><th>Expected: </th><td><pre>" + expected + "</pre></td></tr>";
921
if ( actual !== expected ) {
922
output += "<tr class='test-actual'><th>Result: </th><td><pre>" + actual + "</pre></td></tr>";
923
output += "<tr class='test-diff'><th>Diff: </th><td><pre>" + QUnit.diff( expected, actual ) + "</pre></td></tr>";
926
source = sourceFromStacktrace();
929
details.source = source;
930
output += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeText( source ) + "</pre></td></tr>";
933
output += "</table>";
936
runLoggingCallbacks( "log", QUnit, details );
938
config.current.assertions.push({
944
pushFailure: function( message, source, actual ) {
945
if ( !config.current ) {
946
throw new Error( "pushFailure() assertion outside test context, was " + sourceFromStacktrace(2) );
951
module: config.current.module,
952
name: config.current.testName,
957
message = escapeText( message ) || "error";
958
message = "<span class='test-message'>" + message + "</span>";
964
output += "<tr class='test-actual'><th>Result: </th><td><pre>" + escapeText( actual ) + "</pre></td></tr>";
968
details.source = source;
969
output += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeText( source ) + "</pre></td></tr>";
972
output += "</table>";
974
runLoggingCallbacks( "log", QUnit, details );
976
config.current.assertions.push({
982
url: function( params ) {
983
params = extend( extend( {}, QUnit.urlParams ), params );
987
for ( key in params ) {
988
if ( !hasOwn.call( params, key ) ) {
991
querystring += encodeURIComponent( key ) + "=" +
992
encodeURIComponent( params[ key ] ) + "&";
994
return window.location.protocol + "//" + window.location.host +
995
window.location.pathname + querystring.slice( 0, -1 );
1001
// load, equiv, jsDump, diff: Attached later
1005
* @deprecated: Created for backwards compatibility with test runner that set the hook function
1006
* into QUnit.{hook}, instead of invoking it and passing the hook function.
1007
* QUnit.constructor is set to the empty F() above so that we can add to it's prototype here.
1008
* Doing this allows us to tell if the following methods have been overwritten on the actual
1011
extend( QUnit.constructor.prototype, {
1013
// Logging callbacks; all receive a single argument with the listed properties
1014
// run test/logs.html for any related changes
1015
begin: registerLoggingCallback( "begin" ),
1017
// done: { failed, passed, total, runtime }
1018
done: registerLoggingCallback( "done" ),
1020
// log: { result, actual, expected, message }
1021
log: registerLoggingCallback( "log" ),
1023
// testStart: { name }
1024
testStart: registerLoggingCallback( "testStart" ),
1026
// testDone: { name, failed, passed, total, duration }
1027
testDone: registerLoggingCallback( "testDone" ),
1029
// moduleStart: { name }
1030
moduleStart: registerLoggingCallback( "moduleStart" ),
1032
// moduleDone: { name, failed, passed, total }
1033
moduleDone: registerLoggingCallback( "moduleDone" )
1036
if ( typeof document === "undefined" || document.readyState === "complete" ) {
1037
config.autorun = true;
1040
QUnit.load = function() {
1041
runLoggingCallbacks( "begin", QUnit, {} );
1043
// Initialize the config, saving the execution queue
1044
var banner, filter, i, label, len, main, ol, toolbar, userAgent, val,
1045
urlConfigCheckboxesContainer, urlConfigCheckboxes, moduleFilter,
1047
moduleFilterHtml = "",
1049
oldconfig = extend( {}, config );
1052
extend(config, oldconfig);
1054
config.blocking = false;
1056
len = config.urlConfig.length;
1058
for ( i = 0; i < len; i++ ) {
1059
val = config.urlConfig[i];
1060
if ( typeof val === "string" ) {
1064
tooltip: "[no tooltip available]"
1067
config[ val.id ] = QUnit.urlParams[ val.id ];
1068
urlConfigHtml += "<input id='qunit-urlconfig-" + escapeText( val.id ) +
1069
"' name='" + escapeText( val.id ) +
1070
"' type='checkbox'" + ( config[ val.id ] ? " checked='checked'" : "" ) +
1071
" title='" + escapeText( val.tooltip ) +
1072
"'><label for='qunit-urlconfig-" + escapeText( val.id ) +
1073
"' title='" + escapeText( val.tooltip ) + "'>" + val.label + "</label>";
1076
moduleFilterHtml += "<label for='qunit-modulefilter'>Module: </label><select id='qunit-modulefilter' name='modulefilter'><option value='' " +
1077
( config.module === undefined ? "selected='selected'" : "" ) +
1078
">< All Modules ></option>";
1080
for ( i in config.modules ) {
1081
if ( config.modules.hasOwnProperty( i ) ) {
1083
moduleFilterHtml += "<option value='" + escapeText( encodeURIComponent(i) ) + "' " +
1084
( config.module === i ? "selected='selected'" : "" ) +
1085
">" + escapeText(i) + "</option>";
1088
moduleFilterHtml += "</select>";
1090
// `userAgent` initialized at top of scope
1091
userAgent = id( "qunit-userAgent" );
1093
userAgent.innerHTML = navigator.userAgent;
1096
// `banner` initialized at top of scope
1097
banner = id( "qunit-header" );
1099
banner.innerHTML = "<a href='" + QUnit.url({ filter: undefined, module: undefined, testNumber: undefined }) + "'>" + banner.innerHTML + "</a> ";
1102
// `toolbar` initialized at top of scope
1103
toolbar = id( "qunit-testrunner-toolbar" );
1105
// `filter` initialized at top of scope
1106
filter = document.createElement( "input" );
1107
filter.type = "checkbox";
1108
filter.id = "qunit-filter-pass";
1110
addEvent( filter, "click", function() {
1112
ol = document.getElementById( "qunit-tests" );
1114
if ( filter.checked ) {
1115
ol.className = ol.className + " hidepass";
1117
tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " ";
1118
ol.className = tmp.replace( / hidepass /, " " );
1120
if ( defined.sessionStorage ) {
1121
if (filter.checked) {
1122
sessionStorage.setItem( "qunit-filter-passed-tests", "true" );
1124
sessionStorage.removeItem( "qunit-filter-passed-tests" );
1129
if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem( "qunit-filter-passed-tests" ) ) {
1130
filter.checked = true;
1131
// `ol` initialized at top of scope
1132
ol = document.getElementById( "qunit-tests" );
1133
ol.className = ol.className + " hidepass";
1135
toolbar.appendChild( filter );
1137
// `label` initialized at top of scope
1138
label = document.createElement( "label" );
1139
label.setAttribute( "for", "qunit-filter-pass" );
1140
label.setAttribute( "title", "Only show tests and assertons that fail. Stored in sessionStorage." );
1141
label.innerHTML = "Hide passed tests";
1142
toolbar.appendChild( label );
1144
urlConfigCheckboxesContainer = document.createElement("span");
1145
urlConfigCheckboxesContainer.innerHTML = urlConfigHtml;
1146
urlConfigCheckboxes = urlConfigCheckboxesContainer.getElementsByTagName("input");
1147
// For oldIE support:
1148
// * Add handlers to the individual elements instead of the container
1149
// * Use "click" instead of "change"
1150
// * Fallback from event.target to event.srcElement
1151
addEvents( urlConfigCheckboxes, "click", function( event ) {
1153
target = event.target || event.srcElement;
1154
params[ target.name ] = target.checked ? true : undefined;
1155
window.location = QUnit.url( params );
1157
toolbar.appendChild( urlConfigCheckboxesContainer );
1159
if (numModules > 1) {
1160
moduleFilter = document.createElement( 'span' );
1161
moduleFilter.setAttribute( 'id', 'qunit-modulefilter-container' );
1162
moduleFilter.innerHTML = moduleFilterHtml;
1163
addEvent( moduleFilter.lastChild, "change", function() {
1164
var selectBox = moduleFilter.getElementsByTagName("select")[0],
1165
selectedModule = decodeURIComponent(selectBox.options[selectBox.selectedIndex].value);
1167
window.location = QUnit.url( { module: ( selectedModule === "" ) ? undefined : selectedModule } );
1169
toolbar.appendChild(moduleFilter);
1173
// `main` initialized at top of scope
1174
main = id( "qunit-fixture" );
1176
config.fixture = main.innerHTML;
1179
if ( config.autostart ) {
1184
addEvent( window, "load", QUnit.load );
1186
// `onErrorFnPrev` initialized at top of scope
1187
// Preserve other handlers
1188
onErrorFnPrev = window.onerror;
1190
// Cover uncaught exceptions
1191
// Returning true will surpress the default browser handler,
1192
// returning false will let it run.
1193
window.onerror = function ( error, filePath, linerNr ) {
1195
if ( onErrorFnPrev ) {
1196
ret = onErrorFnPrev( error, filePath, linerNr );
1199
// Treat return value as window.onerror itself does,
1200
// Only do our handling if not surpressed.
1201
if ( ret !== true ) {
1202
if ( QUnit.config.current ) {
1203
if ( QUnit.config.current.ignoreGlobalErrors ) {
1206
QUnit.pushFailure( error, filePath + ":" + linerNr );
1208
QUnit.test( "global failure", extend( function() {
1209
QUnit.pushFailure( error, filePath + ":" + linerNr );
1210
}, { validTest: validTest } ) );
1219
config.autorun = true;
1221
// Log the last module results
1222
if ( config.currentModule ) {
1223
runLoggingCallbacks( "moduleDone", QUnit, {
1224
name: config.currentModule,
1225
failed: config.moduleStats.bad,
1226
passed: config.moduleStats.all - config.moduleStats.bad,
1227
total: config.moduleStats.all
1232
banner = id( "qunit-banner" ),
1233
tests = id( "qunit-tests" ),
1234
runtime = +new Date() - config.started,
1235
passed = config.stats.all - config.stats.bad,
1237
"Tests completed in ",
1239
" milliseconds.<br/>",
1240
"<span class='passed'>",
1242
"</span> assertions of <span class='total'>",
1244
"</span> passed, <span class='failed'>",
1250
banner.className = ( config.stats.bad ? "qunit-fail" : "qunit-pass" );
1254
id( "qunit-testresult" ).innerHTML = html;
1257
if ( config.altertitle && typeof document !== "undefined" && document.title ) {
1258
// show âś– for good, âś” for bad suite result in title
1259
// use escape sequences in case file gets loaded with non-utf-8-charset
1261
( config.stats.bad ? "\u2716" : "\u2714" ),
1262
document.title.replace( /^[\u2714\u2716] /i, "" )
1266
// clear own sessionStorage items if all tests passed
1267
if ( config.reorder && defined.sessionStorage && config.stats.bad === 0 ) {
1268
// `key` & `i` initialized at top of scope
1269
for ( i = 0; i < sessionStorage.length; i++ ) {
1270
key = sessionStorage.key( i++ );
1271
if ( key.indexOf( "qunit-test-" ) === 0 ) {
1272
sessionStorage.removeItem( key );
1277
// scroll back to top to show results
1278
if ( window.scrollTo ) {
1279
window.scrollTo(0, 0);
1282
runLoggingCallbacks( "done", QUnit, {
1283
failed: config.stats.bad,
1285
total: config.stats.all,
1290
/** @return Boolean: true if this test should be ran */
1291
function validTest( test ) {
1293
filter = config.filter && config.filter.toLowerCase(),
1294
module = config.module && config.module.toLowerCase(),
1295
fullName = (test.module + ": " + test.testName).toLowerCase();
1297
// Internally-generated tests are always valid
1298
if ( test.callback && test.callback.validTest === validTest ) {
1299
delete test.callback.validTest;
1303
if ( config.testNumber ) {
1304
return test.testNumber === config.testNumber;
1307
if ( module && ( !test.module || test.module.toLowerCase() !== module ) ) {
1315
include = filter.charAt( 0 ) !== "!";
1317
filter = filter.slice( 1 );
1320
// If the filter matches, we need to honour include
1321
if ( fullName.indexOf( filter ) !== -1 ) {
1325
// Otherwise, do the opposite
1329
// so far supports only Firefox, Chrome and Opera (buggy), Safari (for real exceptions)
1330
// Later Safari and IE10 are supposed to support error.stack as well
1331
// See also https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack
1332
function extractStacktrace( e, offset ) {
1333
offset = offset === undefined ? 3 : offset;
1335
var stack, include, i;
1337
if ( e.stacktrace ) {
1339
return e.stacktrace.split( "\n" )[ offset + 3 ];
1340
} else if ( e.stack ) {
1342
stack = e.stack.split( "\n" );
1343
if (/^error$/i.test( stack[0] ) ) {
1348
for ( i = offset; i < stack.length; i++ ) {
1349
if ( stack[ i ].indexOf( fileName ) !== -1 ) {
1352
include.push( stack[ i ] );
1354
if ( include.length ) {
1355
return include.join( "\n" );
1358
return stack[ offset ];
1359
} else if ( e.sourceURL ) {
1360
// Safari, PhantomJS
1361
// hopefully one day Safari provides actual stacktraces
1362
// exclude useless self-reference for generated Error objects
1363
if ( /qunit.js$/.test( e.sourceURL ) ) {
1366
// for actual exceptions, this is useful
1367
return e.sourceURL + ":" + e.line;
1370
function sourceFromStacktrace( offset ) {
1374
return extractStacktrace( e, offset );
1379
* Escape text for attribute or text content.
1381
function escapeText( s ) {
1386
// Both single quotes and double quotes (for attributes)
1387
return s.replace( /['"<>&]/g, function( s ) {
1403
function synchronize( callback, last ) {
1404
config.queue.push( callback );
1406
if ( config.autorun && !config.blocking ) {
1411
function process( last ) {
1415
var start = new Date().getTime();
1416
config.depth = config.depth ? config.depth + 1 : 1;
1418
while ( config.queue.length && !config.blocking ) {
1419
if ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate ) ) {
1420
config.queue.shift()();
1422
window.setTimeout( next, 13 );
1427
if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) {
1432
function saveGlobal() {
1433
config.pollution = [];
1435
if ( config.noglobals ) {
1436
for ( var key in window ) {
1437
// in Opera sometimes DOM element ids show up here, ignore them
1438
if ( !hasOwn.call( window, key ) || /^qunit-test-output/.test( key ) ) {
1441
config.pollution.push( key );
1446
function checkPollution() {
1449
old = config.pollution;
1453
newGlobals = diff( config.pollution, old );
1454
if ( newGlobals.length > 0 ) {
1455
QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join(", ") );
1458
deletedGlobals = diff( old, config.pollution );
1459
if ( deletedGlobals.length > 0 ) {
1460
QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join(", ") );
1464
// returns a new Array with the elements that are in a but not in b
1465
function diff( a, b ) {
1469
for ( i = 0; i < result.length; i++ ) {
1470
for ( j = 0; j < b.length; j++ ) {
1471
if ( result[i] === b[j] ) {
1472
result.splice( i, 1 );
1481
function extend( a, b ) {
1482
for ( var prop in b ) {
1483
if ( b[ prop ] === undefined ) {
1486
// Avoid "Member not found" error in IE8 caused by setting window.constructor
1487
} else if ( prop !== "constructor" || a !== window ) {
1488
a[ prop ] = b[ prop ];
1496
* @param {HTMLElement} elem
1497
* @param {string} type
1498
* @param {Function} fn
1500
function addEvent( elem, type, fn ) {
1501
// Standards-based browsers
1502
if ( elem.addEventListener ) {
1503
elem.addEventListener( type, fn, false );
1506
elem.attachEvent( "on" + type, fn );
1511
* @param {Array|NodeList} elems
1512
* @param {string} type
1513
* @param {Function} fn
1515
function addEvents( elems, type, fn ) {
1516
var i = elems.length;
1518
addEvent( elems[i], type, fn );
1522
function hasClass( elem, name ) {
1523
return (" " + elem.className + " ").indexOf(" " + name + " ") > -1;
1526
function addClass( elem, name ) {
1527
if ( !hasClass( elem, name ) ) {
1528
elem.className += (elem.className ? " " : "") + name;
1532
function removeClass( elem, name ) {
1533
var set = " " + elem.className + " ";
1534
// Class name may appear multiple times
1535
while ( set.indexOf(" " + name + " ") > -1 ) {
1536
set = set.replace(" " + name + " " , " ");
1538
// If possible, trim it for prettiness, but not neccecarily
1539
elem.className = window.jQuery ? jQuery.trim( set ) : ( set.trim ? set.trim() : set );
1542
function id( name ) {
1543
return !!( typeof document !== "undefined" && document && document.getElementById ) &&
1544
document.getElementById( name );
1547
function registerLoggingCallback( key ) {
1548
return function( callback ) {
1549
config[key].push( callback );
1553
// Supports deprecated method of completely overwriting logging callbacks
1554
function runLoggingCallbacks( key, scope, args ) {
1556
if ( QUnit.hasOwnProperty( key ) ) {
1557
QUnit[ key ].call(scope, args );
1559
callbacks = config[ key ];
1560
for ( i = 0; i < callbacks.length; i++ ) {
1561
callbacks[ i ].call( scope, args );
1566
// Test for equality any JavaScript type.
1567
// Author: Philippe Rathé <prathe@gmail.com>
1568
QUnit.equiv = (function() {
1570
// Call the o related callback with the given arguments.
1571
function bindCallbacks( o, callbacks, args ) {
1572
var prop = QUnit.objectType( o );
1574
if ( QUnit.objectType( callbacks[ prop ] ) === "function" ) {
1575
return callbacks[ prop ].apply( callbacks, args );
1577
return callbacks[ prop ]; // or undefined
1582
// the real equiv function
1584
// stack to decide between skip/abort functions
1586
// stack to avoiding loops from circular referencing
1589
getProto = Object.getPrototypeOf || function ( obj ) {
1590
return obj.__proto__;
1592
callbacks = (function () {
1594
// for string, boolean, number and null
1595
function useStrictEquality( b, a ) {
1596
/*jshint eqeqeq:false */
1597
if ( b instanceof a.constructor || a instanceof b.constructor ) {
1598
// to catch short annotaion VS 'new' annotation of a
1601
// var j = new Number(1);
1609
"string": useStrictEquality,
1610
"boolean": useStrictEquality,
1611
"number": useStrictEquality,
1612
"null": useStrictEquality,
1613
"undefined": useStrictEquality,
1615
"nan": function( b ) {
1619
"date": function( b, a ) {
1620
return QUnit.objectType( b ) === "date" && a.valueOf() === b.valueOf();
1623
"regexp": function( b, a ) {
1624
return QUnit.objectType( b ) === "regexp" &&
1626
a.source === b.source &&
1628
a.global === b.global &&
1630
a.ignoreCase === b.ignoreCase &&
1631
a.multiline === b.multiline &&
1632
a.sticky === b.sticky;
1635
// - skip when the property is a method of an instance (OOP)
1636
// - abort otherwise,
1637
// initial === would have catch identical references anyway
1638
"function": function() {
1639
var caller = callers[callers.length - 1];
1640
return caller !== Object && typeof caller !== "undefined";
1643
"array": function( b, a ) {
1644
var i, j, len, loop;
1646
// b could be an object literal here
1647
if ( QUnit.objectType( b ) !== "array" ) {
1652
if ( len !== b.length ) {
1657
// track reference to avoid circular references
1659
for ( i = 0; i < len; i++ ) {
1661
for ( j = 0; j < parents.length; j++ ) {
1662
if ( parents[j] === a[i] ) {
1663
loop = true;// dont rewalk array
1666
if ( !loop && !innerEquiv(a[i], b[i]) ) {
1675
"object": function( b, a ) {
1682
// comparing constructors is more strict than using
1684
if ( a.constructor !== b.constructor ) {
1685
// Allow objects with no prototype to be equivalent to
1686
// objects with Object as their constructor.
1687
if ( !(( getProto(a) === null && getProto(b) === Object.prototype ) ||
1688
( getProto(b) === null && getProto(a) === Object.prototype ) ) ) {
1693
// stack constructor before traversing properties
1694
callers.push( a.constructor );
1695
// track reference to avoid circular references
1698
for ( i in a ) { // be strict: don't ensures hasOwnProperty
1701
for ( j = 0; j < parents.length; j++ ) {
1702
if ( parents[j] === a[i] ) {
1703
// don't go down the same path twice
1707
aProperties.push(i); // collect a's properties
1709
if (!loop && !innerEquiv( a[i], b[i] ) ) {
1715
callers.pop(); // unstack, we are done
1719
bProperties.push( i ); // collect b's properties
1722
// Ensures identical properties name
1723
return eq && innerEquiv( aProperties.sort(), bProperties.sort() );
1728
innerEquiv = function() { // can take multiple arguments
1729
var args = [].slice.apply( arguments );
1730
if ( args.length < 2 ) {
1731
return true; // end transition
1734
return (function( a, b ) {
1736
return true; // catch the most you can
1737
} else if ( a === null || b === null || typeof a === "undefined" ||
1738
typeof b === "undefined" ||
1739
QUnit.objectType(a) !== QUnit.objectType(b) ) {
1740
return false; // don't lose time with error prone cases
1742
return bindCallbacks(a, callbacks, [ b, a ]);
1745
// apply transition with (1..n) arguments
1746
}( args[0], args[1] ) && arguments.callee.apply( this, args.splice(1, args.length - 1 )) );
1753
* jsDump Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com |
1754
* http://flesler.blogspot.com Licensed under BSD
1755
* (http://www.opensource.org/licenses/bsd-license.php) Date: 5/15/2008
1757
* @projectDescription Advanced and extensible data dumping for Javascript.
1759
* @author Ariel Flesler
1760
* @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html}
1762
QUnit.jsDump = (function() {
1763
function quote( str ) {
1764
return '"' + str.toString().replace( /"/g, '\\"' ) + '"';
1766
function literal( o ) {
1769
function join( pre, arr, post ) {
1770
var s = jsDump.separator(),
1771
base = jsDump.indent(),
1772
inner = jsDump.indent(1);
1774
arr = arr.join( "," + s + inner );
1779
return [ pre, inner + arr, base + post ].join(s);
1781
function array( arr, stack ) {
1782
var i = arr.length, ret = new Array(i);
1785
ret[i] = this.parse( arr[i] , undefined , stack);
1788
return join( "[", ret, "]" );
1791
var reName = /^function (\w+)/,
1793
// type is used mostly internally, you can fix a (custom)type in advance
1794
parse: function( obj, type, stack ) {
1795
stack = stack || [ ];
1797
parser = this.parsers[ type || this.typeOf(obj) ];
1799
type = typeof parser;
1800
inStack = inArray( obj, stack );
1802
if ( inStack !== -1 ) {
1803
return "recursion(" + (inStack - stack.length) + ")";
1805
if ( type === "function" ) {
1807
res = parser.call( this, obj, stack );
1811
return ( type === "string" ) ? parser : this.parsers.error;
1813
typeOf: function( obj ) {
1815
if ( obj === null ) {
1817
} else if ( typeof obj === "undefined" ) {
1819
} else if ( QUnit.is( "regexp", obj) ) {
1821
} else if ( QUnit.is( "date", obj) ) {
1823
} else if ( QUnit.is( "function", obj) ) {
1825
} else if ( typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined" ) {
1827
} else if ( obj.nodeType === 9 ) {
1829
} else if ( obj.nodeType ) {
1833
toString.call( obj ) === "[object Array]" ||
1835
( typeof obj.length === "number" && typeof obj.item !== "undefined" && ( obj.length ? obj.item(0) === obj[0] : ( obj.item( 0 ) === null && typeof obj[0] === "undefined" ) ) )
1838
} else if ( obj.constructor === Error.prototype.constructor ) {
1845
separator: function() {
1846
return this.multiline ? this.HTML ? "<br />" : "\n" : this.HTML ? " " : " ";
1848
// extra can be a number, shortcut for increasing-calling-decreasing
1849
indent: function( extra ) {
1850
if ( !this.multiline ) {
1853
var chr = this.indentChar;
1855
chr = chr.replace( /\t/g, " " ).replace( / /g, " " );
1857
return new Array( this._depth_ + (extra||0) ).join(chr);
1860
this._depth_ += a || 1;
1862
down: function( a ) {
1863
this._depth_ -= a || 1;
1865
setParser: function( name, parser ) {
1866
this.parsers[name] = parser;
1868
// The next 3 are exposed so you can use them
1874
// This is the list of parsers, to modify them, use jsDump.setParser
1877
document: "[Document]",
1878
error: function(error) {
1879
return "Error(\"" + error.message + "\")";
1881
unknown: "[Unknown]",
1883
"undefined": "undefined",
1884
"function": function( fn ) {
1885
var ret = "function",
1886
// functions never have name in IE
1887
name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1];
1894
ret = [ ret, QUnit.jsDump.parse( fn, "functionArgs" ), "){" ].join( "" );
1895
return join( ret, QUnit.jsDump.parse(fn,"functionCode" ), "}" );
1900
object: function( map, stack ) {
1901
var ret = [ ], keys, key, val, i;
1904
for ( key in map ) {
1908
for ( i = 0; i < keys.length; i++ ) {
1911
ret.push( QUnit.jsDump.parse( key, "key" ) + ": " + QUnit.jsDump.parse( val, undefined, stack ) );
1913
QUnit.jsDump.down();
1914
return join( "{", ret, "}" );
1916
node: function( node ) {
1918
open = QUnit.jsDump.HTML ? "<" : "<",
1919
close = QUnit.jsDump.HTML ? ">" : ">",
1920
tag = node.nodeName.toLowerCase(),
1922
attrs = node.attributes;
1925
for ( i = 0, len = attrs.length; i < len; i++ ) {
1926
val = attrs[i].nodeValue;
1927
// IE6 includes all attributes in .attributes, even ones not explicitly set.
1928
// Those have values like undefined, null, 0, false, "" or "inherit".
1929
if ( val && val !== "inherit" ) {
1930
ret += " " + attrs[i].nodeName + "=" + QUnit.jsDump.parse( val, "attribute" );
1936
// Show content of TextNode or CDATASection
1937
if ( node.nodeType === 3 || node.nodeType === 4 ) {
1938
ret += node.nodeValue;
1941
return ret + open + "/" + tag + close;
1943
// function calls it internally, it's the arguments part of the function
1944
functionArgs: function( fn ) {
1952
args = new Array(l);
1955
args[l] = String.fromCharCode(97+l);
1957
return " " + args.join( ", " ) + " ";
1959
// object calls it internally, the key part of an item in a map
1961
// function calls it internally, it's the content of the function
1962
functionCode: "[code]",
1963
// node calls it internally, it's an html attribute value
1971
// if true, entities are escaped ( <, >, \t, space and \n )
1975
// if true, items in a collection, are separated by a \n, else just a space.
1983
function inArray( elem, array ) {
1984
if ( array.indexOf ) {
1985
return array.indexOf( elem );
1988
for ( var i = 0, length = array.length; i < length; i++ ) {
1989
if ( array[ i ] === elem ) {
1998
* Javascript Diff Algorithm
1999
* By John Resig (http://ejohn.org/)
2000
* Modified by Chu Alan "sprite"
2002
* Released under the MIT license.
2005
* http://ejohn.org/projects/javascript-diff-algorithm/
2007
* Usage: QUnit.diff(expected, actual)
2009
* 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"
2011
QUnit.diff = (function() {
2012
/*jshint eqeqeq:false, eqnull:true */
2013
function diff( o, n ) {
2018
for ( i = 0; i < n.length; i++ ) {
2019
if ( !hasOwn.call( ns, n[i] ) ) {
2025
ns[ n[i] ].rows.push( i );
2028
for ( i = 0; i < o.length; i++ ) {
2029
if ( !hasOwn.call( os, o[i] ) ) {
2035
os[ o[i] ].rows.push( i );
2039
if ( !hasOwn.call( ns, i ) ) {
2042
if ( ns[i].rows.length === 1 && hasOwn.call( os, i ) && os[i].rows.length === 1 ) {
2043
n[ ns[i].rows[0] ] = {
2044
text: n[ ns[i].rows[0] ],
2047
o[ os[i].rows[0] ] = {
2048
text: o[ os[i].rows[0] ],
2054
for ( i = 0; i < n.length - 1; i++ ) {
2055
if ( n[i].text != null && n[ i + 1 ].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null &&
2056
n[ i + 1 ] == o[ n[i].row + 1 ] ) {
2062
o[ n[i].row + 1 ] = {
2063
text: o[ n[i].row + 1 ],
2069
for ( i = n.length - 1; i > 0; i-- ) {
2070
if ( n[i].text != null && n[ i - 1 ].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null &&
2071
n[ i - 1 ] == o[ n[i].row - 1 ]) {
2077
o[ n[i].row - 1 ] = {
2078
text: o[ n[i].row - 1 ],
2090
return function( o, n ) {
2091
o = o.replace( /\s+$/, "" );
2092
n = n.replace( /\s+$/, "" );
2096
out = diff( o === "" ? [] : o.split(/\s+/), n === "" ? [] : n.split(/\s+/) ),
2097
oSpace = o.match(/\s+/g),
2098
nSpace = n.match(/\s+/g);
2100
if ( oSpace == null ) {
2107
if ( nSpace == null ) {
2114
if ( out.n.length === 0 ) {
2115
for ( i = 0; i < out.o.length; i++ ) {
2116
str += "<del>" + out.o[i] + oSpace[i] + "</del>";
2120
if ( out.n[0].text == null ) {
2121
for ( n = 0; n < out.o.length && out.o[n].text == null; n++ ) {
2122
str += "<del>" + out.o[n] + oSpace[n] + "</del>";
2126
for ( i = 0; i < out.n.length; i++ ) {
2127
if (out.n[i].text == null) {
2128
str += "<ins>" + out.n[i] + nSpace[i] + "</ins>";
2131
// `pre` initialized at top of scope
2134
for ( n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) {
2135
pre += "<del>" + out.o[n] + oSpace[n] + "</del>";
2137
str += " " + out.n[i].text + nSpace[i] + pre;
2146
// for CommonJS enviroments, export everything
2147
if ( typeof exports !== "undefined" ) {
2148
extend( exports, QUnit );
2151
// get at whatever the global object is, like window in browsers
2152
}( (function() {return this;}.call()) ));