teaspoon-qunit 1.19.0 → 1.20.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80ab369d873e91647999e166230e7faae6b04e13
4
- data.tar.gz: 10273fd125eb92e90e66837f28b35c3665e74441
3
+ metadata.gz: 18ff28f3c935b63442cf52329afa2f0e785eb3d6
4
+ data.tar.gz: b85414b81e292ba39a465433d47af8cf438e64d3
5
5
  SHA512:
6
- metadata.gz: 8730f26d75b64a68de98ed2e2d4a059a93ce9eaf14461516b981422cadc4d53f2d7e7546a5f7ab9dfa5dec2a310524714d7b2bf85d542cf076ab568d97e80935
7
- data.tar.gz: f1566bf08429beb1d3c6f1113f355bc7c4c1eb673f43bd5024496566f6c6abc01681041e5471efcbdbd36fab8f21ff31273313fb7b3d78b6a3252143d9381adb
6
+ metadata.gz: 3929ca919d85faa588014def92ba363d9dfec1cfd2f22b5008f34662964b37792df7fcea72b795099d391bcce5f75a1c0100331dd265d23e818d548259b26e59
7
+ data.tar.gz: 568b06198c1d051018ee6200c4ec41d43ae8cdc070c30490c287fed26be797b0d376a5784a1073617b175e9d8d98a69566ac12f919469a09a2cacc3638178309
@@ -0,0 +1,4158 @@
1
+ /*!
2
+ * QUnit 1.20.0
3
+ * http://qunitjs.com/
4
+ *
5
+ * Copyright jQuery Foundation and other contributors
6
+ * Released under the MIT license
7
+ * http://jquery.org/license
8
+ *
9
+ * Date: 2015-10-27T17:53Z
10
+ */
11
+
12
+ (function( global ) {
13
+
14
+ var QUnit = {};
15
+
16
+ var Date = global.Date;
17
+ var now = Date.now || function() {
18
+ return new Date().getTime();
19
+ };
20
+
21
+ var setTimeout = global.setTimeout;
22
+ var clearTimeout = global.clearTimeout;
23
+
24
+ // Store a local window from the global to allow direct references.
25
+ var window = global.window;
26
+
27
+ var defined = {
28
+ document: window && window.document !== undefined,
29
+ setTimeout: setTimeout !== undefined,
30
+ sessionStorage: (function() {
31
+ var x = "qunit-test-string";
32
+ try {
33
+ sessionStorage.setItem( x, x );
34
+ sessionStorage.removeItem( x );
35
+ return true;
36
+ } catch ( e ) {
37
+ return false;
38
+ }
39
+ }() )
40
+ };
41
+
42
+ var fileName = ( sourceFromStacktrace( 0 ) || "" ).replace( /(:\d+)+\)?/, "" ).replace( /.+\//, "" );
43
+ var globalStartCalled = false;
44
+ var runStarted = false;
45
+
46
+ var toString = Object.prototype.toString,
47
+ hasOwn = Object.prototype.hasOwnProperty;
48
+
49
+ // returns a new Array with the elements that are in a but not in b
50
+ function diff( a, b ) {
51
+ var i, j,
52
+ result = a.slice();
53
+
54
+ for ( i = 0; i < result.length; i++ ) {
55
+ for ( j = 0; j < b.length; j++ ) {
56
+ if ( result[ i ] === b[ j ] ) {
57
+ result.splice( i, 1 );
58
+ i--;
59
+ break;
60
+ }
61
+ }
62
+ }
63
+ return result;
64
+ }
65
+
66
+ // from jquery.js
67
+ function inArray( elem, array ) {
68
+ if ( array.indexOf ) {
69
+ return array.indexOf( elem );
70
+ }
71
+
72
+ for ( var i = 0, length = array.length; i < length; i++ ) {
73
+ if ( array[ i ] === elem ) {
74
+ return i;
75
+ }
76
+ }
77
+
78
+ return -1;
79
+ }
80
+
81
+ /**
82
+ * Makes a clone of an object using only Array or Object as base,
83
+ * and copies over the own enumerable properties.
84
+ *
85
+ * @param {Object} obj
86
+ * @return {Object} New object with only the own properties (recursively).
87
+ */
88
+ function objectValues ( obj ) {
89
+ var key, val,
90
+ vals = QUnit.is( "array", obj ) ? [] : {};
91
+ for ( key in obj ) {
92
+ if ( hasOwn.call( obj, key ) ) {
93
+ val = obj[ key ];
94
+ vals[ key ] = val === Object( val ) ? objectValues( val ) : val;
95
+ }
96
+ }
97
+ return vals;
98
+ }
99
+
100
+ function extend( a, b, undefOnly ) {
101
+ for ( var prop in b ) {
102
+ if ( hasOwn.call( b, prop ) ) {
103
+
104
+ // Avoid "Member not found" error in IE8 caused by messing with window.constructor
105
+ // This block runs on every environment, so `global` is being used instead of `window`
106
+ // to avoid errors on node.
107
+ if ( prop !== "constructor" || a !== global ) {
108
+ if ( b[ prop ] === undefined ) {
109
+ delete a[ prop ];
110
+ } else if ( !( undefOnly && typeof a[ prop ] !== "undefined" ) ) {
111
+ a[ prop ] = b[ prop ];
112
+ }
113
+ }
114
+ }
115
+ }
116
+
117
+ return a;
118
+ }
119
+
120
+ function objectType( obj ) {
121
+ if ( typeof obj === "undefined" ) {
122
+ return "undefined";
123
+ }
124
+
125
+ // Consider: typeof null === object
126
+ if ( obj === null ) {
127
+ return "null";
128
+ }
129
+
130
+ var match = toString.call( obj ).match( /^\[object\s(.*)\]$/ ),
131
+ type = match && match[ 1 ];
132
+
133
+ switch ( type ) {
134
+ case "Number":
135
+ if ( isNaN( obj ) ) {
136
+ return "nan";
137
+ }
138
+ return "number";
139
+ case "String":
140
+ case "Boolean":
141
+ case "Array":
142
+ case "Set":
143
+ case "Map":
144
+ case "Date":
145
+ case "RegExp":
146
+ case "Function":
147
+ case "Symbol":
148
+ return type.toLowerCase();
149
+ }
150
+ if ( typeof obj === "object" ) {
151
+ return "object";
152
+ }
153
+ }
154
+
155
+ // Safe object type checking
156
+ function is( type, obj ) {
157
+ return QUnit.objectType( obj ) === type;
158
+ }
159
+
160
+ var getUrlParams = function() {
161
+ var i, current;
162
+ var urlParams = {};
163
+ var location = window.location;
164
+ var params = location.search.slice( 1 ).split( "&" );
165
+ var length = params.length;
166
+
167
+ if ( params[ 0 ] ) {
168
+ for ( i = 0; i < length; i++ ) {
169
+ current = params[ i ].split( "=" );
170
+ current[ 0 ] = decodeURIComponent( current[ 0 ] );
171
+
172
+ // allow just a key to turn on a flag, e.g., test.html?noglobals
173
+ current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true;
174
+ if ( urlParams[ current[ 0 ] ] ) {
175
+ urlParams[ current[ 0 ] ] = [].concat( urlParams[ current[ 0 ] ], current[ 1 ] );
176
+ } else {
177
+ urlParams[ current[ 0 ] ] = current[ 1 ];
178
+ }
179
+ }
180
+ }
181
+
182
+ return urlParams;
183
+ };
184
+
185
+ // Doesn't support IE6 to IE9, it will return undefined on these browsers
186
+ // See also https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack
187
+ function extractStacktrace( e, offset ) {
188
+ offset = offset === undefined ? 4 : offset;
189
+
190
+ var stack, include, i;
191
+
192
+ if ( e.stack ) {
193
+ stack = e.stack.split( "\n" );
194
+ if ( /^error$/i.test( stack[ 0 ] ) ) {
195
+ stack.shift();
196
+ }
197
+ if ( fileName ) {
198
+ include = [];
199
+ for ( i = offset; i < stack.length; i++ ) {
200
+ if ( stack[ i ].indexOf( fileName ) !== -1 ) {
201
+ break;
202
+ }
203
+ include.push( stack[ i ] );
204
+ }
205
+ if ( include.length ) {
206
+ return include.join( "\n" );
207
+ }
208
+ }
209
+ return stack[ offset ];
210
+
211
+ // Support: Safari <=6 only
212
+ } else if ( e.sourceURL ) {
213
+
214
+ // exclude useless self-reference for generated Error objects
215
+ if ( /qunit.js$/.test( e.sourceURL ) ) {
216
+ return;
217
+ }
218
+
219
+ // for actual exceptions, this is useful
220
+ return e.sourceURL + ":" + e.line;
221
+ }
222
+ }
223
+
224
+ function sourceFromStacktrace( offset ) {
225
+ var error = new Error();
226
+
227
+ // Support: Safari <=7 only, IE <=10 - 11 only
228
+ // Not all browsers generate the `stack` property for `new Error()`, see also #636
229
+ if ( !error.stack ) {
230
+ try {
231
+ throw error;
232
+ } catch ( err ) {
233
+ error = err;
234
+ }
235
+ }
236
+
237
+ return extractStacktrace( error, offset );
238
+ }
239
+
240
+ /**
241
+ * Config object: Maintain internal state
242
+ * Later exposed as QUnit.config
243
+ * `config` initialized at top of scope
244
+ */
245
+ var config = {
246
+ // The queue of tests to run
247
+ queue: [],
248
+
249
+ // block until document ready
250
+ blocking: true,
251
+
252
+ // by default, run previously failed tests first
253
+ // very useful in combination with "Hide passed tests" checked
254
+ reorder: true,
255
+
256
+ // by default, modify document.title when suite is done
257
+ altertitle: true,
258
+
259
+ // HTML Reporter: collapse every test except the first failing test
260
+ // If false, all failing tests will be expanded
261
+ collapse: true,
262
+
263
+ // by default, scroll to top of the page when suite is done
264
+ scrolltop: true,
265
+
266
+ // depth up-to which object will be dumped
267
+ maxDepth: 5,
268
+
269
+ // when enabled, all tests must call expect()
270
+ requireExpects: false,
271
+
272
+ // add checkboxes that are persisted in the query-string
273
+ // when enabled, the id is set to `true` as a `QUnit.config` property
274
+ urlConfig: [
275
+ {
276
+ id: "hidepassed",
277
+ label: "Hide passed tests",
278
+ tooltip: "Only show tests and assertions that fail. Stored as query-strings."
279
+ },
280
+ {
281
+ id: "noglobals",
282
+ label: "Check for Globals",
283
+ tooltip: "Enabling this will test if any test introduces new properties on the " +
284
+ "global object (`window` in Browsers). Stored as query-strings."
285
+ },
286
+ {
287
+ id: "notrycatch",
288
+ label: "No try-catch",
289
+ tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging " +
290
+ "exceptions in IE reasonable. Stored as query-strings."
291
+ }
292
+ ],
293
+
294
+ // Set of all modules.
295
+ modules: [],
296
+
297
+ // Stack of nested modules
298
+ moduleStack: [],
299
+
300
+ // The first unnamed module
301
+ currentModule: {
302
+ name: "",
303
+ tests: []
304
+ },
305
+
306
+ callbacks: {}
307
+ };
308
+
309
+ var urlParams = defined.document ? getUrlParams() : {};
310
+
311
+ // Push a loose unnamed module to the modules collection
312
+ config.modules.push( config.currentModule );
313
+
314
+ if ( urlParams.filter === true ) {
315
+ delete urlParams.filter;
316
+ }
317
+
318
+ // String search anywhere in moduleName+testName
319
+ config.filter = urlParams.filter;
320
+
321
+ config.testId = [];
322
+ if ( urlParams.testId ) {
323
+ // Ensure that urlParams.testId is an array
324
+ urlParams.testId = decodeURIComponent( urlParams.testId ).split( "," );
325
+ for (var i = 0; i < urlParams.testId.length; i++ ) {
326
+ config.testId.push( urlParams.testId[ i ] );
327
+ }
328
+ }
329
+
330
+ var loggingCallbacks = {};
331
+
332
+ // Register logging callbacks
333
+ function registerLoggingCallbacks( obj ) {
334
+ var i, l, key,
335
+ callbackNames = [ "begin", "done", "log", "testStart", "testDone",
336
+ "moduleStart", "moduleDone" ];
337
+
338
+ function registerLoggingCallback( key ) {
339
+ var loggingCallback = function( callback ) {
340
+ if ( objectType( callback ) !== "function" ) {
341
+ throw new Error(
342
+ "QUnit logging methods require a callback function as their first parameters."
343
+ );
344
+ }
345
+
346
+ config.callbacks[ key ].push( callback );
347
+ };
348
+
349
+ // DEPRECATED: This will be removed on QUnit 2.0.0+
350
+ // Stores the registered functions allowing restoring
351
+ // at verifyLoggingCallbacks() if modified
352
+ loggingCallbacks[ key ] = loggingCallback;
353
+
354
+ return loggingCallback;
355
+ }
356
+
357
+ for ( i = 0, l = callbackNames.length; i < l; i++ ) {
358
+ key = callbackNames[ i ];
359
+
360
+ // Initialize key collection of logging callback
361
+ if ( objectType( config.callbacks[ key ] ) === "undefined" ) {
362
+ config.callbacks[ key ] = [];
363
+ }
364
+
365
+ obj[ key ] = registerLoggingCallback( key );
366
+ }
367
+ }
368
+
369
+ function runLoggingCallbacks( key, args ) {
370
+ var i, l, callbacks;
371
+
372
+ callbacks = config.callbacks[ key ];
373
+ for ( i = 0, l = callbacks.length; i < l; i++ ) {
374
+ callbacks[ i ]( args );
375
+ }
376
+ }
377
+
378
+ // DEPRECATED: This will be removed on 2.0.0+
379
+ // This function verifies if the loggingCallbacks were modified by the user
380
+ // If so, it will restore it, assign the given callback and print a console warning
381
+ function verifyLoggingCallbacks() {
382
+ var loggingCallback, userCallback;
383
+
384
+ for ( loggingCallback in loggingCallbacks ) {
385
+ if ( QUnit[ loggingCallback ] !== loggingCallbacks[ loggingCallback ] ) {
386
+
387
+ userCallback = QUnit[ loggingCallback ];
388
+
389
+ // Restore the callback function
390
+ QUnit[ loggingCallback ] = loggingCallbacks[ loggingCallback ];
391
+
392
+ // Assign the deprecated given callback
393
+ QUnit[ loggingCallback ]( userCallback );
394
+
395
+ if ( global.console && global.console.warn ) {
396
+ global.console.warn(
397
+ "QUnit." + loggingCallback + " was replaced with a new value.\n" +
398
+ "Please, check out the documentation on how to apply logging callbacks.\n" +
399
+ "Reference: http://api.qunitjs.com/category/callbacks/"
400
+ );
401
+ }
402
+ }
403
+ }
404
+ }
405
+
406
+ ( function() {
407
+ if ( !defined.document ) {
408
+ return;
409
+ }
410
+
411
+ // `onErrorFnPrev` initialized at top of scope
412
+ // Preserve other handlers
413
+ var onErrorFnPrev = window.onerror;
414
+
415
+ // Cover uncaught exceptions
416
+ // Returning true will suppress the default browser handler,
417
+ // returning false will let it run.
418
+ window.onerror = function( error, filePath, linerNr ) {
419
+ var ret = false;
420
+ if ( onErrorFnPrev ) {
421
+ ret = onErrorFnPrev( error, filePath, linerNr );
422
+ }
423
+
424
+ // Treat return value as window.onerror itself does,
425
+ // Only do our handling if not suppressed.
426
+ if ( ret !== true ) {
427
+ if ( QUnit.config.current ) {
428
+ if ( QUnit.config.current.ignoreGlobalErrors ) {
429
+ return true;
430
+ }
431
+ QUnit.pushFailure( error, filePath + ":" + linerNr );
432
+ } else {
433
+ QUnit.test( "global failure", extend(function() {
434
+ QUnit.pushFailure( error, filePath + ":" + linerNr );
435
+ }, { validTest: true } ) );
436
+ }
437
+ return false;
438
+ }
439
+
440
+ return ret;
441
+ };
442
+ } )();
443
+
444
+ QUnit.urlParams = urlParams;
445
+
446
+ // Figure out if we're running the tests from a server or not
447
+ QUnit.isLocal = !( defined.document && window.location.protocol !== "file:" );
448
+
449
+ // Expose the current QUnit version
450
+ QUnit.version = "1.20.0";
451
+
452
+ extend( QUnit, {
453
+
454
+ // call on start of module test to prepend name to all tests
455
+ module: function( name, testEnvironment, executeNow ) {
456
+ var module, moduleFns;
457
+ var currentModule = config.currentModule;
458
+
459
+ if ( arguments.length === 2 ) {
460
+ if ( testEnvironment instanceof Function ) {
461
+ executeNow = testEnvironment;
462
+ testEnvironment = undefined;
463
+ }
464
+ }
465
+
466
+ // DEPRECATED: handles setup/teardown functions,
467
+ // beforeEach and afterEach should be used instead
468
+ if ( testEnvironment && testEnvironment.setup ) {
469
+ testEnvironment.beforeEach = testEnvironment.setup;
470
+ delete testEnvironment.setup;
471
+ }
472
+ if ( testEnvironment && testEnvironment.teardown ) {
473
+ testEnvironment.afterEach = testEnvironment.teardown;
474
+ delete testEnvironment.teardown;
475
+ }
476
+
477
+ module = createModule();
478
+
479
+ moduleFns = {
480
+ beforeEach: setHook( module, "beforeEach" ),
481
+ afterEach: setHook( module, "afterEach" )
482
+ };
483
+
484
+ if ( executeNow instanceof Function ) {
485
+ config.moduleStack.push( module );
486
+ setCurrentModule( module );
487
+ executeNow.call( module.testEnvironment, moduleFns );
488
+ config.moduleStack.pop();
489
+ module = module.parentModule || currentModule;
490
+ }
491
+
492
+ setCurrentModule( module );
493
+
494
+ function createModule() {
495
+ var parentModule = config.moduleStack.length ?
496
+ config.moduleStack.slice( -1 )[ 0 ] : null;
497
+ var moduleName = parentModule !== null ?
498
+ [ parentModule.name, name ].join( " > " ) : name;
499
+ var module = {
500
+ name: moduleName,
501
+ parentModule: parentModule,
502
+ tests: []
503
+ };
504
+
505
+ var env = {};
506
+ if ( parentModule ) {
507
+ extend( env, parentModule.testEnvironment );
508
+ delete env.beforeEach;
509
+ delete env.afterEach;
510
+ }
511
+ extend( env, testEnvironment );
512
+ module.testEnvironment = env;
513
+
514
+ config.modules.push( module );
515
+ return module;
516
+ }
517
+
518
+ function setCurrentModule( module ) {
519
+ config.currentModule = module;
520
+ }
521
+
522
+ },
523
+
524
+ // DEPRECATED: QUnit.asyncTest() will be removed in QUnit 2.0.
525
+ asyncTest: asyncTest,
526
+
527
+ test: test,
528
+
529
+ skip: skip,
530
+
531
+ only: only,
532
+
533
+ // DEPRECATED: The functionality of QUnit.start() will be altered in QUnit 2.0.
534
+ // In QUnit 2.0, invoking it will ONLY affect the `QUnit.config.autostart` blocking behavior.
535
+ start: function( count ) {
536
+ var globalStartAlreadyCalled = globalStartCalled;
537
+
538
+ if ( !config.current ) {
539
+ globalStartCalled = true;
540
+
541
+ if ( runStarted ) {
542
+ throw new Error( "Called start() outside of a test context while already started" );
543
+ } else if ( globalStartAlreadyCalled || count > 1 ) {
544
+ throw new Error( "Called start() outside of a test context too many times" );
545
+ } else if ( config.autostart ) {
546
+ throw new Error( "Called start() outside of a test context when " +
547
+ "QUnit.config.autostart was true" );
548
+ } else if ( !config.pageLoaded ) {
549
+
550
+ // The page isn't completely loaded yet, so bail out and let `QUnit.load` handle it
551
+ config.autostart = true;
552
+ return;
553
+ }
554
+ } else {
555
+
556
+ // If a test is running, adjust its semaphore
557
+ config.current.semaphore -= count || 1;
558
+
559
+ // If semaphore is non-numeric, throw error
560
+ if ( isNaN( config.current.semaphore ) ) {
561
+ config.current.semaphore = 0;
562
+
563
+ QUnit.pushFailure(
564
+ "Called start() with a non-numeric decrement.",
565
+ sourceFromStacktrace( 2 )
566
+ );
567
+ return;
568
+ }
569
+
570
+ // Don't start until equal number of stop-calls
571
+ if ( config.current.semaphore > 0 ) {
572
+ return;
573
+ }
574
+
575
+ // throw an Error if start is called more often than stop
576
+ if ( config.current.semaphore < 0 ) {
577
+ config.current.semaphore = 0;
578
+
579
+ QUnit.pushFailure(
580
+ "Called start() while already started (test's semaphore was 0 already)",
581
+ sourceFromStacktrace( 2 )
582
+ );
583
+ return;
584
+ }
585
+ }
586
+
587
+ resumeProcessing();
588
+ },
589
+
590
+ // DEPRECATED: QUnit.stop() will be removed in QUnit 2.0.
591
+ stop: function( count ) {
592
+
593
+ // If there isn't a test running, don't allow QUnit.stop() to be called
594
+ if ( !config.current ) {
595
+ throw new Error( "Called stop() outside of a test context" );
596
+ }
597
+
598
+ // If a test is running, adjust its semaphore
599
+ config.current.semaphore += count || 1;
600
+
601
+ pauseProcessing();
602
+ },
603
+
604
+ config: config,
605
+
606
+ is: is,
607
+
608
+ objectType: objectType,
609
+
610
+ extend: extend,
611
+
612
+ load: function() {
613
+ config.pageLoaded = true;
614
+
615
+ // Initialize the configuration options
616
+ extend( config, {
617
+ stats: { all: 0, bad: 0 },
618
+ moduleStats: { all: 0, bad: 0 },
619
+ started: 0,
620
+ updateRate: 1000,
621
+ autostart: true,
622
+ filter: ""
623
+ }, true );
624
+
625
+ config.blocking = false;
626
+
627
+ if ( config.autostart ) {
628
+ resumeProcessing();
629
+ }
630
+ },
631
+
632
+ stack: function( offset ) {
633
+ offset = ( offset || 0 ) + 2;
634
+ return sourceFromStacktrace( offset );
635
+ }
636
+ });
637
+
638
+ registerLoggingCallbacks( QUnit );
639
+
640
+ function begin() {
641
+ var i, l,
642
+ modulesLog = [];
643
+
644
+ // If the test run hasn't officially begun yet
645
+ if ( !config.started ) {
646
+
647
+ // Record the time of the test run's beginning
648
+ config.started = now();
649
+
650
+ verifyLoggingCallbacks();
651
+
652
+ // Delete the loose unnamed module if unused.
653
+ if ( config.modules[ 0 ].name === "" && config.modules[ 0 ].tests.length === 0 ) {
654
+ config.modules.shift();
655
+ }
656
+
657
+ // Avoid unnecessary information by not logging modules' test environments
658
+ for ( i = 0, l = config.modules.length; i < l; i++ ) {
659
+ modulesLog.push({
660
+ name: config.modules[ i ].name,
661
+ tests: config.modules[ i ].tests
662
+ });
663
+ }
664
+
665
+ // The test run is officially beginning now
666
+ runLoggingCallbacks( "begin", {
667
+ totalTests: Test.count,
668
+ modules: modulesLog
669
+ });
670
+ }
671
+
672
+ config.blocking = false;
673
+ process( true );
674
+ }
675
+
676
+ function process( last ) {
677
+ function next() {
678
+ process( last );
679
+ }
680
+ var start = now();
681
+ config.depth = ( config.depth || 0 ) + 1;
682
+
683
+ while ( config.queue.length && !config.blocking ) {
684
+ if ( !defined.setTimeout || config.updateRate <= 0 ||
685
+ ( ( now() - start ) < config.updateRate ) ) {
686
+ if ( config.current ) {
687
+
688
+ // Reset async tracking for each phase of the Test lifecycle
689
+ config.current.usedAsync = false;
690
+ }
691
+ config.queue.shift()();
692
+ } else {
693
+ setTimeout( next, 13 );
694
+ break;
695
+ }
696
+ }
697
+ config.depth--;
698
+ if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) {
699
+ done();
700
+ }
701
+ }
702
+
703
+ function pauseProcessing() {
704
+ config.blocking = true;
705
+
706
+ if ( config.testTimeout && defined.setTimeout ) {
707
+ clearTimeout( config.timeout );
708
+ config.timeout = setTimeout(function() {
709
+ if ( config.current ) {
710
+ config.current.semaphore = 0;
711
+ QUnit.pushFailure( "Test timed out", sourceFromStacktrace( 2 ) );
712
+ } else {
713
+ throw new Error( "Test timed out" );
714
+ }
715
+ resumeProcessing();
716
+ }, config.testTimeout );
717
+ }
718
+ }
719
+
720
+ function resumeProcessing() {
721
+ runStarted = true;
722
+
723
+ // A slight delay to allow this iteration of the event loop to finish (more assertions, etc.)
724
+ if ( defined.setTimeout ) {
725
+ setTimeout(function() {
726
+ if ( config.current && config.current.semaphore > 0 ) {
727
+ return;
728
+ }
729
+ if ( config.timeout ) {
730
+ clearTimeout( config.timeout );
731
+ }
732
+
733
+ begin();
734
+ }, 13 );
735
+ } else {
736
+ begin();
737
+ }
738
+ }
739
+
740
+ function done() {
741
+ var runtime, passed;
742
+
743
+ config.autorun = true;
744
+
745
+ // Log the last module results
746
+ if ( config.previousModule ) {
747
+ runLoggingCallbacks( "moduleDone", {
748
+ name: config.previousModule.name,
749
+ tests: config.previousModule.tests,
750
+ failed: config.moduleStats.bad,
751
+ passed: config.moduleStats.all - config.moduleStats.bad,
752
+ total: config.moduleStats.all,
753
+ runtime: now() - config.moduleStats.started
754
+ });
755
+ }
756
+ delete config.previousModule;
757
+
758
+ runtime = now() - config.started;
759
+ passed = config.stats.all - config.stats.bad;
760
+
761
+ runLoggingCallbacks( "done", {
762
+ failed: config.stats.bad,
763
+ passed: passed,
764
+ total: config.stats.all,
765
+ runtime: runtime
766
+ });
767
+ }
768
+
769
+ function setHook( module, hookName ) {
770
+ if ( module.testEnvironment === undefined ) {
771
+ module.testEnvironment = {};
772
+ }
773
+
774
+ return function( callback ) {
775
+ module.testEnvironment[ hookName ] = callback;
776
+ };
777
+ }
778
+
779
+ var focused = false;
780
+
781
+ function Test( settings ) {
782
+ var i, l;
783
+
784
+ ++Test.count;
785
+
786
+ extend( this, settings );
787
+ this.assertions = [];
788
+ this.semaphore = 0;
789
+ this.usedAsync = false;
790
+ this.module = config.currentModule;
791
+ this.stack = sourceFromStacktrace( 3 );
792
+
793
+ // Register unique strings
794
+ for ( i = 0, l = this.module.tests; i < l.length; i++ ) {
795
+ if ( this.module.tests[ i ].name === this.testName ) {
796
+ this.testName += " ";
797
+ }
798
+ }
799
+
800
+ this.testId = generateHash( this.module.name, this.testName );
801
+
802
+ this.module.tests.push({
803
+ name: this.testName,
804
+ testId: this.testId
805
+ });
806
+
807
+ if ( settings.skip ) {
808
+
809
+ // Skipped tests will fully ignore any sent callback
810
+ this.callback = function() {};
811
+ this.async = false;
812
+ this.expected = 0;
813
+ } else {
814
+ this.assert = new Assert( this );
815
+ }
816
+ }
817
+
818
+ Test.count = 0;
819
+
820
+ Test.prototype = {
821
+ before: function() {
822
+ if (
823
+
824
+ // Emit moduleStart when we're switching from one module to another
825
+ this.module !== config.previousModule ||
826
+
827
+ // They could be equal (both undefined) but if the previousModule property doesn't
828
+ // yet exist it means this is the first test in a suite that isn't wrapped in a
829
+ // module, in which case we'll just emit a moduleStart event for 'undefined'.
830
+ // Without this, reporters can get testStart before moduleStart which is a problem.
831
+ !hasOwn.call( config, "previousModule" )
832
+ ) {
833
+ if ( hasOwn.call( config, "previousModule" ) ) {
834
+ runLoggingCallbacks( "moduleDone", {
835
+ name: config.previousModule.name,
836
+ tests: config.previousModule.tests,
837
+ failed: config.moduleStats.bad,
838
+ passed: config.moduleStats.all - config.moduleStats.bad,
839
+ total: config.moduleStats.all,
840
+ runtime: now() - config.moduleStats.started
841
+ });
842
+ }
843
+ config.previousModule = this.module;
844
+ config.moduleStats = { all: 0, bad: 0, started: now() };
845
+ runLoggingCallbacks( "moduleStart", {
846
+ name: this.module.name,
847
+ tests: this.module.tests
848
+ });
849
+ }
850
+
851
+ config.current = this;
852
+
853
+ if ( this.module.testEnvironment ) {
854
+ delete this.module.testEnvironment.beforeEach;
855
+ delete this.module.testEnvironment.afterEach;
856
+ }
857
+ this.testEnvironment = extend( {}, this.module.testEnvironment );
858
+
859
+ this.started = now();
860
+ runLoggingCallbacks( "testStart", {
861
+ name: this.testName,
862
+ module: this.module.name,
863
+ testId: this.testId
864
+ });
865
+
866
+ if ( !config.pollution ) {
867
+ saveGlobal();
868
+ }
869
+ },
870
+
871
+ run: function() {
872
+ var promise;
873
+
874
+ config.current = this;
875
+
876
+ if ( this.async ) {
877
+ QUnit.stop();
878
+ }
879
+
880
+ this.callbackStarted = now();
881
+
882
+ if ( config.notrycatch ) {
883
+ runTest( this );
884
+ return;
885
+ }
886
+
887
+ try {
888
+ runTest( this );
889
+ } catch ( e ) {
890
+ this.pushFailure( "Died on test #" + ( this.assertions.length + 1 ) + " " +
891
+ this.stack + ": " + ( e.message || e ), extractStacktrace( e, 0 ) );
892
+
893
+ // else next test will carry the responsibility
894
+ saveGlobal();
895
+
896
+ // Restart the tests if they're blocking
897
+ if ( config.blocking ) {
898
+ QUnit.start();
899
+ }
900
+ }
901
+
902
+ function runTest( test ) {
903
+ promise = test.callback.call( test.testEnvironment, test.assert );
904
+ test.resolvePromise( promise );
905
+ }
906
+ },
907
+
908
+ after: function() {
909
+ checkPollution();
910
+ },
911
+
912
+ queueHook: function( hook, hookName ) {
913
+ var promise,
914
+ test = this;
915
+ return function runHook() {
916
+ config.current = test;
917
+ if ( config.notrycatch ) {
918
+ callHook();
919
+ return;
920
+ }
921
+ try {
922
+ callHook();
923
+ } catch ( error ) {
924
+ test.pushFailure( hookName + " failed on " + test.testName + ": " +
925
+ ( error.message || error ), extractStacktrace( error, 0 ) );
926
+ }
927
+
928
+ function callHook() {
929
+ promise = hook.call( test.testEnvironment, test.assert );
930
+ test.resolvePromise( promise, hookName );
931
+ }
932
+ };
933
+ },
934
+
935
+ // Currently only used for module level hooks, can be used to add global level ones
936
+ hooks: function( handler ) {
937
+ var hooks = [];
938
+
939
+ function processHooks( test, module ) {
940
+ if ( module.parentModule ) {
941
+ processHooks( test, module.parentModule );
942
+ }
943
+ if ( module.testEnvironment &&
944
+ QUnit.objectType( module.testEnvironment[ handler ] ) === "function" ) {
945
+ hooks.push( test.queueHook( module.testEnvironment[ handler ], handler ) );
946
+ }
947
+ }
948
+
949
+ // Hooks are ignored on skipped tests
950
+ if ( !this.skip ) {
951
+ processHooks( this, this.module );
952
+ }
953
+ return hooks;
954
+ },
955
+
956
+ finish: function() {
957
+ config.current = this;
958
+ if ( config.requireExpects && this.expected === null ) {
959
+ this.pushFailure( "Expected number of assertions to be defined, but expect() was " +
960
+ "not called.", this.stack );
961
+ } else if ( this.expected !== null && this.expected !== this.assertions.length ) {
962
+ this.pushFailure( "Expected " + this.expected + " assertions, but " +
963
+ this.assertions.length + " were run", this.stack );
964
+ } else if ( this.expected === null && !this.assertions.length ) {
965
+ this.pushFailure( "Expected at least one assertion, but none were run - call " +
966
+ "expect(0) to accept zero assertions.", this.stack );
967
+ }
968
+
969
+ var i,
970
+ bad = 0;
971
+
972
+ this.runtime = now() - this.started;
973
+ config.stats.all += this.assertions.length;
974
+ config.moduleStats.all += this.assertions.length;
975
+
976
+ for ( i = 0; i < this.assertions.length; i++ ) {
977
+ if ( !this.assertions[ i ].result ) {
978
+ bad++;
979
+ config.stats.bad++;
980
+ config.moduleStats.bad++;
981
+ }
982
+ }
983
+
984
+ runLoggingCallbacks( "testDone", {
985
+ name: this.testName,
986
+ module: this.module.name,
987
+ skipped: !!this.skip,
988
+ failed: bad,
989
+ passed: this.assertions.length - bad,
990
+ total: this.assertions.length,
991
+ runtime: this.runtime,
992
+
993
+ // HTML Reporter use
994
+ assertions: this.assertions,
995
+ testId: this.testId,
996
+
997
+ // Source of Test
998
+ source: this.stack,
999
+
1000
+ // DEPRECATED: this property will be removed in 2.0.0, use runtime instead
1001
+ duration: this.runtime
1002
+ });
1003
+
1004
+ // QUnit.reset() is deprecated and will be replaced for a new
1005
+ // fixture reset function on QUnit 2.0/2.1.
1006
+ // It's still called here for backwards compatibility handling
1007
+ QUnit.reset();
1008
+
1009
+ config.current = undefined;
1010
+ },
1011
+
1012
+ queue: function() {
1013
+ var priority,
1014
+ test = this;
1015
+
1016
+ if ( !this.valid() ) {
1017
+ return;
1018
+ }
1019
+
1020
+ function run() {
1021
+
1022
+ // each of these can by async
1023
+ synchronize([
1024
+ function() {
1025
+ test.before();
1026
+ },
1027
+
1028
+ test.hooks( "beforeEach" ),
1029
+ function() {
1030
+ test.run();
1031
+ },
1032
+
1033
+ test.hooks( "afterEach" ).reverse(),
1034
+
1035
+ function() {
1036
+ test.after();
1037
+ },
1038
+ function() {
1039
+ test.finish();
1040
+ }
1041
+ ]);
1042
+ }
1043
+
1044
+ // Prioritize previously failed tests, detected from sessionStorage
1045
+ priority = QUnit.config.reorder && defined.sessionStorage &&
1046
+ +sessionStorage.getItem( "qunit-test-" + this.module.name + "-" + this.testName );
1047
+
1048
+ return synchronize( run, priority );
1049
+ },
1050
+
1051
+ push: function( result, actual, expected, message, negative ) {
1052
+ var source,
1053
+ details = {
1054
+ module: this.module.name,
1055
+ name: this.testName,
1056
+ result: result,
1057
+ message: message,
1058
+ actual: actual,
1059
+ expected: expected,
1060
+ testId: this.testId,
1061
+ negative: negative || false,
1062
+ runtime: now() - this.started
1063
+ };
1064
+
1065
+ if ( !result ) {
1066
+ source = sourceFromStacktrace();
1067
+
1068
+ if ( source ) {
1069
+ details.source = source;
1070
+ }
1071
+ }
1072
+
1073
+ runLoggingCallbacks( "log", details );
1074
+
1075
+ this.assertions.push({
1076
+ result: !!result,
1077
+ message: message
1078
+ });
1079
+ },
1080
+
1081
+ pushFailure: function( message, source, actual ) {
1082
+ if ( !( this instanceof Test ) ) {
1083
+ throw new Error( "pushFailure() assertion outside test context, was " +
1084
+ sourceFromStacktrace( 2 ) );
1085
+ }
1086
+
1087
+ var details = {
1088
+ module: this.module.name,
1089
+ name: this.testName,
1090
+ result: false,
1091
+ message: message || "error",
1092
+ actual: actual || null,
1093
+ testId: this.testId,
1094
+ runtime: now() - this.started
1095
+ };
1096
+
1097
+ if ( source ) {
1098
+ details.source = source;
1099
+ }
1100
+
1101
+ runLoggingCallbacks( "log", details );
1102
+
1103
+ this.assertions.push({
1104
+ result: false,
1105
+ message: message
1106
+ });
1107
+ },
1108
+
1109
+ resolvePromise: function( promise, phase ) {
1110
+ var then, message,
1111
+ test = this;
1112
+ if ( promise != null ) {
1113
+ then = promise.then;
1114
+ if ( QUnit.objectType( then ) === "function" ) {
1115
+ QUnit.stop();
1116
+ then.call(
1117
+ promise,
1118
+ function() { QUnit.start(); },
1119
+ function( error ) {
1120
+ message = "Promise rejected " +
1121
+ ( !phase ? "during" : phase.replace( /Each$/, "" ) ) +
1122
+ " " + test.testName + ": " + ( error.message || error );
1123
+ test.pushFailure( message, extractStacktrace( error, 0 ) );
1124
+
1125
+ // else next test will carry the responsibility
1126
+ saveGlobal();
1127
+
1128
+ // Unblock
1129
+ QUnit.start();
1130
+ }
1131
+ );
1132
+ }
1133
+ }
1134
+ },
1135
+
1136
+ valid: function() {
1137
+ var include,
1138
+ filter = config.filter && config.filter.toLowerCase(),
1139
+ module = QUnit.urlParams.module && QUnit.urlParams.module.toLowerCase(),
1140
+ fullName = ( this.module.name + ": " + this.testName ).toLowerCase();
1141
+
1142
+ function testInModuleChain( testModule ) {
1143
+ var testModuleName = testModule.name ? testModule.name.toLowerCase() : null;
1144
+ if ( testModuleName === module ) {
1145
+ return true;
1146
+ } else if ( testModule.parentModule ) {
1147
+ return testInModuleChain( testModule.parentModule );
1148
+ } else {
1149
+ return false;
1150
+ }
1151
+ }
1152
+
1153
+ // Internally-generated tests are always valid
1154
+ if ( this.callback && this.callback.validTest ) {
1155
+ return true;
1156
+ }
1157
+
1158
+ if ( config.testId.length > 0 && inArray( this.testId, config.testId ) < 0 ) {
1159
+ return false;
1160
+ }
1161
+
1162
+ if ( module && !testInModuleChain( this.module ) ) {
1163
+ return false;
1164
+ }
1165
+
1166
+ if ( !filter ) {
1167
+ return true;
1168
+ }
1169
+
1170
+ include = filter.charAt( 0 ) !== "!";
1171
+ if ( !include ) {
1172
+ filter = filter.slice( 1 );
1173
+ }
1174
+
1175
+ // If the filter matches, we need to honour include
1176
+ if ( fullName.indexOf( filter ) !== -1 ) {
1177
+ return include;
1178
+ }
1179
+
1180
+ // Otherwise, do the opposite
1181
+ return !include;
1182
+ }
1183
+ };
1184
+
1185
+ // Resets the test setup. Useful for tests that modify the DOM.
1186
+ /*
1187
+ DEPRECATED: Use multiple tests instead of resetting inside a test.
1188
+ Use testStart or testDone for custom cleanup.
1189
+ This method will throw an error in 2.0, and will be removed in 2.1
1190
+ */
1191
+ QUnit.reset = function() {
1192
+
1193
+ // Return on non-browser environments
1194
+ // This is necessary to not break on node tests
1195
+ if ( !defined.document ) {
1196
+ return;
1197
+ }
1198
+
1199
+ var fixture = defined.document && document.getElementById &&
1200
+ document.getElementById( "qunit-fixture" );
1201
+
1202
+ if ( fixture ) {
1203
+ fixture.innerHTML = config.fixture;
1204
+ }
1205
+ };
1206
+
1207
+ QUnit.pushFailure = function() {
1208
+ if ( !QUnit.config.current ) {
1209
+ throw new Error( "pushFailure() assertion outside test context, in " +
1210
+ sourceFromStacktrace( 2 ) );
1211
+ }
1212
+
1213
+ // Gets current test obj
1214
+ var currentTest = QUnit.config.current;
1215
+
1216
+ return currentTest.pushFailure.apply( currentTest, arguments );
1217
+ };
1218
+
1219
+ // Based on Java's String.hashCode, a simple but not
1220
+ // rigorously collision resistant hashing function
1221
+ function generateHash( module, testName ) {
1222
+ var hex,
1223
+ i = 0,
1224
+ hash = 0,
1225
+ str = module + "\x1C" + testName,
1226
+ len = str.length;
1227
+
1228
+ for ( ; i < len; i++ ) {
1229
+ hash = ( ( hash << 5 ) - hash ) + str.charCodeAt( i );
1230
+ hash |= 0;
1231
+ }
1232
+
1233
+ // Convert the possibly negative integer hash code into an 8 character hex string, which isn't
1234
+ // strictly necessary but increases user understanding that the id is a SHA-like hash
1235
+ hex = ( 0x100000000 + hash ).toString( 16 );
1236
+ if ( hex.length < 8 ) {
1237
+ hex = "0000000" + hex;
1238
+ }
1239
+
1240
+ return hex.slice( -8 );
1241
+ }
1242
+
1243
+ function synchronize( callback, priority ) {
1244
+ var last = !priority;
1245
+
1246
+ if ( QUnit.objectType( callback ) === "array" ) {
1247
+ while ( callback.length ) {
1248
+ synchronize( callback.shift() );
1249
+ }
1250
+ return;
1251
+ }
1252
+
1253
+ if ( priority ) {
1254
+ priorityFill( callback );
1255
+ } else {
1256
+ config.queue.push( callback );
1257
+ }
1258
+
1259
+ if ( config.autorun && !config.blocking ) {
1260
+ process( last );
1261
+ }
1262
+ }
1263
+
1264
+ // Place previously failed tests on a queue priority line, respecting the order they get assigned.
1265
+ function priorityFill( callback ) {
1266
+ var queue, prioritizedQueue;
1267
+
1268
+ queue = config.queue.slice( priorityFill.pos );
1269
+ prioritizedQueue = config.queue.slice( 0, -config.queue.length + priorityFill.pos );
1270
+
1271
+ queue.unshift( callback );
1272
+ queue.unshift.apply( queue, prioritizedQueue );
1273
+
1274
+ config.queue = queue;
1275
+
1276
+ priorityFill.pos += 1;
1277
+ }
1278
+ priorityFill.pos = 0;
1279
+
1280
+ function saveGlobal() {
1281
+ config.pollution = [];
1282
+
1283
+ if ( config.noglobals ) {
1284
+ for ( var key in global ) {
1285
+ if ( hasOwn.call( global, key ) ) {
1286
+
1287
+ // in Opera sometimes DOM element ids show up here, ignore them
1288
+ if ( /^qunit-test-output/.test( key ) ) {
1289
+ continue;
1290
+ }
1291
+ config.pollution.push( key );
1292
+ }
1293
+ }
1294
+ }
1295
+ }
1296
+
1297
+ function checkPollution() {
1298
+ var newGlobals,
1299
+ deletedGlobals,
1300
+ old = config.pollution;
1301
+
1302
+ saveGlobal();
1303
+
1304
+ newGlobals = diff( config.pollution, old );
1305
+ if ( newGlobals.length > 0 ) {
1306
+ QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join( ", " ) );
1307
+ }
1308
+
1309
+ deletedGlobals = diff( old, config.pollution );
1310
+ if ( deletedGlobals.length > 0 ) {
1311
+ QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join( ", " ) );
1312
+ }
1313
+ }
1314
+
1315
+ // Will be exposed as QUnit.asyncTest
1316
+ function asyncTest( testName, expected, callback ) {
1317
+ if ( arguments.length === 2 ) {
1318
+ callback = expected;
1319
+ expected = null;
1320
+ }
1321
+
1322
+ QUnit.test( testName, expected, callback, true );
1323
+ }
1324
+
1325
+ // Will be exposed as QUnit.test
1326
+ function test( testName, expected, callback, async ) {
1327
+ if ( focused ) { return; }
1328
+
1329
+ var newTest;
1330
+
1331
+ if ( arguments.length === 2 ) {
1332
+ callback = expected;
1333
+ expected = null;
1334
+ }
1335
+
1336
+ newTest = new Test({
1337
+ testName: testName,
1338
+ expected: expected,
1339
+ async: async,
1340
+ callback: callback
1341
+ });
1342
+
1343
+ newTest.queue();
1344
+ }
1345
+
1346
+ // Will be exposed as QUnit.skip
1347
+ function skip( testName ) {
1348
+ if ( focused ) { return; }
1349
+
1350
+ var test = new Test({
1351
+ testName: testName,
1352
+ skip: true
1353
+ });
1354
+
1355
+ test.queue();
1356
+ }
1357
+
1358
+ // Will be exposed as QUnit.only
1359
+ function only( testName, expected, callback, async ) {
1360
+ var newTest;
1361
+
1362
+ if ( focused ) { return; }
1363
+
1364
+ QUnit.config.queue.length = 0;
1365
+ focused = true;
1366
+
1367
+ if ( arguments.length === 2 ) {
1368
+ callback = expected;
1369
+ expected = null;
1370
+ }
1371
+
1372
+ newTest = new Test({
1373
+ testName: testName,
1374
+ expected: expected,
1375
+ async: async,
1376
+ callback: callback
1377
+ });
1378
+
1379
+ newTest.queue();
1380
+ }
1381
+
1382
+ function Assert( testContext ) {
1383
+ this.test = testContext;
1384
+ }
1385
+
1386
+ // Assert helpers
1387
+ QUnit.assert = Assert.prototype = {
1388
+
1389
+ // Specify the number of expected assertions to guarantee that failed test
1390
+ // (no assertions are run at all) don't slip through.
1391
+ expect: function( asserts ) {
1392
+ if ( arguments.length === 1 ) {
1393
+ this.test.expected = asserts;
1394
+ } else {
1395
+ return this.test.expected;
1396
+ }
1397
+ },
1398
+
1399
+ // Increment this Test's semaphore counter, then return a function that
1400
+ // decrements that counter a maximum of once.
1401
+ async: function( count ) {
1402
+ var test = this.test,
1403
+ popped = false,
1404
+ acceptCallCount = count;
1405
+
1406
+ if ( typeof acceptCallCount === "undefined" ) {
1407
+ acceptCallCount = 1;
1408
+ }
1409
+
1410
+ test.semaphore += 1;
1411
+ test.usedAsync = true;
1412
+ pauseProcessing();
1413
+
1414
+ return function done() {
1415
+
1416
+ if ( popped ) {
1417
+ test.pushFailure( "Too many calls to the `assert.async` callback",
1418
+ sourceFromStacktrace( 2 ) );
1419
+ return;
1420
+ }
1421
+ acceptCallCount -= 1;
1422
+ if ( acceptCallCount > 0 ) {
1423
+ return;
1424
+ }
1425
+
1426
+ test.semaphore -= 1;
1427
+ popped = true;
1428
+ resumeProcessing();
1429
+ };
1430
+ },
1431
+
1432
+ // Exports test.push() to the user API
1433
+ push: function( /* result, actual, expected, message, negative */ ) {
1434
+ var assert = this,
1435
+ currentTest = ( assert instanceof Assert && assert.test ) || QUnit.config.current;
1436
+
1437
+ // Backwards compatibility fix.
1438
+ // Allows the direct use of global exported assertions and QUnit.assert.*
1439
+ // Although, it's use is not recommended as it can leak assertions
1440
+ // to other tests from async tests, because we only get a reference to the current test,
1441
+ // not exactly the test where assertion were intended to be called.
1442
+ if ( !currentTest ) {
1443
+ throw new Error( "assertion outside test context, in " + sourceFromStacktrace( 2 ) );
1444
+ }
1445
+
1446
+ if ( currentTest.usedAsync === true && currentTest.semaphore === 0 ) {
1447
+ currentTest.pushFailure( "Assertion after the final `assert.async` was resolved",
1448
+ sourceFromStacktrace( 2 ) );
1449
+
1450
+ // Allow this assertion to continue running anyway...
1451
+ }
1452
+
1453
+ if ( !( assert instanceof Assert ) ) {
1454
+ assert = currentTest.assert;
1455
+ }
1456
+ return assert.test.push.apply( assert.test, arguments );
1457
+ },
1458
+
1459
+ ok: function( result, message ) {
1460
+ message = message || ( result ? "okay" : "failed, expected argument to be truthy, was: " +
1461
+ QUnit.dump.parse( result ) );
1462
+ this.push( !!result, result, true, message );
1463
+ },
1464
+
1465
+ notOk: function( result, message ) {
1466
+ message = message || ( !result ? "okay" : "failed, expected argument to be falsy, was: " +
1467
+ QUnit.dump.parse( result ) );
1468
+ this.push( !result, result, false, message, true );
1469
+ },
1470
+
1471
+ equal: function( actual, expected, message ) {
1472
+ /*jshint eqeqeq:false */
1473
+ this.push( expected == actual, actual, expected, message );
1474
+ },
1475
+
1476
+ notEqual: function( actual, expected, message ) {
1477
+ /*jshint eqeqeq:false */
1478
+ this.push( expected != actual, actual, expected, message, true );
1479
+ },
1480
+
1481
+ propEqual: function( actual, expected, message ) {
1482
+ actual = objectValues( actual );
1483
+ expected = objectValues( expected );
1484
+ this.push( QUnit.equiv( actual, expected ), actual, expected, message );
1485
+ },
1486
+
1487
+ notPropEqual: function( actual, expected, message ) {
1488
+ actual = objectValues( actual );
1489
+ expected = objectValues( expected );
1490
+ this.push( !QUnit.equiv( actual, expected ), actual, expected, message, true );
1491
+ },
1492
+
1493
+ deepEqual: function( actual, expected, message ) {
1494
+ this.push( QUnit.equiv( actual, expected ), actual, expected, message );
1495
+ },
1496
+
1497
+ notDeepEqual: function( actual, expected, message ) {
1498
+ this.push( !QUnit.equiv( actual, expected ), actual, expected, message, true );
1499
+ },
1500
+
1501
+ strictEqual: function( actual, expected, message ) {
1502
+ this.push( expected === actual, actual, expected, message );
1503
+ },
1504
+
1505
+ notStrictEqual: function( actual, expected, message ) {
1506
+ this.push( expected !== actual, actual, expected, message, true );
1507
+ },
1508
+
1509
+ "throws": function( block, expected, message ) {
1510
+ var actual, expectedType,
1511
+ expectedOutput = expected,
1512
+ ok = false,
1513
+ currentTest = ( this instanceof Assert && this.test ) || QUnit.config.current;
1514
+
1515
+ // 'expected' is optional unless doing string comparison
1516
+ if ( message == null && typeof expected === "string" ) {
1517
+ message = expected;
1518
+ expected = null;
1519
+ }
1520
+
1521
+ currentTest.ignoreGlobalErrors = true;
1522
+ try {
1523
+ block.call( currentTest.testEnvironment );
1524
+ } catch (e) {
1525
+ actual = e;
1526
+ }
1527
+ currentTest.ignoreGlobalErrors = false;
1528
+
1529
+ if ( actual ) {
1530
+ expectedType = QUnit.objectType( expected );
1531
+
1532
+ // we don't want to validate thrown error
1533
+ if ( !expected ) {
1534
+ ok = true;
1535
+ expectedOutput = null;
1536
+
1537
+ // expected is a regexp
1538
+ } else if ( expectedType === "regexp" ) {
1539
+ ok = expected.test( errorString( actual ) );
1540
+
1541
+ // expected is a string
1542
+ } else if ( expectedType === "string" ) {
1543
+ ok = expected === errorString( actual );
1544
+
1545
+ // expected is a constructor, maybe an Error constructor
1546
+ } else if ( expectedType === "function" && actual instanceof expected ) {
1547
+ ok = true;
1548
+
1549
+ // expected is an Error object
1550
+ } else if ( expectedType === "object" ) {
1551
+ ok = actual instanceof expected.constructor &&
1552
+ actual.name === expected.name &&
1553
+ actual.message === expected.message;
1554
+
1555
+ // expected is a validation function which returns true if validation passed
1556
+ } else if ( expectedType === "function" && expected.call( {}, actual ) === true ) {
1557
+ expectedOutput = null;
1558
+ ok = true;
1559
+ }
1560
+ }
1561
+
1562
+ currentTest.assert.push( ok, actual, expectedOutput, message );
1563
+ }
1564
+ };
1565
+
1566
+ // Provide an alternative to assert.throws(), for environments that consider throws a reserved word
1567
+ // Known to us are: Closure Compiler, Narwhal
1568
+ (function() {
1569
+ /*jshint sub:true */
1570
+ Assert.prototype.raises = Assert.prototype[ "throws" ];
1571
+ }());
1572
+
1573
+ function errorString( error ) {
1574
+ var name, message,
1575
+ resultErrorString = error.toString();
1576
+ if ( resultErrorString.substring( 0, 7 ) === "[object" ) {
1577
+ name = error.name ? error.name.toString() : "Error";
1578
+ message = error.message ? error.message.toString() : "";
1579
+ if ( name && message ) {
1580
+ return name + ": " + message;
1581
+ } else if ( name ) {
1582
+ return name;
1583
+ } else if ( message ) {
1584
+ return message;
1585
+ } else {
1586
+ return "Error";
1587
+ }
1588
+ } else {
1589
+ return resultErrorString;
1590
+ }
1591
+ }
1592
+
1593
+ // Test for equality any JavaScript type.
1594
+ // Author: Philippe Rathé <prathe@gmail.com>
1595
+ QUnit.equiv = (function() {
1596
+
1597
+ // Stack to decide between skip/abort functions
1598
+ var callers = [];
1599
+
1600
+ // Stack to avoiding loops from circular referencing
1601
+ var parents = [];
1602
+ var parentsB = [];
1603
+
1604
+ function useStrictEquality( b, a ) {
1605
+
1606
+ /*jshint eqeqeq:false */
1607
+ if ( b instanceof a.constructor || a instanceof b.constructor ) {
1608
+
1609
+ // To catch short annotation VS 'new' annotation of a declaration. e.g.:
1610
+ // `var i = 1;`
1611
+ // `var j = new Number(1);`
1612
+ return a == b;
1613
+ } else {
1614
+ return a === b;
1615
+ }
1616
+ }
1617
+
1618
+ function compareConstructors( a, b ) {
1619
+ var getProto = Object.getPrototypeOf || function( obj ) {
1620
+
1621
+ /*jshint proto: true */
1622
+ return obj.__proto__;
1623
+ };
1624
+ var protoA = getProto( a );
1625
+ var protoB = getProto( b );
1626
+
1627
+ // Comparing constructors is more strict than using `instanceof`
1628
+ if ( a.constructor === b.constructor ) {
1629
+ return true;
1630
+ }
1631
+
1632
+ // Ref #851
1633
+ // If the obj prototype descends from a null constructor, treat it
1634
+ // as a null prototype.
1635
+ if ( protoA && protoA.constructor === null ) {
1636
+ protoA = null;
1637
+ }
1638
+ if ( protoB && protoB.constructor === null ) {
1639
+ protoB = null;
1640
+ }
1641
+
1642
+ // Allow objects with no prototype to be equivalent to
1643
+ // objects with Object as their constructor.
1644
+ if ( ( protoA === null && protoB === Object.prototype ) ||
1645
+ ( protoB === null && protoA === Object.prototype ) ) {
1646
+ return true;
1647
+ }
1648
+
1649
+ return false;
1650
+ }
1651
+
1652
+ var callbacks = {
1653
+ "string": useStrictEquality,
1654
+ "boolean": useStrictEquality,
1655
+ "number": useStrictEquality,
1656
+ "null": useStrictEquality,
1657
+ "undefined": useStrictEquality,
1658
+ "symbol": useStrictEquality,
1659
+
1660
+ "nan": function( b ) {
1661
+ return isNaN( b );
1662
+ },
1663
+
1664
+ "date": function( b, a ) {
1665
+ return QUnit.objectType( b ) === "date" && a.valueOf() === b.valueOf();
1666
+ },
1667
+
1668
+ "regexp": function( b, a ) {
1669
+ return QUnit.objectType( b ) === "regexp" &&
1670
+
1671
+ // The regex itself
1672
+ a.source === b.source &&
1673
+
1674
+ // And its modifiers
1675
+ a.global === b.global &&
1676
+
1677
+ // (gmi) ...
1678
+ a.ignoreCase === b.ignoreCase &&
1679
+ a.multiline === b.multiline &&
1680
+ a.sticky === b.sticky;
1681
+ },
1682
+
1683
+ // - skip when the property is a method of an instance (OOP)
1684
+ // - abort otherwise,
1685
+ // initial === would have catch identical references anyway
1686
+ "function": function() {
1687
+ var caller = callers[ callers.length - 1 ];
1688
+ return caller !== Object && typeof caller !== "undefined";
1689
+ },
1690
+
1691
+ "array": function( b, a ) {
1692
+ var i, j, len, loop, aCircular, bCircular;
1693
+
1694
+ // b could be an object literal here
1695
+ if ( QUnit.objectType( b ) !== "array" ) {
1696
+ return false;
1697
+ }
1698
+
1699
+ len = a.length;
1700
+ if ( len !== b.length ) {
1701
+ // safe and faster
1702
+ return false;
1703
+ }
1704
+
1705
+ // Track reference to avoid circular references
1706
+ parents.push( a );
1707
+ parentsB.push( b );
1708
+ for ( i = 0; i < len; i++ ) {
1709
+ loop = false;
1710
+ for ( j = 0; j < parents.length; j++ ) {
1711
+ aCircular = parents[ j ] === a[ i ];
1712
+ bCircular = parentsB[ j ] === b[ i ];
1713
+ if ( aCircular || bCircular ) {
1714
+ if ( a[ i ] === b[ i ] || aCircular && bCircular ) {
1715
+ loop = true;
1716
+ } else {
1717
+ parents.pop();
1718
+ parentsB.pop();
1719
+ return false;
1720
+ }
1721
+ }
1722
+ }
1723
+ if ( !loop && !innerEquiv( a[ i ], b[ i ] ) ) {
1724
+ parents.pop();
1725
+ parentsB.pop();
1726
+ return false;
1727
+ }
1728
+ }
1729
+ parents.pop();
1730
+ parentsB.pop();
1731
+ return true;
1732
+ },
1733
+
1734
+ "set": function( b, a ) {
1735
+ var aArray, bArray;
1736
+
1737
+ // `b` could be any object here
1738
+ if ( QUnit.objectType( b ) !== "set" ) {
1739
+ return false;
1740
+ }
1741
+
1742
+ aArray = [];
1743
+ a.forEach( function( v ) {
1744
+ aArray.push( v );
1745
+ });
1746
+ bArray = [];
1747
+ b.forEach( function( v ) {
1748
+ bArray.push( v );
1749
+ });
1750
+
1751
+ return innerEquiv( bArray, aArray );
1752
+ },
1753
+
1754
+ "map": function( b, a ) {
1755
+ var aArray, bArray;
1756
+
1757
+ // `b` could be any object here
1758
+ if ( QUnit.objectType( b ) !== "map" ) {
1759
+ return false;
1760
+ }
1761
+
1762
+ aArray = [];
1763
+ a.forEach( function( v, k ) {
1764
+ aArray.push( [ k, v ] );
1765
+ });
1766
+ bArray = [];
1767
+ b.forEach( function( v, k ) {
1768
+ bArray.push( [ k, v ] );
1769
+ });
1770
+
1771
+ return innerEquiv( bArray, aArray );
1772
+ },
1773
+
1774
+ "object": function( b, a ) {
1775
+ var i, j, loop, aCircular, bCircular;
1776
+
1777
+ // Default to true
1778
+ var eq = true;
1779
+ var aProperties = [];
1780
+ var bProperties = [];
1781
+
1782
+ if ( compareConstructors( a, b ) === false ) {
1783
+ return false;
1784
+ }
1785
+
1786
+ // Stack constructor before traversing properties
1787
+ callers.push( a.constructor );
1788
+
1789
+ // Track reference to avoid circular references
1790
+ parents.push( a );
1791
+ parentsB.push( b );
1792
+
1793
+ // Be strict: don't ensure hasOwnProperty and go deep
1794
+ for ( i in a ) {
1795
+ loop = false;
1796
+ for ( j = 0; j < parents.length; j++ ) {
1797
+ aCircular = parents[ j ] === a[ i ];
1798
+ bCircular = parentsB[ j ] === b[ i ];
1799
+ if ( aCircular || bCircular ) {
1800
+ if ( a[ i ] === b[ i ] || aCircular && bCircular ) {
1801
+ loop = true;
1802
+ } else {
1803
+ eq = false;
1804
+ break;
1805
+ }
1806
+ }
1807
+ }
1808
+ aProperties.push( i );
1809
+ if ( !loop && !innerEquiv( a[ i ], b[ i ] ) ) {
1810
+ eq = false;
1811
+ break;
1812
+ }
1813
+ }
1814
+
1815
+ parents.pop();
1816
+ parentsB.pop();
1817
+
1818
+ // Unstack, we are done
1819
+ callers.pop();
1820
+
1821
+ for ( i in b ) {
1822
+
1823
+ // Collect b's properties
1824
+ bProperties.push( i );
1825
+ }
1826
+
1827
+ // Ensures identical properties name
1828
+ return eq && innerEquiv( aProperties.sort(), bProperties.sort() );
1829
+ }
1830
+ };
1831
+
1832
+ function typeEquiv( a, b ) {
1833
+ var prop = QUnit.objectType( a );
1834
+ return callbacks[ prop ]( b, a );
1835
+ }
1836
+
1837
+ // The real equiv function
1838
+ function innerEquiv() {
1839
+ var args = [].slice.apply( arguments );
1840
+ if ( args.length < 2 ) {
1841
+
1842
+ // End transition
1843
+ return true;
1844
+ }
1845
+
1846
+ return ( (function( a, b ) {
1847
+ if ( a === b ) {
1848
+
1849
+ // Catch the most you can
1850
+ return true;
1851
+ } else if ( a === null || b === null || typeof a === "undefined" ||
1852
+ typeof b === "undefined" ||
1853
+ QUnit.objectType( a ) !== QUnit.objectType( b ) ) {
1854
+
1855
+ // Don't lose time with error prone cases
1856
+ return false;
1857
+ } else {
1858
+ return typeEquiv( a, b );
1859
+ }
1860
+
1861
+ // Apply transition with (1..n) arguments
1862
+ }( args[ 0 ], args[ 1 ] ) ) &&
1863
+ innerEquiv.apply( this, args.splice( 1, args.length - 1 ) ) );
1864
+ }
1865
+
1866
+ return innerEquiv;
1867
+ }());
1868
+
1869
+ // Based on jsDump by Ariel Flesler
1870
+ // http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html
1871
+ QUnit.dump = (function() {
1872
+ function quote( str ) {
1873
+ return "\"" + str.toString().replace( /\\/g, "\\\\" ).replace( /"/g, "\\\"" ) + "\"";
1874
+ }
1875
+ function literal( o ) {
1876
+ return o + "";
1877
+ }
1878
+ function join( pre, arr, post ) {
1879
+ var s = dump.separator(),
1880
+ base = dump.indent(),
1881
+ inner = dump.indent( 1 );
1882
+ if ( arr.join ) {
1883
+ arr = arr.join( "," + s + inner );
1884
+ }
1885
+ if ( !arr ) {
1886
+ return pre + post;
1887
+ }
1888
+ return [ pre, inner + arr, base + post ].join( s );
1889
+ }
1890
+ function array( arr, stack ) {
1891
+ var i = arr.length,
1892
+ ret = new Array( i );
1893
+
1894
+ if ( dump.maxDepth && dump.depth > dump.maxDepth ) {
1895
+ return "[object Array]";
1896
+ }
1897
+
1898
+ this.up();
1899
+ while ( i-- ) {
1900
+ ret[ i ] = this.parse( arr[ i ], undefined, stack );
1901
+ }
1902
+ this.down();
1903
+ return join( "[", ret, "]" );
1904
+ }
1905
+
1906
+ var reName = /^function (\w+)/,
1907
+ dump = {
1908
+
1909
+ // objType is used mostly internally, you can fix a (custom) type in advance
1910
+ parse: function( obj, objType, stack ) {
1911
+ stack = stack || [];
1912
+ var res, parser, parserType,
1913
+ inStack = inArray( obj, stack );
1914
+
1915
+ if ( inStack !== -1 ) {
1916
+ return "recursion(" + ( inStack - stack.length ) + ")";
1917
+ }
1918
+
1919
+ objType = objType || this.typeOf( obj );
1920
+ parser = this.parsers[ objType ];
1921
+ parserType = typeof parser;
1922
+
1923
+ if ( parserType === "function" ) {
1924
+ stack.push( obj );
1925
+ res = parser.call( this, obj, stack );
1926
+ stack.pop();
1927
+ return res;
1928
+ }
1929
+ return ( parserType === "string" ) ? parser : this.parsers.error;
1930
+ },
1931
+ typeOf: function( obj ) {
1932
+ var type;
1933
+ if ( obj === null ) {
1934
+ type = "null";
1935
+ } else if ( typeof obj === "undefined" ) {
1936
+ type = "undefined";
1937
+ } else if ( QUnit.is( "regexp", obj ) ) {
1938
+ type = "regexp";
1939
+ } else if ( QUnit.is( "date", obj ) ) {
1940
+ type = "date";
1941
+ } else if ( QUnit.is( "function", obj ) ) {
1942
+ type = "function";
1943
+ } else if ( obj.setInterval !== undefined &&
1944
+ obj.document !== undefined &&
1945
+ obj.nodeType === undefined ) {
1946
+ type = "window";
1947
+ } else if ( obj.nodeType === 9 ) {
1948
+ type = "document";
1949
+ } else if ( obj.nodeType ) {
1950
+ type = "node";
1951
+ } else if (
1952
+
1953
+ // native arrays
1954
+ toString.call( obj ) === "[object Array]" ||
1955
+
1956
+ // NodeList objects
1957
+ ( typeof obj.length === "number" && obj.item !== undefined &&
1958
+ ( obj.length ? obj.item( 0 ) === obj[ 0 ] : ( obj.item( 0 ) === null &&
1959
+ obj[ 0 ] === undefined ) ) )
1960
+ ) {
1961
+ type = "array";
1962
+ } else if ( obj.constructor === Error.prototype.constructor ) {
1963
+ type = "error";
1964
+ } else {
1965
+ type = typeof obj;
1966
+ }
1967
+ return type;
1968
+ },
1969
+ separator: function() {
1970
+ return this.multiline ? this.HTML ? "<br />" : "\n" : this.HTML ? "&#160;" : " ";
1971
+ },
1972
+ // extra can be a number, shortcut for increasing-calling-decreasing
1973
+ indent: function( extra ) {
1974
+ if ( !this.multiline ) {
1975
+ return "";
1976
+ }
1977
+ var chr = this.indentChar;
1978
+ if ( this.HTML ) {
1979
+ chr = chr.replace( /\t/g, " " ).replace( / /g, "&#160;" );
1980
+ }
1981
+ return new Array( this.depth + ( extra || 0 ) ).join( chr );
1982
+ },
1983
+ up: function( a ) {
1984
+ this.depth += a || 1;
1985
+ },
1986
+ down: function( a ) {
1987
+ this.depth -= a || 1;
1988
+ },
1989
+ setParser: function( name, parser ) {
1990
+ this.parsers[ name ] = parser;
1991
+ },
1992
+ // The next 3 are exposed so you can use them
1993
+ quote: quote,
1994
+ literal: literal,
1995
+ join: join,
1996
+ //
1997
+ depth: 1,
1998
+ maxDepth: QUnit.config.maxDepth,
1999
+
2000
+ // This is the list of parsers, to modify them, use dump.setParser
2001
+ parsers: {
2002
+ window: "[Window]",
2003
+ document: "[Document]",
2004
+ error: function( error ) {
2005
+ return "Error(\"" + error.message + "\")";
2006
+ },
2007
+ unknown: "[Unknown]",
2008
+ "null": "null",
2009
+ "undefined": "undefined",
2010
+ "function": function( fn ) {
2011
+ var ret = "function",
2012
+
2013
+ // functions never have name in IE
2014
+ name = "name" in fn ? fn.name : ( reName.exec( fn ) || [] )[ 1 ];
2015
+
2016
+ if ( name ) {
2017
+ ret += " " + name;
2018
+ }
2019
+ ret += "( ";
2020
+
2021
+ ret = [ ret, dump.parse( fn, "functionArgs" ), "){" ].join( "" );
2022
+ return join( ret, dump.parse( fn, "functionCode" ), "}" );
2023
+ },
2024
+ array: array,
2025
+ nodelist: array,
2026
+ "arguments": array,
2027
+ object: function( map, stack ) {
2028
+ var keys, key, val, i, nonEnumerableProperties,
2029
+ ret = [];
2030
+
2031
+ if ( dump.maxDepth && dump.depth > dump.maxDepth ) {
2032
+ return "[object Object]";
2033
+ }
2034
+
2035
+ dump.up();
2036
+ keys = [];
2037
+ for ( key in map ) {
2038
+ keys.push( key );
2039
+ }
2040
+
2041
+ // Some properties are not always enumerable on Error objects.
2042
+ nonEnumerableProperties = [ "message", "name" ];
2043
+ for ( i in nonEnumerableProperties ) {
2044
+ key = nonEnumerableProperties[ i ];
2045
+ if ( key in map && inArray( key, keys ) < 0 ) {
2046
+ keys.push( key );
2047
+ }
2048
+ }
2049
+ keys.sort();
2050
+ for ( i = 0; i < keys.length; i++ ) {
2051
+ key = keys[ i ];
2052
+ val = map[ key ];
2053
+ ret.push( dump.parse( key, "key" ) + ": " +
2054
+ dump.parse( val, undefined, stack ) );
2055
+ }
2056
+ dump.down();
2057
+ return join( "{", ret, "}" );
2058
+ },
2059
+ node: function( node ) {
2060
+ var len, i, val,
2061
+ open = dump.HTML ? "&lt;" : "<",
2062
+ close = dump.HTML ? "&gt;" : ">",
2063
+ tag = node.nodeName.toLowerCase(),
2064
+ ret = open + tag,
2065
+ attrs = node.attributes;
2066
+
2067
+ if ( attrs ) {
2068
+ for ( i = 0, len = attrs.length; i < len; i++ ) {
2069
+ val = attrs[ i ].nodeValue;
2070
+
2071
+ // IE6 includes all attributes in .attributes, even ones not explicitly
2072
+ // set. Those have values like undefined, null, 0, false, "" or
2073
+ // "inherit".
2074
+ if ( val && val !== "inherit" ) {
2075
+ ret += " " + attrs[ i ].nodeName + "=" +
2076
+ dump.parse( val, "attribute" );
2077
+ }
2078
+ }
2079
+ }
2080
+ ret += close;
2081
+
2082
+ // Show content of TextNode or CDATASection
2083
+ if ( node.nodeType === 3 || node.nodeType === 4 ) {
2084
+ ret += node.nodeValue;
2085
+ }
2086
+
2087
+ return ret + open + "/" + tag + close;
2088
+ },
2089
+
2090
+ // function calls it internally, it's the arguments part of the function
2091
+ functionArgs: function( fn ) {
2092
+ var args,
2093
+ l = fn.length;
2094
+
2095
+ if ( !l ) {
2096
+ return "";
2097
+ }
2098
+
2099
+ args = new Array( l );
2100
+ while ( l-- ) {
2101
+
2102
+ // 97 is 'a'
2103
+ args[ l ] = String.fromCharCode( 97 + l );
2104
+ }
2105
+ return " " + args.join( ", " ) + " ";
2106
+ },
2107
+ // object calls it internally, the key part of an item in a map
2108
+ key: quote,
2109
+ // function calls it internally, it's the content of the function
2110
+ functionCode: "[code]",
2111
+ // node calls it internally, it's an html attribute value
2112
+ attribute: quote,
2113
+ string: quote,
2114
+ date: quote,
2115
+ regexp: literal,
2116
+ number: literal,
2117
+ "boolean": literal
2118
+ },
2119
+ // if true, entities are escaped ( <, >, \t, space and \n )
2120
+ HTML: false,
2121
+ // indentation unit
2122
+ indentChar: " ",
2123
+ // if true, items in a collection, are separated by a \n, else just a space.
2124
+ multiline: true
2125
+ };
2126
+
2127
+ return dump;
2128
+ }());
2129
+
2130
+ // back compat
2131
+ QUnit.jsDump = QUnit.dump;
2132
+
2133
+ // For browser, export only select globals
2134
+ if ( defined.document ) {
2135
+
2136
+ // Deprecated
2137
+ // Extend assert methods to QUnit and Global scope through Backwards compatibility
2138
+ (function() {
2139
+ var i,
2140
+ assertions = Assert.prototype;
2141
+
2142
+ function applyCurrent( current ) {
2143
+ return function() {
2144
+ var assert = new Assert( QUnit.config.current );
2145
+ current.apply( assert, arguments );
2146
+ };
2147
+ }
2148
+
2149
+ for ( i in assertions ) {
2150
+ QUnit[ i ] = applyCurrent( assertions[ i ] );
2151
+ }
2152
+ })();
2153
+
2154
+ (function() {
2155
+ var i, l,
2156
+ keys = [
2157
+ "test",
2158
+ "module",
2159
+ "expect",
2160
+ "asyncTest",
2161
+ "start",
2162
+ "stop",
2163
+ "ok",
2164
+ "notOk",
2165
+ "equal",
2166
+ "notEqual",
2167
+ "propEqual",
2168
+ "notPropEqual",
2169
+ "deepEqual",
2170
+ "notDeepEqual",
2171
+ "strictEqual",
2172
+ "notStrictEqual",
2173
+ "throws",
2174
+ "raises"
2175
+ ];
2176
+
2177
+ for ( i = 0, l = keys.length; i < l; i++ ) {
2178
+ window[ keys[ i ] ] = QUnit[ keys[ i ] ];
2179
+ }
2180
+ })();
2181
+
2182
+ window.QUnit = QUnit;
2183
+ }
2184
+
2185
+ // For nodejs
2186
+ if ( typeof module !== "undefined" && module && module.exports ) {
2187
+ module.exports = QUnit;
2188
+
2189
+ // For consistency with CommonJS environments' exports
2190
+ module.exports.QUnit = QUnit;
2191
+ }
2192
+
2193
+ // For CommonJS with exports, but without module.exports, like Rhino
2194
+ if ( typeof exports !== "undefined" && exports ) {
2195
+ exports.QUnit = QUnit;
2196
+ }
2197
+
2198
+ if ( typeof define === "function" && define.amd ) {
2199
+ define( function() {
2200
+ return QUnit;
2201
+ } );
2202
+ QUnit.config.autostart = false;
2203
+ }
2204
+
2205
+ /*
2206
+ * This file is a modified version of google-diff-match-patch's JavaScript implementation
2207
+ * (https://code.google.com/p/google-diff-match-patch/source/browse/trunk/javascript/diff_match_patch_uncompressed.js),
2208
+ * modifications are licensed as more fully set forth in LICENSE.txt.
2209
+ *
2210
+ * The original source of google-diff-match-patch is attributable and licensed as follows:
2211
+ *
2212
+ * Copyright 2006 Google Inc.
2213
+ * http://code.google.com/p/google-diff-match-patch/
2214
+ *
2215
+ * Licensed under the Apache License, Version 2.0 (the "License");
2216
+ * you may not use this file except in compliance with the License.
2217
+ * You may obtain a copy of the License at
2218
+ *
2219
+ * http://www.apache.org/licenses/LICENSE-2.0
2220
+ *
2221
+ * Unless required by applicable law or agreed to in writing, software
2222
+ * distributed under the License is distributed on an "AS IS" BASIS,
2223
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2224
+ * See the License for the specific language governing permissions and
2225
+ * limitations under the License.
2226
+ *
2227
+ * More Info:
2228
+ * https://code.google.com/p/google-diff-match-patch/
2229
+ *
2230
+ * Usage: QUnit.diff(expected, actual)
2231
+ *
2232
+ */
2233
+ QUnit.diff = ( function() {
2234
+ function DiffMatchPatch() {
2235
+ }
2236
+
2237
+ // DIFF FUNCTIONS
2238
+
2239
+ /**
2240
+ * The data structure representing a diff is an array of tuples:
2241
+ * [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']]
2242
+ * which means: delete 'Hello', add 'Goodbye' and keep ' world.'
2243
+ */
2244
+ var DIFF_DELETE = -1,
2245
+ DIFF_INSERT = 1,
2246
+ DIFF_EQUAL = 0;
2247
+
2248
+ /**
2249
+ * Find the differences between two texts. Simplifies the problem by stripping
2250
+ * any common prefix or suffix off the texts before diffing.
2251
+ * @param {string} text1 Old string to be diffed.
2252
+ * @param {string} text2 New string to be diffed.
2253
+ * @param {boolean=} optChecklines Optional speedup flag. If present and false,
2254
+ * then don't run a line-level diff first to identify the changed areas.
2255
+ * Defaults to true, which does a faster, slightly less optimal diff.
2256
+ * @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples.
2257
+ */
2258
+ DiffMatchPatch.prototype.DiffMain = function( text1, text2, optChecklines ) {
2259
+ var deadline, checklines, commonlength,
2260
+ commonprefix, commonsuffix, diffs;
2261
+
2262
+ // The diff must be complete in up to 1 second.
2263
+ deadline = ( new Date() ).getTime() + 1000;
2264
+
2265
+ // Check for null inputs.
2266
+ if ( text1 === null || text2 === null ) {
2267
+ throw new Error( "Null input. (DiffMain)" );
2268
+ }
2269
+
2270
+ // Check for equality (speedup).
2271
+ if ( text1 === text2 ) {
2272
+ if ( text1 ) {
2273
+ return [
2274
+ [ DIFF_EQUAL, text1 ]
2275
+ ];
2276
+ }
2277
+ return [];
2278
+ }
2279
+
2280
+ if ( typeof optChecklines === "undefined" ) {
2281
+ optChecklines = true;
2282
+ }
2283
+
2284
+ checklines = optChecklines;
2285
+
2286
+ // Trim off common prefix (speedup).
2287
+ commonlength = this.diffCommonPrefix( text1, text2 );
2288
+ commonprefix = text1.substring( 0, commonlength );
2289
+ text1 = text1.substring( commonlength );
2290
+ text2 = text2.substring( commonlength );
2291
+
2292
+ // Trim off common suffix (speedup).
2293
+ commonlength = this.diffCommonSuffix( text1, text2 );
2294
+ commonsuffix = text1.substring( text1.length - commonlength );
2295
+ text1 = text1.substring( 0, text1.length - commonlength );
2296
+ text2 = text2.substring( 0, text2.length - commonlength );
2297
+
2298
+ // Compute the diff on the middle block.
2299
+ diffs = this.diffCompute( text1, text2, checklines, deadline );
2300
+
2301
+ // Restore the prefix and suffix.
2302
+ if ( commonprefix ) {
2303
+ diffs.unshift( [ DIFF_EQUAL, commonprefix ] );
2304
+ }
2305
+ if ( commonsuffix ) {
2306
+ diffs.push( [ DIFF_EQUAL, commonsuffix ] );
2307
+ }
2308
+ this.diffCleanupMerge( diffs );
2309
+ return diffs;
2310
+ };
2311
+
2312
+ /**
2313
+ * Reduce the number of edits by eliminating operationally trivial equalities.
2314
+ * @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples.
2315
+ */
2316
+ DiffMatchPatch.prototype.diffCleanupEfficiency = function( diffs ) {
2317
+ var changes, equalities, equalitiesLength, lastequality,
2318
+ pointer, preIns, preDel, postIns, postDel;
2319
+ changes = false;
2320
+ equalities = []; // Stack of indices where equalities are found.
2321
+ equalitiesLength = 0; // Keeping our own length var is faster in JS.
2322
+ /** @type {?string} */
2323
+ lastequality = null;
2324
+ // Always equal to diffs[equalities[equalitiesLength - 1]][1]
2325
+ pointer = 0; // Index of current position.
2326
+ // Is there an insertion operation before the last equality.
2327
+ preIns = false;
2328
+ // Is there a deletion operation before the last equality.
2329
+ preDel = false;
2330
+ // Is there an insertion operation after the last equality.
2331
+ postIns = false;
2332
+ // Is there a deletion operation after the last equality.
2333
+ postDel = false;
2334
+ while ( pointer < diffs.length ) {
2335
+
2336
+ // Equality found.
2337
+ if ( diffs[ pointer ][ 0 ] === DIFF_EQUAL ) {
2338
+ if ( diffs[ pointer ][ 1 ].length < 4 && ( postIns || postDel ) ) {
2339
+
2340
+ // Candidate found.
2341
+ equalities[ equalitiesLength++ ] = pointer;
2342
+ preIns = postIns;
2343
+ preDel = postDel;
2344
+ lastequality = diffs[ pointer ][ 1 ];
2345
+ } else {
2346
+
2347
+ // Not a candidate, and can never become one.
2348
+ equalitiesLength = 0;
2349
+ lastequality = null;
2350
+ }
2351
+ postIns = postDel = false;
2352
+
2353
+ // An insertion or deletion.
2354
+ } else {
2355
+
2356
+ if ( diffs[ pointer ][ 0 ] === DIFF_DELETE ) {
2357
+ postDel = true;
2358
+ } else {
2359
+ postIns = true;
2360
+ }
2361
+
2362
+ /*
2363
+ * Five types to be split:
2364
+ * <ins>A</ins><del>B</del>XY<ins>C</ins><del>D</del>
2365
+ * <ins>A</ins>X<ins>C</ins><del>D</del>
2366
+ * <ins>A</ins><del>B</del>X<ins>C</ins>
2367
+ * <ins>A</del>X<ins>C</ins><del>D</del>
2368
+ * <ins>A</ins><del>B</del>X<del>C</del>
2369
+ */
2370
+ if ( lastequality && ( ( preIns && preDel && postIns && postDel ) ||
2371
+ ( ( lastequality.length < 2 ) &&
2372
+ ( preIns + preDel + postIns + postDel ) === 3 ) ) ) {
2373
+
2374
+ // Duplicate record.
2375
+ diffs.splice(
2376
+ equalities[ equalitiesLength - 1 ],
2377
+ 0,
2378
+ [ DIFF_DELETE, lastequality ]
2379
+ );
2380
+
2381
+ // Change second copy to insert.
2382
+ diffs[ equalities[ equalitiesLength - 1 ] + 1 ][ 0 ] = DIFF_INSERT;
2383
+ equalitiesLength--; // Throw away the equality we just deleted;
2384
+ lastequality = null;
2385
+ if ( preIns && preDel ) {
2386
+ // No changes made which could affect previous entry, keep going.
2387
+ postIns = postDel = true;
2388
+ equalitiesLength = 0;
2389
+ } else {
2390
+ equalitiesLength--; // Throw away the previous equality.
2391
+ pointer = equalitiesLength > 0 ? equalities[ equalitiesLength - 1 ] : -1;
2392
+ postIns = postDel = false;
2393
+ }
2394
+ changes = true;
2395
+ }
2396
+ }
2397
+ pointer++;
2398
+ }
2399
+
2400
+ if ( changes ) {
2401
+ this.diffCleanupMerge( diffs );
2402
+ }
2403
+ };
2404
+
2405
+ /**
2406
+ * Convert a diff array into a pretty HTML report.
2407
+ * @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples.
2408
+ * @param {integer} string to be beautified.
2409
+ * @return {string} HTML representation.
2410
+ */
2411
+ DiffMatchPatch.prototype.diffPrettyHtml = function( diffs ) {
2412
+ var op, data, x,
2413
+ html = [];
2414
+ for ( x = 0; x < diffs.length; x++ ) {
2415
+ op = diffs[ x ][ 0 ]; // Operation (insert, delete, equal)
2416
+ data = diffs[ x ][ 1 ]; // Text of change.
2417
+ switch ( op ) {
2418
+ case DIFF_INSERT:
2419
+ html[ x ] = "<ins>" + data + "</ins>";
2420
+ break;
2421
+ case DIFF_DELETE:
2422
+ html[ x ] = "<del>" + data + "</del>";
2423
+ break;
2424
+ case DIFF_EQUAL:
2425
+ html[ x ] = "<span>" + data + "</span>";
2426
+ break;
2427
+ }
2428
+ }
2429
+ return html.join( "" );
2430
+ };
2431
+
2432
+ /**
2433
+ * Determine the common prefix of two strings.
2434
+ * @param {string} text1 First string.
2435
+ * @param {string} text2 Second string.
2436
+ * @return {number} The number of characters common to the start of each
2437
+ * string.
2438
+ */
2439
+ DiffMatchPatch.prototype.diffCommonPrefix = function( text1, text2 ) {
2440
+ var pointermid, pointermax, pointermin, pointerstart;
2441
+ // Quick check for common null cases.
2442
+ if ( !text1 || !text2 || text1.charAt( 0 ) !== text2.charAt( 0 ) ) {
2443
+ return 0;
2444
+ }
2445
+ // Binary search.
2446
+ // Performance analysis: http://neil.fraser.name/news/2007/10/09/
2447
+ pointermin = 0;
2448
+ pointermax = Math.min( text1.length, text2.length );
2449
+ pointermid = pointermax;
2450
+ pointerstart = 0;
2451
+ while ( pointermin < pointermid ) {
2452
+ if ( text1.substring( pointerstart, pointermid ) ===
2453
+ text2.substring( pointerstart, pointermid ) ) {
2454
+ pointermin = pointermid;
2455
+ pointerstart = pointermin;
2456
+ } else {
2457
+ pointermax = pointermid;
2458
+ }
2459
+ pointermid = Math.floor( ( pointermax - pointermin ) / 2 + pointermin );
2460
+ }
2461
+ return pointermid;
2462
+ };
2463
+
2464
+ /**
2465
+ * Determine the common suffix of two strings.
2466
+ * @param {string} text1 First string.
2467
+ * @param {string} text2 Second string.
2468
+ * @return {number} The number of characters common to the end of each string.
2469
+ */
2470
+ DiffMatchPatch.prototype.diffCommonSuffix = function( text1, text2 ) {
2471
+ var pointermid, pointermax, pointermin, pointerend;
2472
+ // Quick check for common null cases.
2473
+ if ( !text1 ||
2474
+ !text2 ||
2475
+ text1.charAt( text1.length - 1 ) !== text2.charAt( text2.length - 1 ) ) {
2476
+ return 0;
2477
+ }
2478
+ // Binary search.
2479
+ // Performance analysis: http://neil.fraser.name/news/2007/10/09/
2480
+ pointermin = 0;
2481
+ pointermax = Math.min( text1.length, text2.length );
2482
+ pointermid = pointermax;
2483
+ pointerend = 0;
2484
+ while ( pointermin < pointermid ) {
2485
+ if ( text1.substring( text1.length - pointermid, text1.length - pointerend ) ===
2486
+ text2.substring( text2.length - pointermid, text2.length - pointerend ) ) {
2487
+ pointermin = pointermid;
2488
+ pointerend = pointermin;
2489
+ } else {
2490
+ pointermax = pointermid;
2491
+ }
2492
+ pointermid = Math.floor( ( pointermax - pointermin ) / 2 + pointermin );
2493
+ }
2494
+ return pointermid;
2495
+ };
2496
+
2497
+ /**
2498
+ * Find the differences between two texts. Assumes that the texts do not
2499
+ * have any common prefix or suffix.
2500
+ * @param {string} text1 Old string to be diffed.
2501
+ * @param {string} text2 New string to be diffed.
2502
+ * @param {boolean} checklines Speedup flag. If false, then don't run a
2503
+ * line-level diff first to identify the changed areas.
2504
+ * If true, then run a faster, slightly less optimal diff.
2505
+ * @param {number} deadline Time when the diff should be complete by.
2506
+ * @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples.
2507
+ * @private
2508
+ */
2509
+ DiffMatchPatch.prototype.diffCompute = function( text1, text2, checklines, deadline ) {
2510
+ var diffs, longtext, shorttext, i, hm,
2511
+ text1A, text2A, text1B, text2B,
2512
+ midCommon, diffsA, diffsB;
2513
+
2514
+ if ( !text1 ) {
2515
+ // Just add some text (speedup).
2516
+ return [
2517
+ [ DIFF_INSERT, text2 ]
2518
+ ];
2519
+ }
2520
+
2521
+ if ( !text2 ) {
2522
+ // Just delete some text (speedup).
2523
+ return [
2524
+ [ DIFF_DELETE, text1 ]
2525
+ ];
2526
+ }
2527
+
2528
+ longtext = text1.length > text2.length ? text1 : text2;
2529
+ shorttext = text1.length > text2.length ? text2 : text1;
2530
+ i = longtext.indexOf( shorttext );
2531
+ if ( i !== -1 ) {
2532
+ // Shorter text is inside the longer text (speedup).
2533
+ diffs = [
2534
+ [ DIFF_INSERT, longtext.substring( 0, i ) ],
2535
+ [ DIFF_EQUAL, shorttext ],
2536
+ [ DIFF_INSERT, longtext.substring( i + shorttext.length ) ]
2537
+ ];
2538
+ // Swap insertions for deletions if diff is reversed.
2539
+ if ( text1.length > text2.length ) {
2540
+ diffs[ 0 ][ 0 ] = diffs[ 2 ][ 0 ] = DIFF_DELETE;
2541
+ }
2542
+ return diffs;
2543
+ }
2544
+
2545
+ if ( shorttext.length === 1 ) {
2546
+ // Single character string.
2547
+ // After the previous speedup, the character can't be an equality.
2548
+ return [
2549
+ [ DIFF_DELETE, text1 ],
2550
+ [ DIFF_INSERT, text2 ]
2551
+ ];
2552
+ }
2553
+
2554
+ // Check to see if the problem can be split in two.
2555
+ hm = this.diffHalfMatch( text1, text2 );
2556
+ if ( hm ) {
2557
+ // A half-match was found, sort out the return data.
2558
+ text1A = hm[ 0 ];
2559
+ text1B = hm[ 1 ];
2560
+ text2A = hm[ 2 ];
2561
+ text2B = hm[ 3 ];
2562
+ midCommon = hm[ 4 ];
2563
+ // Send both pairs off for separate processing.
2564
+ diffsA = this.DiffMain( text1A, text2A, checklines, deadline );
2565
+ diffsB = this.DiffMain( text1B, text2B, checklines, deadline );
2566
+ // Merge the results.
2567
+ return diffsA.concat( [
2568
+ [ DIFF_EQUAL, midCommon ]
2569
+ ], diffsB );
2570
+ }
2571
+
2572
+ if ( checklines && text1.length > 100 && text2.length > 100 ) {
2573
+ return this.diffLineMode( text1, text2, deadline );
2574
+ }
2575
+
2576
+ return this.diffBisect( text1, text2, deadline );
2577
+ };
2578
+
2579
+ /**
2580
+ * Do the two texts share a substring which is at least half the length of the
2581
+ * longer text?
2582
+ * This speedup can produce non-minimal diffs.
2583
+ * @param {string} text1 First string.
2584
+ * @param {string} text2 Second string.
2585
+ * @return {Array.<string>} Five element Array, containing the prefix of
2586
+ * text1, the suffix of text1, the prefix of text2, the suffix of
2587
+ * text2 and the common middle. Or null if there was no match.
2588
+ * @private
2589
+ */
2590
+ DiffMatchPatch.prototype.diffHalfMatch = function( text1, text2 ) {
2591
+ var longtext, shorttext, dmp,
2592
+ text1A, text2B, text2A, text1B, midCommon,
2593
+ hm1, hm2, hm;
2594
+
2595
+ longtext = text1.length > text2.length ? text1 : text2;
2596
+ shorttext = text1.length > text2.length ? text2 : text1;
2597
+ if ( longtext.length < 4 || shorttext.length * 2 < longtext.length ) {
2598
+ return null; // Pointless.
2599
+ }
2600
+ dmp = this; // 'this' becomes 'window' in a closure.
2601
+
2602
+ /**
2603
+ * Does a substring of shorttext exist within longtext such that the substring
2604
+ * is at least half the length of longtext?
2605
+ * Closure, but does not reference any external variables.
2606
+ * @param {string} longtext Longer string.
2607
+ * @param {string} shorttext Shorter string.
2608
+ * @param {number} i Start index of quarter length substring within longtext.
2609
+ * @return {Array.<string>} Five element Array, containing the prefix of
2610
+ * longtext, the suffix of longtext, the prefix of shorttext, the suffix
2611
+ * of shorttext and the common middle. Or null if there was no match.
2612
+ * @private
2613
+ */
2614
+ function diffHalfMatchI( longtext, shorttext, i ) {
2615
+ var seed, j, bestCommon, prefixLength, suffixLength,
2616
+ bestLongtextA, bestLongtextB, bestShorttextA, bestShorttextB;
2617
+ // Start with a 1/4 length substring at position i as a seed.
2618
+ seed = longtext.substring( i, i + Math.floor( longtext.length / 4 ) );
2619
+ j = -1;
2620
+ bestCommon = "";
2621
+ while ( ( j = shorttext.indexOf( seed, j + 1 ) ) !== -1 ) {
2622
+ prefixLength = dmp.diffCommonPrefix( longtext.substring( i ),
2623
+ shorttext.substring( j ) );
2624
+ suffixLength = dmp.diffCommonSuffix( longtext.substring( 0, i ),
2625
+ shorttext.substring( 0, j ) );
2626
+ if ( bestCommon.length < suffixLength + prefixLength ) {
2627
+ bestCommon = shorttext.substring( j - suffixLength, j ) +
2628
+ shorttext.substring( j, j + prefixLength );
2629
+ bestLongtextA = longtext.substring( 0, i - suffixLength );
2630
+ bestLongtextB = longtext.substring( i + prefixLength );
2631
+ bestShorttextA = shorttext.substring( 0, j - suffixLength );
2632
+ bestShorttextB = shorttext.substring( j + prefixLength );
2633
+ }
2634
+ }
2635
+ if ( bestCommon.length * 2 >= longtext.length ) {
2636
+ return [ bestLongtextA, bestLongtextB,
2637
+ bestShorttextA, bestShorttextB, bestCommon
2638
+ ];
2639
+ } else {
2640
+ return null;
2641
+ }
2642
+ }
2643
+
2644
+ // First check if the second quarter is the seed for a half-match.
2645
+ hm1 = diffHalfMatchI( longtext, shorttext,
2646
+ Math.ceil( longtext.length / 4 ) );
2647
+ // Check again based on the third quarter.
2648
+ hm2 = diffHalfMatchI( longtext, shorttext,
2649
+ Math.ceil( longtext.length / 2 ) );
2650
+ if ( !hm1 && !hm2 ) {
2651
+ return null;
2652
+ } else if ( !hm2 ) {
2653
+ hm = hm1;
2654
+ } else if ( !hm1 ) {
2655
+ hm = hm2;
2656
+ } else {
2657
+ // Both matched. Select the longest.
2658
+ hm = hm1[ 4 ].length > hm2[ 4 ].length ? hm1 : hm2;
2659
+ }
2660
+
2661
+ // A half-match was found, sort out the return data.
2662
+ text1A, text1B, text2A, text2B;
2663
+ if ( text1.length > text2.length ) {
2664
+ text1A = hm[ 0 ];
2665
+ text1B = hm[ 1 ];
2666
+ text2A = hm[ 2 ];
2667
+ text2B = hm[ 3 ];
2668
+ } else {
2669
+ text2A = hm[ 0 ];
2670
+ text2B = hm[ 1 ];
2671
+ text1A = hm[ 2 ];
2672
+ text1B = hm[ 3 ];
2673
+ }
2674
+ midCommon = hm[ 4 ];
2675
+ return [ text1A, text1B, text2A, text2B, midCommon ];
2676
+ };
2677
+
2678
+ /**
2679
+ * Do a quick line-level diff on both strings, then rediff the parts for
2680
+ * greater accuracy.
2681
+ * This speedup can produce non-minimal diffs.
2682
+ * @param {string} text1 Old string to be diffed.
2683
+ * @param {string} text2 New string to be diffed.
2684
+ * @param {number} deadline Time when the diff should be complete by.
2685
+ * @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples.
2686
+ * @private
2687
+ */
2688
+ DiffMatchPatch.prototype.diffLineMode = function( text1, text2, deadline ) {
2689
+ var a, diffs, linearray, pointer, countInsert,
2690
+ countDelete, textInsert, textDelete, j;
2691
+ // Scan the text on a line-by-line basis first.
2692
+ a = this.diffLinesToChars( text1, text2 );
2693
+ text1 = a.chars1;
2694
+ text2 = a.chars2;
2695
+ linearray = a.lineArray;
2696
+
2697
+ diffs = this.DiffMain( text1, text2, false, deadline );
2698
+
2699
+ // Convert the diff back to original text.
2700
+ this.diffCharsToLines( diffs, linearray );
2701
+ // Eliminate freak matches (e.g. blank lines)
2702
+ this.diffCleanupSemantic( diffs );
2703
+
2704
+ // Rediff any replacement blocks, this time character-by-character.
2705
+ // Add a dummy entry at the end.
2706
+ diffs.push( [ DIFF_EQUAL, "" ] );
2707
+ pointer = 0;
2708
+ countDelete = 0;
2709
+ countInsert = 0;
2710
+ textDelete = "";
2711
+ textInsert = "";
2712
+ while ( pointer < diffs.length ) {
2713
+ switch ( diffs[ pointer ][ 0 ] ) {
2714
+ case DIFF_INSERT:
2715
+ countInsert++;
2716
+ textInsert += diffs[ pointer ][ 1 ];
2717
+ break;
2718
+ case DIFF_DELETE:
2719
+ countDelete++;
2720
+ textDelete += diffs[ pointer ][ 1 ];
2721
+ break;
2722
+ case DIFF_EQUAL:
2723
+ // Upon reaching an equality, check for prior redundancies.
2724
+ if ( countDelete >= 1 && countInsert >= 1 ) {
2725
+ // Delete the offending records and add the merged ones.
2726
+ diffs.splice( pointer - countDelete - countInsert,
2727
+ countDelete + countInsert );
2728
+ pointer = pointer - countDelete - countInsert;
2729
+ a = this.DiffMain( textDelete, textInsert, false, deadline );
2730
+ for ( j = a.length - 1; j >= 0; j-- ) {
2731
+ diffs.splice( pointer, 0, a[ j ] );
2732
+ }
2733
+ pointer = pointer + a.length;
2734
+ }
2735
+ countInsert = 0;
2736
+ countDelete = 0;
2737
+ textDelete = "";
2738
+ textInsert = "";
2739
+ break;
2740
+ }
2741
+ pointer++;
2742
+ }
2743
+ diffs.pop(); // Remove the dummy entry at the end.
2744
+
2745
+ return diffs;
2746
+ };
2747
+
2748
+ /**
2749
+ * Find the 'middle snake' of a diff, split the problem in two
2750
+ * and return the recursively constructed diff.
2751
+ * See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.
2752
+ * @param {string} text1 Old string to be diffed.
2753
+ * @param {string} text2 New string to be diffed.
2754
+ * @param {number} deadline Time at which to bail if not yet complete.
2755
+ * @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples.
2756
+ * @private
2757
+ */
2758
+ DiffMatchPatch.prototype.diffBisect = function( text1, text2, deadline ) {
2759
+ var text1Length, text2Length, maxD, vOffset, vLength,
2760
+ v1, v2, x, delta, front, k1start, k1end, k2start,
2761
+ k2end, k2Offset, k1Offset, x1, x2, y1, y2, d, k1, k2;
2762
+ // Cache the text lengths to prevent multiple calls.
2763
+ text1Length = text1.length;
2764
+ text2Length = text2.length;
2765
+ maxD = Math.ceil( ( text1Length + text2Length ) / 2 );
2766
+ vOffset = maxD;
2767
+ vLength = 2 * maxD;
2768
+ v1 = new Array( vLength );
2769
+ v2 = new Array( vLength );
2770
+ // Setting all elements to -1 is faster in Chrome & Firefox than mixing
2771
+ // integers and undefined.
2772
+ for ( x = 0; x < vLength; x++ ) {
2773
+ v1[ x ] = -1;
2774
+ v2[ x ] = -1;
2775
+ }
2776
+ v1[ vOffset + 1 ] = 0;
2777
+ v2[ vOffset + 1 ] = 0;
2778
+ delta = text1Length - text2Length;
2779
+ // If the total number of characters is odd, then the front path will collide
2780
+ // with the reverse path.
2781
+ front = ( delta % 2 !== 0 );
2782
+ // Offsets for start and end of k loop.
2783
+ // Prevents mapping of space beyond the grid.
2784
+ k1start = 0;
2785
+ k1end = 0;
2786
+ k2start = 0;
2787
+ k2end = 0;
2788
+ for ( d = 0; d < maxD; d++ ) {
2789
+ // Bail out if deadline is reached.
2790
+ if ( ( new Date() ).getTime() > deadline ) {
2791
+ break;
2792
+ }
2793
+
2794
+ // Walk the front path one step.
2795
+ for ( k1 = -d + k1start; k1 <= d - k1end; k1 += 2 ) {
2796
+ k1Offset = vOffset + k1;
2797
+ if ( k1 === -d || ( k1 !== d && v1[ k1Offset - 1 ] < v1[ k1Offset + 1 ] ) ) {
2798
+ x1 = v1[ k1Offset + 1 ];
2799
+ } else {
2800
+ x1 = v1[ k1Offset - 1 ] + 1;
2801
+ }
2802
+ y1 = x1 - k1;
2803
+ while ( x1 < text1Length && y1 < text2Length &&
2804
+ text1.charAt( x1 ) === text2.charAt( y1 ) ) {
2805
+ x1++;
2806
+ y1++;
2807
+ }
2808
+ v1[ k1Offset ] = x1;
2809
+ if ( x1 > text1Length ) {
2810
+ // Ran off the right of the graph.
2811
+ k1end += 2;
2812
+ } else if ( y1 > text2Length ) {
2813
+ // Ran off the bottom of the graph.
2814
+ k1start += 2;
2815
+ } else if ( front ) {
2816
+ k2Offset = vOffset + delta - k1;
2817
+ if ( k2Offset >= 0 && k2Offset < vLength && v2[ k2Offset ] !== -1 ) {
2818
+ // Mirror x2 onto top-left coordinate system.
2819
+ x2 = text1Length - v2[ k2Offset ];
2820
+ if ( x1 >= x2 ) {
2821
+ // Overlap detected.
2822
+ return this.diffBisectSplit( text1, text2, x1, y1, deadline );
2823
+ }
2824
+ }
2825
+ }
2826
+ }
2827
+
2828
+ // Walk the reverse path one step.
2829
+ for ( k2 = -d + k2start; k2 <= d - k2end; k2 += 2 ) {
2830
+ k2Offset = vOffset + k2;
2831
+ if ( k2 === -d || ( k2 !== d && v2[ k2Offset - 1 ] < v2[ k2Offset + 1 ] ) ) {
2832
+ x2 = v2[ k2Offset + 1 ];
2833
+ } else {
2834
+ x2 = v2[ k2Offset - 1 ] + 1;
2835
+ }
2836
+ y2 = x2 - k2;
2837
+ while ( x2 < text1Length && y2 < text2Length &&
2838
+ text1.charAt( text1Length - x2 - 1 ) ===
2839
+ text2.charAt( text2Length - y2 - 1 ) ) {
2840
+ x2++;
2841
+ y2++;
2842
+ }
2843
+ v2[ k2Offset ] = x2;
2844
+ if ( x2 > text1Length ) {
2845
+ // Ran off the left of the graph.
2846
+ k2end += 2;
2847
+ } else if ( y2 > text2Length ) {
2848
+ // Ran off the top of the graph.
2849
+ k2start += 2;
2850
+ } else if ( !front ) {
2851
+ k1Offset = vOffset + delta - k2;
2852
+ if ( k1Offset >= 0 && k1Offset < vLength && v1[ k1Offset ] !== -1 ) {
2853
+ x1 = v1[ k1Offset ];
2854
+ y1 = vOffset + x1 - k1Offset;
2855
+ // Mirror x2 onto top-left coordinate system.
2856
+ x2 = text1Length - x2;
2857
+ if ( x1 >= x2 ) {
2858
+ // Overlap detected.
2859
+ return this.diffBisectSplit( text1, text2, x1, y1, deadline );
2860
+ }
2861
+ }
2862
+ }
2863
+ }
2864
+ }
2865
+ // Diff took too long and hit the deadline or
2866
+ // number of diffs equals number of characters, no commonality at all.
2867
+ return [
2868
+ [ DIFF_DELETE, text1 ],
2869
+ [ DIFF_INSERT, text2 ]
2870
+ ];
2871
+ };
2872
+
2873
+ /**
2874
+ * Given the location of the 'middle snake', split the diff in two parts
2875
+ * and recurse.
2876
+ * @param {string} text1 Old string to be diffed.
2877
+ * @param {string} text2 New string to be diffed.
2878
+ * @param {number} x Index of split point in text1.
2879
+ * @param {number} y Index of split point in text2.
2880
+ * @param {number} deadline Time at which to bail if not yet complete.
2881
+ * @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples.
2882
+ * @private
2883
+ */
2884
+ DiffMatchPatch.prototype.diffBisectSplit = function( text1, text2, x, y, deadline ) {
2885
+ var text1a, text1b, text2a, text2b, diffs, diffsb;
2886
+ text1a = text1.substring( 0, x );
2887
+ text2a = text2.substring( 0, y );
2888
+ text1b = text1.substring( x );
2889
+ text2b = text2.substring( y );
2890
+
2891
+ // Compute both diffs serially.
2892
+ diffs = this.DiffMain( text1a, text2a, false, deadline );
2893
+ diffsb = this.DiffMain( text1b, text2b, false, deadline );
2894
+
2895
+ return diffs.concat( diffsb );
2896
+ };
2897
+
2898
+ /**
2899
+ * Reduce the number of edits by eliminating semantically trivial equalities.
2900
+ * @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples.
2901
+ */
2902
+ DiffMatchPatch.prototype.diffCleanupSemantic = function( diffs ) {
2903
+ var changes, equalities, equalitiesLength, lastequality,
2904
+ pointer, lengthInsertions2, lengthDeletions2, lengthInsertions1,
2905
+ lengthDeletions1, deletion, insertion, overlapLength1, overlapLength2;
2906
+ changes = false;
2907
+ equalities = []; // Stack of indices where equalities are found.
2908
+ equalitiesLength = 0; // Keeping our own length var is faster in JS.
2909
+ /** @type {?string} */
2910
+ lastequality = null;
2911
+ // Always equal to diffs[equalities[equalitiesLength - 1]][1]
2912
+ pointer = 0; // Index of current position.
2913
+ // Number of characters that changed prior to the equality.
2914
+ lengthInsertions1 = 0;
2915
+ lengthDeletions1 = 0;
2916
+ // Number of characters that changed after the equality.
2917
+ lengthInsertions2 = 0;
2918
+ lengthDeletions2 = 0;
2919
+ while ( pointer < diffs.length ) {
2920
+ if ( diffs[ pointer ][ 0 ] === DIFF_EQUAL ) { // Equality found.
2921
+ equalities[ equalitiesLength++ ] = pointer;
2922
+ lengthInsertions1 = lengthInsertions2;
2923
+ lengthDeletions1 = lengthDeletions2;
2924
+ lengthInsertions2 = 0;
2925
+ lengthDeletions2 = 0;
2926
+ lastequality = diffs[ pointer ][ 1 ];
2927
+ } else { // An insertion or deletion.
2928
+ if ( diffs[ pointer ][ 0 ] === DIFF_INSERT ) {
2929
+ lengthInsertions2 += diffs[ pointer ][ 1 ].length;
2930
+ } else {
2931
+ lengthDeletions2 += diffs[ pointer ][ 1 ].length;
2932
+ }
2933
+ // Eliminate an equality that is smaller or equal to the edits on both
2934
+ // sides of it.
2935
+ if ( lastequality && ( lastequality.length <=
2936
+ Math.max( lengthInsertions1, lengthDeletions1 ) ) &&
2937
+ ( lastequality.length <= Math.max( lengthInsertions2,
2938
+ lengthDeletions2 ) ) ) {
2939
+
2940
+ // Duplicate record.
2941
+ diffs.splice(
2942
+ equalities[ equalitiesLength - 1 ],
2943
+ 0,
2944
+ [ DIFF_DELETE, lastequality ]
2945
+ );
2946
+
2947
+ // Change second copy to insert.
2948
+ diffs[ equalities[ equalitiesLength - 1 ] + 1 ][ 0 ] = DIFF_INSERT;
2949
+
2950
+ // Throw away the equality we just deleted.
2951
+ equalitiesLength--;
2952
+
2953
+ // Throw away the previous equality (it needs to be reevaluated).
2954
+ equalitiesLength--;
2955
+ pointer = equalitiesLength > 0 ? equalities[ equalitiesLength - 1 ] : -1;
2956
+
2957
+ // Reset the counters.
2958
+ lengthInsertions1 = 0;
2959
+ lengthDeletions1 = 0;
2960
+ lengthInsertions2 = 0;
2961
+ lengthDeletions2 = 0;
2962
+ lastequality = null;
2963
+ changes = true;
2964
+ }
2965
+ }
2966
+ pointer++;
2967
+ }
2968
+
2969
+ // Normalize the diff.
2970
+ if ( changes ) {
2971
+ this.diffCleanupMerge( diffs );
2972
+ }
2973
+
2974
+ // Find any overlaps between deletions and insertions.
2975
+ // e.g: <del>abcxxx</del><ins>xxxdef</ins>
2976
+ // -> <del>abc</del>xxx<ins>def</ins>
2977
+ // e.g: <del>xxxabc</del><ins>defxxx</ins>
2978
+ // -> <ins>def</ins>xxx<del>abc</del>
2979
+ // Only extract an overlap if it is as big as the edit ahead or behind it.
2980
+ pointer = 1;
2981
+ while ( pointer < diffs.length ) {
2982
+ if ( diffs[ pointer - 1 ][ 0 ] === DIFF_DELETE &&
2983
+ diffs[ pointer ][ 0 ] === DIFF_INSERT ) {
2984
+ deletion = diffs[ pointer - 1 ][ 1 ];
2985
+ insertion = diffs[ pointer ][ 1 ];
2986
+ overlapLength1 = this.diffCommonOverlap( deletion, insertion );
2987
+ overlapLength2 = this.diffCommonOverlap( insertion, deletion );
2988
+ if ( overlapLength1 >= overlapLength2 ) {
2989
+ if ( overlapLength1 >= deletion.length / 2 ||
2990
+ overlapLength1 >= insertion.length / 2 ) {
2991
+ // Overlap found. Insert an equality and trim the surrounding edits.
2992
+ diffs.splice(
2993
+ pointer,
2994
+ 0,
2995
+ [ DIFF_EQUAL, insertion.substring( 0, overlapLength1 ) ]
2996
+ );
2997
+ diffs[ pointer - 1 ][ 1 ] =
2998
+ deletion.substring( 0, deletion.length - overlapLength1 );
2999
+ diffs[ pointer + 1 ][ 1 ] = insertion.substring( overlapLength1 );
3000
+ pointer++;
3001
+ }
3002
+ } else {
3003
+ if ( overlapLength2 >= deletion.length / 2 ||
3004
+ overlapLength2 >= insertion.length / 2 ) {
3005
+
3006
+ // Reverse overlap found.
3007
+ // Insert an equality and swap and trim the surrounding edits.
3008
+ diffs.splice(
3009
+ pointer,
3010
+ 0,
3011
+ [ DIFF_EQUAL, deletion.substring( 0, overlapLength2 ) ]
3012
+ );
3013
+
3014
+ diffs[ pointer - 1 ][ 0 ] = DIFF_INSERT;
3015
+ diffs[ pointer - 1 ][ 1 ] =
3016
+ insertion.substring( 0, insertion.length - overlapLength2 );
3017
+ diffs[ pointer + 1 ][ 0 ] = DIFF_DELETE;
3018
+ diffs[ pointer + 1 ][ 1 ] =
3019
+ deletion.substring( overlapLength2 );
3020
+ pointer++;
3021
+ }
3022
+ }
3023
+ pointer++;
3024
+ }
3025
+ pointer++;
3026
+ }
3027
+ };
3028
+
3029
+ /**
3030
+ * Determine if the suffix of one string is the prefix of another.
3031
+ * @param {string} text1 First string.
3032
+ * @param {string} text2 Second string.
3033
+ * @return {number} The number of characters common to the end of the first
3034
+ * string and the start of the second string.
3035
+ * @private
3036
+ */
3037
+ DiffMatchPatch.prototype.diffCommonOverlap = function( text1, text2 ) {
3038
+ var text1Length, text2Length, textLength,
3039
+ best, length, pattern, found;
3040
+ // Cache the text lengths to prevent multiple calls.
3041
+ text1Length = text1.length;
3042
+ text2Length = text2.length;
3043
+ // Eliminate the null case.
3044
+ if ( text1Length === 0 || text2Length === 0 ) {
3045
+ return 0;
3046
+ }
3047
+ // Truncate the longer string.
3048
+ if ( text1Length > text2Length ) {
3049
+ text1 = text1.substring( text1Length - text2Length );
3050
+ } else if ( text1Length < text2Length ) {
3051
+ text2 = text2.substring( 0, text1Length );
3052
+ }
3053
+ textLength = Math.min( text1Length, text2Length );
3054
+ // Quick check for the worst case.
3055
+ if ( text1 === text2 ) {
3056
+ return textLength;
3057
+ }
3058
+
3059
+ // Start by looking for a single character match
3060
+ // and increase length until no match is found.
3061
+ // Performance analysis: http://neil.fraser.name/news/2010/11/04/
3062
+ best = 0;
3063
+ length = 1;
3064
+ while ( true ) {
3065
+ pattern = text1.substring( textLength - length );
3066
+ found = text2.indexOf( pattern );
3067
+ if ( found === -1 ) {
3068
+ return best;
3069
+ }
3070
+ length += found;
3071
+ if ( found === 0 || text1.substring( textLength - length ) ===
3072
+ text2.substring( 0, length ) ) {
3073
+ best = length;
3074
+ length++;
3075
+ }
3076
+ }
3077
+ };
3078
+
3079
+ /**
3080
+ * Split two texts into an array of strings. Reduce the texts to a string of
3081
+ * hashes where each Unicode character represents one line.
3082
+ * @param {string} text1 First string.
3083
+ * @param {string} text2 Second string.
3084
+ * @return {{chars1: string, chars2: string, lineArray: !Array.<string>}}
3085
+ * An object containing the encoded text1, the encoded text2 and
3086
+ * the array of unique strings.
3087
+ * The zeroth element of the array of unique strings is intentionally blank.
3088
+ * @private
3089
+ */
3090
+ DiffMatchPatch.prototype.diffLinesToChars = function( text1, text2 ) {
3091
+ var lineArray, lineHash, chars1, chars2;
3092
+ lineArray = []; // e.g. lineArray[4] === 'Hello\n'
3093
+ lineHash = {}; // e.g. lineHash['Hello\n'] === 4
3094
+
3095
+ // '\x00' is a valid character, but various debuggers don't like it.
3096
+ // So we'll insert a junk entry to avoid generating a null character.
3097
+ lineArray[ 0 ] = "";
3098
+
3099
+ /**
3100
+ * Split a text into an array of strings. Reduce the texts to a string of
3101
+ * hashes where each Unicode character represents one line.
3102
+ * Modifies linearray and linehash through being a closure.
3103
+ * @param {string} text String to encode.
3104
+ * @return {string} Encoded string.
3105
+ * @private
3106
+ */
3107
+ function diffLinesToCharsMunge( text ) {
3108
+ var chars, lineStart, lineEnd, lineArrayLength, line;
3109
+ chars = "";
3110
+ // Walk the text, pulling out a substring for each line.
3111
+ // text.split('\n') would would temporarily double our memory footprint.
3112
+ // Modifying text would create many large strings to garbage collect.
3113
+ lineStart = 0;
3114
+ lineEnd = -1;
3115
+ // Keeping our own length variable is faster than looking it up.
3116
+ lineArrayLength = lineArray.length;
3117
+ while ( lineEnd < text.length - 1 ) {
3118
+ lineEnd = text.indexOf( "\n", lineStart );
3119
+ if ( lineEnd === -1 ) {
3120
+ lineEnd = text.length - 1;
3121
+ }
3122
+ line = text.substring( lineStart, lineEnd + 1 );
3123
+ lineStart = lineEnd + 1;
3124
+
3125
+ if ( lineHash.hasOwnProperty ? lineHash.hasOwnProperty( line ) :
3126
+ ( lineHash[ line ] !== undefined ) ) {
3127
+ chars += String.fromCharCode( lineHash[ line ] );
3128
+ } else {
3129
+ chars += String.fromCharCode( lineArrayLength );
3130
+ lineHash[ line ] = lineArrayLength;
3131
+ lineArray[ lineArrayLength++ ] = line;
3132
+ }
3133
+ }
3134
+ return chars;
3135
+ }
3136
+
3137
+ chars1 = diffLinesToCharsMunge( text1 );
3138
+ chars2 = diffLinesToCharsMunge( text2 );
3139
+ return {
3140
+ chars1: chars1,
3141
+ chars2: chars2,
3142
+ lineArray: lineArray
3143
+ };
3144
+ };
3145
+
3146
+ /**
3147
+ * Rehydrate the text in a diff from a string of line hashes to real lines of
3148
+ * text.
3149
+ * @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples.
3150
+ * @param {!Array.<string>} lineArray Array of unique strings.
3151
+ * @private
3152
+ */
3153
+ DiffMatchPatch.prototype.diffCharsToLines = function( diffs, lineArray ) {
3154
+ var x, chars, text, y;
3155
+ for ( x = 0; x < diffs.length; x++ ) {
3156
+ chars = diffs[ x ][ 1 ];
3157
+ text = [];
3158
+ for ( y = 0; y < chars.length; y++ ) {
3159
+ text[ y ] = lineArray[ chars.charCodeAt( y ) ];
3160
+ }
3161
+ diffs[ x ][ 1 ] = text.join( "" );
3162
+ }
3163
+ };
3164
+
3165
+ /**
3166
+ * Reorder and merge like edit sections. Merge equalities.
3167
+ * Any edit section can move as long as it doesn't cross an equality.
3168
+ * @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples.
3169
+ */
3170
+ DiffMatchPatch.prototype.diffCleanupMerge = function( diffs ) {
3171
+ var pointer, countDelete, countInsert, textInsert, textDelete,
3172
+ commonlength, changes, diffPointer, position;
3173
+ diffs.push( [ DIFF_EQUAL, "" ] ); // Add a dummy entry at the end.
3174
+ pointer = 0;
3175
+ countDelete = 0;
3176
+ countInsert = 0;
3177
+ textDelete = "";
3178
+ textInsert = "";
3179
+ commonlength;
3180
+ while ( pointer < diffs.length ) {
3181
+ switch ( diffs[ pointer ][ 0 ] ) {
3182
+ case DIFF_INSERT:
3183
+ countInsert++;
3184
+ textInsert += diffs[ pointer ][ 1 ];
3185
+ pointer++;
3186
+ break;
3187
+ case DIFF_DELETE:
3188
+ countDelete++;
3189
+ textDelete += diffs[ pointer ][ 1 ];
3190
+ pointer++;
3191
+ break;
3192
+ case DIFF_EQUAL:
3193
+ // Upon reaching an equality, check for prior redundancies.
3194
+ if ( countDelete + countInsert > 1 ) {
3195
+ if ( countDelete !== 0 && countInsert !== 0 ) {
3196
+ // Factor out any common prefixies.
3197
+ commonlength = this.diffCommonPrefix( textInsert, textDelete );
3198
+ if ( commonlength !== 0 ) {
3199
+ if ( ( pointer - countDelete - countInsert ) > 0 &&
3200
+ diffs[ pointer - countDelete - countInsert - 1 ][ 0 ] ===
3201
+ DIFF_EQUAL ) {
3202
+ diffs[ pointer - countDelete - countInsert - 1 ][ 1 ] +=
3203
+ textInsert.substring( 0, commonlength );
3204
+ } else {
3205
+ diffs.splice( 0, 0, [ DIFF_EQUAL,
3206
+ textInsert.substring( 0, commonlength )
3207
+ ] );
3208
+ pointer++;
3209
+ }
3210
+ textInsert = textInsert.substring( commonlength );
3211
+ textDelete = textDelete.substring( commonlength );
3212
+ }
3213
+ // Factor out any common suffixies.
3214
+ commonlength = this.diffCommonSuffix( textInsert, textDelete );
3215
+ if ( commonlength !== 0 ) {
3216
+ diffs[ pointer ][ 1 ] = textInsert.substring( textInsert.length -
3217
+ commonlength ) + diffs[ pointer ][ 1 ];
3218
+ textInsert = textInsert.substring( 0, textInsert.length -
3219
+ commonlength );
3220
+ textDelete = textDelete.substring( 0, textDelete.length -
3221
+ commonlength );
3222
+ }
3223
+ }
3224
+ // Delete the offending records and add the merged ones.
3225
+ if ( countDelete === 0 ) {
3226
+ diffs.splice( pointer - countInsert,
3227
+ countDelete + countInsert, [ DIFF_INSERT, textInsert ] );
3228
+ } else if ( countInsert === 0 ) {
3229
+ diffs.splice( pointer - countDelete,
3230
+ countDelete + countInsert, [ DIFF_DELETE, textDelete ] );
3231
+ } else {
3232
+ diffs.splice(
3233
+ pointer - countDelete - countInsert,
3234
+ countDelete + countInsert,
3235
+ [ DIFF_DELETE, textDelete ], [ DIFF_INSERT, textInsert ]
3236
+ );
3237
+ }
3238
+ pointer = pointer - countDelete - countInsert +
3239
+ ( countDelete ? 1 : 0 ) + ( countInsert ? 1 : 0 ) + 1;
3240
+ } else if ( pointer !== 0 && diffs[ pointer - 1 ][ 0 ] === DIFF_EQUAL ) {
3241
+
3242
+ // Merge this equality with the previous one.
3243
+ diffs[ pointer - 1 ][ 1 ] += diffs[ pointer ][ 1 ];
3244
+ diffs.splice( pointer, 1 );
3245
+ } else {
3246
+ pointer++;
3247
+ }
3248
+ countInsert = 0;
3249
+ countDelete = 0;
3250
+ textDelete = "";
3251
+ textInsert = "";
3252
+ break;
3253
+ }
3254
+ }
3255
+ if ( diffs[ diffs.length - 1 ][ 1 ] === "" ) {
3256
+ diffs.pop(); // Remove the dummy entry at the end.
3257
+ }
3258
+
3259
+ // Second pass: look for single edits surrounded on both sides by equalities
3260
+ // which can be shifted sideways to eliminate an equality.
3261
+ // e.g: A<ins>BA</ins>C -> <ins>AB</ins>AC
3262
+ changes = false;
3263
+ pointer = 1;
3264
+
3265
+ // Intentionally ignore the first and last element (don't need checking).
3266
+ while ( pointer < diffs.length - 1 ) {
3267
+ if ( diffs[ pointer - 1 ][ 0 ] === DIFF_EQUAL &&
3268
+ diffs[ pointer + 1 ][ 0 ] === DIFF_EQUAL ) {
3269
+
3270
+ diffPointer = diffs[ pointer ][ 1 ];
3271
+ position = diffPointer.substring(
3272
+ diffPointer.length - diffs[ pointer - 1 ][ 1 ].length
3273
+ );
3274
+
3275
+ // This is a single edit surrounded by equalities.
3276
+ if ( position === diffs[ pointer - 1 ][ 1 ] ) {
3277
+
3278
+ // Shift the edit over the previous equality.
3279
+ diffs[ pointer ][ 1 ] = diffs[ pointer - 1 ][ 1 ] +
3280
+ diffs[ pointer ][ 1 ].substring( 0, diffs[ pointer ][ 1 ].length -
3281
+ diffs[ pointer - 1 ][ 1 ].length );
3282
+ diffs[ pointer + 1 ][ 1 ] =
3283
+ diffs[ pointer - 1 ][ 1 ] + diffs[ pointer + 1 ][ 1 ];
3284
+ diffs.splice( pointer - 1, 1 );
3285
+ changes = true;
3286
+ } else if ( diffPointer.substring( 0, diffs[ pointer + 1 ][ 1 ].length ) ===
3287
+ diffs[ pointer + 1 ][ 1 ] ) {
3288
+
3289
+ // Shift the edit over the next equality.
3290
+ diffs[ pointer - 1 ][ 1 ] += diffs[ pointer + 1 ][ 1 ];
3291
+ diffs[ pointer ][ 1 ] =
3292
+ diffs[ pointer ][ 1 ].substring( diffs[ pointer + 1 ][ 1 ].length ) +
3293
+ diffs[ pointer + 1 ][ 1 ];
3294
+ diffs.splice( pointer + 1, 1 );
3295
+ changes = true;
3296
+ }
3297
+ }
3298
+ pointer++;
3299
+ }
3300
+ // If shifts were made, the diff needs reordering and another shift sweep.
3301
+ if ( changes ) {
3302
+ this.diffCleanupMerge( diffs );
3303
+ }
3304
+ };
3305
+
3306
+ return function( o, n ) {
3307
+ var diff, output, text;
3308
+ diff = new DiffMatchPatch();
3309
+ output = diff.DiffMain( o, n );
3310
+ diff.diffCleanupEfficiency( output );
3311
+ text = diff.diffPrettyHtml( output );
3312
+
3313
+ return text;
3314
+ };
3315
+ }() );
3316
+
3317
+ // Get a reference to the global object, like window in browsers
3318
+ }( (function() {
3319
+ return this;
3320
+ })() ));
3321
+
3322
+ (function() {
3323
+
3324
+ // Don't load the HTML Reporter on non-Browser environments
3325
+ if ( typeof window === "undefined" || !window.document ) {
3326
+ return;
3327
+ }
3328
+
3329
+ // Deprecated QUnit.init - Ref #530
3330
+ // Re-initialize the configuration options
3331
+ QUnit.init = function() {
3332
+ var tests, banner, result, qunit,
3333
+ config = QUnit.config;
3334
+
3335
+ config.stats = { all: 0, bad: 0 };
3336
+ config.moduleStats = { all: 0, bad: 0 };
3337
+ config.started = 0;
3338
+ config.updateRate = 1000;
3339
+ config.blocking = false;
3340
+ config.autostart = true;
3341
+ config.autorun = false;
3342
+ config.filter = "";
3343
+ config.queue = [];
3344
+
3345
+ // Return on non-browser environments
3346
+ // This is necessary to not break on node tests
3347
+ if ( typeof window === "undefined" ) {
3348
+ return;
3349
+ }
3350
+
3351
+ qunit = id( "qunit" );
3352
+ if ( qunit ) {
3353
+ qunit.innerHTML =
3354
+ "<h1 id='qunit-header'>" + escapeText( document.title ) + "</h1>" +
3355
+ "<h2 id='qunit-banner'></h2>" +
3356
+ "<div id='qunit-testrunner-toolbar'></div>" +
3357
+ "<h2 id='qunit-userAgent'></h2>" +
3358
+ "<ol id='qunit-tests'></ol>";
3359
+ }
3360
+
3361
+ tests = id( "qunit-tests" );
3362
+ banner = id( "qunit-banner" );
3363
+ result = id( "qunit-testresult" );
3364
+
3365
+ if ( tests ) {
3366
+ tests.innerHTML = "";
3367
+ }
3368
+
3369
+ if ( banner ) {
3370
+ banner.className = "";
3371
+ }
3372
+
3373
+ if ( result ) {
3374
+ result.parentNode.removeChild( result );
3375
+ }
3376
+
3377
+ if ( tests ) {
3378
+ result = document.createElement( "p" );
3379
+ result.id = "qunit-testresult";
3380
+ result.className = "result";
3381
+ tests.parentNode.insertBefore( result, tests );
3382
+ result.innerHTML = "Running...<br />&#160;";
3383
+ }
3384
+ };
3385
+
3386
+ var config = QUnit.config,
3387
+ collapseNext = false,
3388
+ hasOwn = Object.prototype.hasOwnProperty,
3389
+ defined = {
3390
+ document: window.document !== undefined,
3391
+ sessionStorage: (function() {
3392
+ var x = "qunit-test-string";
3393
+ try {
3394
+ sessionStorage.setItem( x, x );
3395
+ sessionStorage.removeItem( x );
3396
+ return true;
3397
+ } catch ( e ) {
3398
+ return false;
3399
+ }
3400
+ }())
3401
+ },
3402
+ modulesList = [];
3403
+
3404
+ /**
3405
+ * Escape text for attribute or text content.
3406
+ */
3407
+ function escapeText( s ) {
3408
+ if ( !s ) {
3409
+ return "";
3410
+ }
3411
+ s = s + "";
3412
+
3413
+ // Both single quotes and double quotes (for attributes)
3414
+ return s.replace( /['"<>&]/g, function( s ) {
3415
+ switch ( s ) {
3416
+ case "'":
3417
+ return "&#039;";
3418
+ case "\"":
3419
+ return "&quot;";
3420
+ case "<":
3421
+ return "&lt;";
3422
+ case ">":
3423
+ return "&gt;";
3424
+ case "&":
3425
+ return "&amp;";
3426
+ }
3427
+ });
3428
+ }
3429
+
3430
+ /**
3431
+ * @param {HTMLElement} elem
3432
+ * @param {string} type
3433
+ * @param {Function} fn
3434
+ */
3435
+ function addEvent( elem, type, fn ) {
3436
+ if ( elem.addEventListener ) {
3437
+
3438
+ // Standards-based browsers
3439
+ elem.addEventListener( type, fn, false );
3440
+ } else if ( elem.attachEvent ) {
3441
+
3442
+ // support: IE <9
3443
+ elem.attachEvent( "on" + type, function() {
3444
+ var event = window.event;
3445
+ if ( !event.target ) {
3446
+ event.target = event.srcElement || document;
3447
+ }
3448
+
3449
+ fn.call( elem, event );
3450
+ });
3451
+ }
3452
+ }
3453
+
3454
+ /**
3455
+ * @param {Array|NodeList} elems
3456
+ * @param {string} type
3457
+ * @param {Function} fn
3458
+ */
3459
+ function addEvents( elems, type, fn ) {
3460
+ var i = elems.length;
3461
+ while ( i-- ) {
3462
+ addEvent( elems[ i ], type, fn );
3463
+ }
3464
+ }
3465
+
3466
+ function hasClass( elem, name ) {
3467
+ return ( " " + elem.className + " " ).indexOf( " " + name + " " ) >= 0;
3468
+ }
3469
+
3470
+ function addClass( elem, name ) {
3471
+ if ( !hasClass( elem, name ) ) {
3472
+ elem.className += ( elem.className ? " " : "" ) + name;
3473
+ }
3474
+ }
3475
+
3476
+ function toggleClass( elem, name ) {
3477
+ if ( hasClass( elem, name ) ) {
3478
+ removeClass( elem, name );
3479
+ } else {
3480
+ addClass( elem, name );
3481
+ }
3482
+ }
3483
+
3484
+ function removeClass( elem, name ) {
3485
+ var set = " " + elem.className + " ";
3486
+
3487
+ // Class name may appear multiple times
3488
+ while ( set.indexOf( " " + name + " " ) >= 0 ) {
3489
+ set = set.replace( " " + name + " ", " " );
3490
+ }
3491
+
3492
+ // trim for prettiness
3493
+ elem.className = typeof set.trim === "function" ? set.trim() : set.replace( /^\s+|\s+$/g, "" );
3494
+ }
3495
+
3496
+ function id( name ) {
3497
+ return defined.document && document.getElementById && document.getElementById( name );
3498
+ }
3499
+
3500
+ function getUrlConfigHtml() {
3501
+ var i, j, val,
3502
+ escaped, escapedTooltip,
3503
+ selection = false,
3504
+ len = config.urlConfig.length,
3505
+ urlConfigHtml = "";
3506
+
3507
+ for ( i = 0; i < len; i++ ) {
3508
+ val = config.urlConfig[ i ];
3509
+ if ( typeof val === "string" ) {
3510
+ val = {
3511
+ id: val,
3512
+ label: val
3513
+ };
3514
+ }
3515
+
3516
+ escaped = escapeText( val.id );
3517
+ escapedTooltip = escapeText( val.tooltip );
3518
+
3519
+ if ( config[ val.id ] === undefined ) {
3520
+ config[ val.id ] = QUnit.urlParams[ val.id ];
3521
+ }
3522
+
3523
+ if ( !val.value || typeof val.value === "string" ) {
3524
+ urlConfigHtml += "<input id='qunit-urlconfig-" + escaped +
3525
+ "' name='" + escaped + "' type='checkbox'" +
3526
+ ( val.value ? " value='" + escapeText( val.value ) + "'" : "" ) +
3527
+ ( config[ val.id ] ? " checked='checked'" : "" ) +
3528
+ " title='" + escapedTooltip + "' /><label for='qunit-urlconfig-" + escaped +
3529
+ "' title='" + escapedTooltip + "'>" + val.label + "</label>";
3530
+ } else {
3531
+ urlConfigHtml += "<label for='qunit-urlconfig-" + escaped +
3532
+ "' title='" + escapedTooltip + "'>" + val.label +
3533
+ ": </label><select id='qunit-urlconfig-" + escaped +
3534
+ "' name='" + escaped + "' title='" + escapedTooltip + "'><option></option>";
3535
+
3536
+ if ( QUnit.is( "array", val.value ) ) {
3537
+ for ( j = 0; j < val.value.length; j++ ) {
3538
+ escaped = escapeText( val.value[ j ] );
3539
+ urlConfigHtml += "<option value='" + escaped + "'" +
3540
+ ( config[ val.id ] === val.value[ j ] ?
3541
+ ( selection = true ) && " selected='selected'" : "" ) +
3542
+ ">" + escaped + "</option>";
3543
+ }
3544
+ } else {
3545
+ for ( j in val.value ) {
3546
+ if ( hasOwn.call( val.value, j ) ) {
3547
+ urlConfigHtml += "<option value='" + escapeText( j ) + "'" +
3548
+ ( config[ val.id ] === j ?
3549
+ ( selection = true ) && " selected='selected'" : "" ) +
3550
+ ">" + escapeText( val.value[ j ] ) + "</option>";
3551
+ }
3552
+ }
3553
+ }
3554
+ if ( config[ val.id ] && !selection ) {
3555
+ escaped = escapeText( config[ val.id ] );
3556
+ urlConfigHtml += "<option value='" + escaped +
3557
+ "' selected='selected' disabled='disabled'>" + escaped + "</option>";
3558
+ }
3559
+ urlConfigHtml += "</select>";
3560
+ }
3561
+ }
3562
+
3563
+ return urlConfigHtml;
3564
+ }
3565
+
3566
+ // Handle "click" events on toolbar checkboxes and "change" for select menus.
3567
+ // Updates the URL with the new state of `config.urlConfig` values.
3568
+ function toolbarChanged() {
3569
+ var updatedUrl, value,
3570
+ field = this,
3571
+ params = {};
3572
+
3573
+ // Detect if field is a select menu or a checkbox
3574
+ if ( "selectedIndex" in field ) {
3575
+ value = field.options[ field.selectedIndex ].value || undefined;
3576
+ } else {
3577
+ value = field.checked ? ( field.defaultValue || true ) : undefined;
3578
+ }
3579
+
3580
+ params[ field.name ] = value;
3581
+ updatedUrl = setUrl( params );
3582
+
3583
+ if ( "hidepassed" === field.name && "replaceState" in window.history ) {
3584
+ config[ field.name ] = value || false;
3585
+ if ( value ) {
3586
+ addClass( id( "qunit-tests" ), "hidepass" );
3587
+ } else {
3588
+ removeClass( id( "qunit-tests" ), "hidepass" );
3589
+ }
3590
+
3591
+ // It is not necessary to refresh the whole page
3592
+ window.history.replaceState( null, "", updatedUrl );
3593
+ } else {
3594
+ window.location = updatedUrl;
3595
+ }
3596
+ }
3597
+
3598
+ function setUrl( params ) {
3599
+ var key,
3600
+ querystring = "?";
3601
+
3602
+ params = QUnit.extend( QUnit.extend( {}, QUnit.urlParams ), params );
3603
+
3604
+ for ( key in params ) {
3605
+ if ( hasOwn.call( params, key ) ) {
3606
+ if ( params[ key ] === undefined ) {
3607
+ continue;
3608
+ }
3609
+ querystring += encodeURIComponent( key );
3610
+ if ( params[ key ] !== true ) {
3611
+ querystring += "=" + encodeURIComponent( params[ key ] );
3612
+ }
3613
+ querystring += "&";
3614
+ }
3615
+ }
3616
+ return location.protocol + "//" + location.host +
3617
+ location.pathname + querystring.slice( 0, -1 );
3618
+ }
3619
+
3620
+ function applyUrlParams() {
3621
+ var selectedModule,
3622
+ modulesList = id( "qunit-modulefilter" ),
3623
+ filter = id( "qunit-filter-input" ).value;
3624
+
3625
+ selectedModule = modulesList ?
3626
+ decodeURIComponent( modulesList.options[ modulesList.selectedIndex ].value ) :
3627
+ undefined;
3628
+
3629
+ window.location = setUrl({
3630
+ module: ( selectedModule === "" ) ? undefined : selectedModule,
3631
+ filter: ( filter === "" ) ? undefined : filter,
3632
+
3633
+ // Remove testId filter
3634
+ testId: undefined
3635
+ });
3636
+ }
3637
+
3638
+ function toolbarUrlConfigContainer() {
3639
+ var urlConfigContainer = document.createElement( "span" );
3640
+
3641
+ urlConfigContainer.innerHTML = getUrlConfigHtml();
3642
+ addClass( urlConfigContainer, "qunit-url-config" );
3643
+
3644
+ // For oldIE support:
3645
+ // * Add handlers to the individual elements instead of the container
3646
+ // * Use "click" instead of "change" for checkboxes
3647
+ addEvents( urlConfigContainer.getElementsByTagName( "input" ), "click", toolbarChanged );
3648
+ addEvents( urlConfigContainer.getElementsByTagName( "select" ), "change", toolbarChanged );
3649
+
3650
+ return urlConfigContainer;
3651
+ }
3652
+
3653
+ function toolbarLooseFilter() {
3654
+ var filter = document.createElement( "form" ),
3655
+ label = document.createElement( "label" ),
3656
+ input = document.createElement( "input" ),
3657
+ button = document.createElement( "button" );
3658
+
3659
+ addClass( filter, "qunit-filter" );
3660
+
3661
+ label.innerHTML = "Filter: ";
3662
+
3663
+ input.type = "text";
3664
+ input.value = config.filter || "";
3665
+ input.name = "filter";
3666
+ input.id = "qunit-filter-input";
3667
+
3668
+ button.innerHTML = "Go";
3669
+
3670
+ label.appendChild( input );
3671
+
3672
+ filter.appendChild( label );
3673
+ filter.appendChild( button );
3674
+ addEvent( filter, "submit", function( ev ) {
3675
+ applyUrlParams();
3676
+
3677
+ if ( ev && ev.preventDefault ) {
3678
+ ev.preventDefault();
3679
+ }
3680
+
3681
+ return false;
3682
+ });
3683
+
3684
+ return filter;
3685
+ }
3686
+
3687
+ function toolbarModuleFilterHtml() {
3688
+ var i,
3689
+ moduleFilterHtml = "";
3690
+
3691
+ if ( !modulesList.length ) {
3692
+ return false;
3693
+ }
3694
+
3695
+ modulesList.sort(function( a, b ) {
3696
+ return a.localeCompare( b );
3697
+ });
3698
+
3699
+ moduleFilterHtml += "<label for='qunit-modulefilter'>Module: </label>" +
3700
+ "<select id='qunit-modulefilter' name='modulefilter'><option value='' " +
3701
+ ( QUnit.urlParams.module === undefined ? "selected='selected'" : "" ) +
3702
+ ">< All Modules ></option>";
3703
+
3704
+ for ( i = 0; i < modulesList.length; i++ ) {
3705
+ moduleFilterHtml += "<option value='" +
3706
+ escapeText( encodeURIComponent( modulesList[ i ] ) ) + "' " +
3707
+ ( QUnit.urlParams.module === modulesList[ i ] ? "selected='selected'" : "" ) +
3708
+ ">" + escapeText( modulesList[ i ] ) + "</option>";
3709
+ }
3710
+ moduleFilterHtml += "</select>";
3711
+
3712
+ return moduleFilterHtml;
3713
+ }
3714
+
3715
+ function toolbarModuleFilter() {
3716
+ var toolbar = id( "qunit-testrunner-toolbar" ),
3717
+ moduleFilter = document.createElement( "span" ),
3718
+ moduleFilterHtml = toolbarModuleFilterHtml();
3719
+
3720
+ if ( !toolbar || !moduleFilterHtml ) {
3721
+ return false;
3722
+ }
3723
+
3724
+ moduleFilter.setAttribute( "id", "qunit-modulefilter-container" );
3725
+ moduleFilter.innerHTML = moduleFilterHtml;
3726
+
3727
+ addEvent( moduleFilter.lastChild, "change", applyUrlParams );
3728
+
3729
+ toolbar.appendChild( moduleFilter );
3730
+ }
3731
+
3732
+ function appendToolbar() {
3733
+ var toolbar = id( "qunit-testrunner-toolbar" );
3734
+
3735
+ if ( toolbar ) {
3736
+ toolbar.appendChild( toolbarUrlConfigContainer() );
3737
+ toolbar.appendChild( toolbarLooseFilter() );
3738
+ }
3739
+ }
3740
+
3741
+ function appendHeader() {
3742
+ var header = id( "qunit-header" );
3743
+
3744
+ if ( header ) {
3745
+ header.innerHTML = "<a href='" +
3746
+ setUrl({ filter: undefined, module: undefined, testId: undefined }) +
3747
+ "'>" + header.innerHTML + "</a> ";
3748
+ }
3749
+ }
3750
+
3751
+ function appendBanner() {
3752
+ var banner = id( "qunit-banner" );
3753
+
3754
+ if ( banner ) {
3755
+ banner.className = "";
3756
+ }
3757
+ }
3758
+
3759
+ function appendTestResults() {
3760
+ var tests = id( "qunit-tests" ),
3761
+ result = id( "qunit-testresult" );
3762
+
3763
+ if ( result ) {
3764
+ result.parentNode.removeChild( result );
3765
+ }
3766
+
3767
+ if ( tests ) {
3768
+ tests.innerHTML = "";
3769
+ result = document.createElement( "p" );
3770
+ result.id = "qunit-testresult";
3771
+ result.className = "result";
3772
+ tests.parentNode.insertBefore( result, tests );
3773
+ result.innerHTML = "Running...<br />&#160;";
3774
+ }
3775
+ }
3776
+
3777
+ function storeFixture() {
3778
+ var fixture = id( "qunit-fixture" );
3779
+ if ( fixture ) {
3780
+ config.fixture = fixture.innerHTML;
3781
+ }
3782
+ }
3783
+
3784
+ function appendFilteredTest() {
3785
+ var testId = QUnit.config.testId;
3786
+ if ( !testId || testId.length <= 0 ) {
3787
+ return "";
3788
+ }
3789
+ return "<div id='qunit-filteredTest'>Rerunning selected tests: " + testId.join(", ") +
3790
+ " <a id='qunit-clearFilter' href='" +
3791
+ setUrl({ filter: undefined, module: undefined, testId: undefined }) +
3792
+ "'>" + "Run all tests" + "</a></div>";
3793
+ }
3794
+
3795
+ function appendUserAgent() {
3796
+ var userAgent = id( "qunit-userAgent" );
3797
+
3798
+ if ( userAgent ) {
3799
+ userAgent.innerHTML = "";
3800
+ userAgent.appendChild(
3801
+ document.createTextNode(
3802
+ "QUnit " + QUnit.version + "; " + navigator.userAgent
3803
+ )
3804
+ );
3805
+ }
3806
+ }
3807
+
3808
+ function appendTestsList( modules ) {
3809
+ var i, l, x, z, test, moduleObj;
3810
+
3811
+ for ( i = 0, l = modules.length; i < l; i++ ) {
3812
+ moduleObj = modules[ i ];
3813
+
3814
+ if ( moduleObj.name ) {
3815
+ modulesList.push( moduleObj.name );
3816
+ }
3817
+
3818
+ for ( x = 0, z = moduleObj.tests.length; x < z; x++ ) {
3819
+ test = moduleObj.tests[ x ];
3820
+
3821
+ appendTest( test.name, test.testId, moduleObj.name );
3822
+ }
3823
+ }
3824
+ }
3825
+
3826
+ function appendTest( name, testId, moduleName ) {
3827
+ var title, rerunTrigger, testBlock, assertList,
3828
+ tests = id( "qunit-tests" );
3829
+
3830
+ if ( !tests ) {
3831
+ return;
3832
+ }
3833
+
3834
+ title = document.createElement( "strong" );
3835
+ title.innerHTML = getNameHtml( name, moduleName );
3836
+
3837
+ rerunTrigger = document.createElement( "a" );
3838
+ rerunTrigger.innerHTML = "Rerun";
3839
+ rerunTrigger.href = setUrl({ testId: testId });
3840
+
3841
+ testBlock = document.createElement( "li" );
3842
+ testBlock.appendChild( title );
3843
+ testBlock.appendChild( rerunTrigger );
3844
+ testBlock.id = "qunit-test-output-" + testId;
3845
+
3846
+ assertList = document.createElement( "ol" );
3847
+ assertList.className = "qunit-assert-list";
3848
+
3849
+ testBlock.appendChild( assertList );
3850
+
3851
+ tests.appendChild( testBlock );
3852
+ }
3853
+
3854
+ // HTML Reporter initialization and load
3855
+ QUnit.begin(function( details ) {
3856
+ var qunit = id( "qunit" );
3857
+
3858
+ // Fixture is the only one necessary to run without the #qunit element
3859
+ storeFixture();
3860
+
3861
+ if ( qunit ) {
3862
+ qunit.innerHTML =
3863
+ "<h1 id='qunit-header'>" + escapeText( document.title ) + "</h1>" +
3864
+ "<h2 id='qunit-banner'></h2>" +
3865
+ "<div id='qunit-testrunner-toolbar'></div>" +
3866
+ appendFilteredTest() +
3867
+ "<h2 id='qunit-userAgent'></h2>" +
3868
+ "<ol id='qunit-tests'></ol>";
3869
+ }
3870
+
3871
+ appendHeader();
3872
+ appendBanner();
3873
+ appendTestResults();
3874
+ appendUserAgent();
3875
+ appendToolbar();
3876
+ appendTestsList( details.modules );
3877
+ toolbarModuleFilter();
3878
+
3879
+ if ( qunit && config.hidepassed ) {
3880
+ addClass( qunit.lastChild, "hidepass" );
3881
+ }
3882
+ });
3883
+
3884
+ QUnit.done(function( details ) {
3885
+ var i, key,
3886
+ banner = id( "qunit-banner" ),
3887
+ tests = id( "qunit-tests" ),
3888
+ html = [
3889
+ "Tests completed in ",
3890
+ details.runtime,
3891
+ " milliseconds.<br />",
3892
+ "<span class='passed'>",
3893
+ details.passed,
3894
+ "</span> assertions of <span class='total'>",
3895
+ details.total,
3896
+ "</span> passed, <span class='failed'>",
3897
+ details.failed,
3898
+ "</span> failed."
3899
+ ].join( "" );
3900
+
3901
+ if ( banner ) {
3902
+ banner.className = details.failed ? "qunit-fail" : "qunit-pass";
3903
+ }
3904
+
3905
+ if ( tests ) {
3906
+ id( "qunit-testresult" ).innerHTML = html;
3907
+ }
3908
+
3909
+ if ( config.altertitle && defined.document && document.title ) {
3910
+
3911
+ // show ✖ for good, ✔ for bad suite result in title
3912
+ // use escape sequences in case file gets loaded with non-utf-8-charset
3913
+ document.title = [
3914
+ ( details.failed ? "\u2716" : "\u2714" ),
3915
+ document.title.replace( /^[\u2714\u2716] /i, "" )
3916
+ ].join( " " );
3917
+ }
3918
+
3919
+ // clear own sessionStorage items if all tests passed
3920
+ if ( config.reorder && defined.sessionStorage && details.failed === 0 ) {
3921
+ for ( i = 0; i < sessionStorage.length; i++ ) {
3922
+ key = sessionStorage.key( i++ );
3923
+ if ( key.indexOf( "qunit-test-" ) === 0 ) {
3924
+ sessionStorage.removeItem( key );
3925
+ }
3926
+ }
3927
+ }
3928
+
3929
+ // scroll back to top to show results
3930
+ if ( config.scrolltop && window.scrollTo ) {
3931
+ window.scrollTo( 0, 0 );
3932
+ }
3933
+ });
3934
+
3935
+ function getNameHtml( name, module ) {
3936
+ var nameHtml = "";
3937
+
3938
+ if ( module ) {
3939
+ nameHtml = "<span class='module-name'>" + escapeText( module ) + "</span>: ";
3940
+ }
3941
+
3942
+ nameHtml += "<span class='test-name'>" + escapeText( name ) + "</span>";
3943
+
3944
+ return nameHtml;
3945
+ }
3946
+
3947
+ QUnit.testStart(function( details ) {
3948
+ var running, testBlock, bad;
3949
+
3950
+ testBlock = id( "qunit-test-output-" + details.testId );
3951
+ if ( testBlock ) {
3952
+ testBlock.className = "running";
3953
+ } else {
3954
+
3955
+ // Report later registered tests
3956
+ appendTest( details.name, details.testId, details.module );
3957
+ }
3958
+
3959
+ running = id( "qunit-testresult" );
3960
+ if ( running ) {
3961
+ bad = QUnit.config.reorder && defined.sessionStorage &&
3962
+ +sessionStorage.getItem( "qunit-test-" + details.module + "-" + details.name );
3963
+
3964
+ running.innerHTML = ( bad ?
3965
+ "Rerunning previously failed test: <br />" :
3966
+ "Running: <br />" ) +
3967
+ getNameHtml( details.name, details.module );
3968
+ }
3969
+
3970
+ });
3971
+
3972
+ function stripHtml( string ) {
3973
+ // strip tags, html entity and whitespaces
3974
+ return string.replace(/<\/?[^>]+(>|$)/g, "").replace(/\&quot;/g, "").replace(/\s+/g, "");
3975
+ }
3976
+
3977
+ QUnit.log(function( details ) {
3978
+ var assertList, assertLi,
3979
+ message, expected, actual, diff,
3980
+ showDiff = false,
3981
+ testItem = id( "qunit-test-output-" + details.testId );
3982
+
3983
+ if ( !testItem ) {
3984
+ return;
3985
+ }
3986
+
3987
+ message = escapeText( details.message ) || ( details.result ? "okay" : "failed" );
3988
+ message = "<span class='test-message'>" + message + "</span>";
3989
+ message += "<span class='runtime'>@ " + details.runtime + " ms</span>";
3990
+
3991
+ // pushFailure doesn't provide details.expected
3992
+ // when it calls, it's implicit to also not show expected and diff stuff
3993
+ // Also, we need to check details.expected existence, as it can exist and be undefined
3994
+ if ( !details.result && hasOwn.call( details, "expected" ) ) {
3995
+ if ( details.negative ) {
3996
+ expected = escapeText( "NOT " + QUnit.dump.parse( details.expected ) );
3997
+ } else {
3998
+ expected = escapeText( QUnit.dump.parse( details.expected ) );
3999
+ }
4000
+
4001
+ actual = escapeText( QUnit.dump.parse( details.actual ) );
4002
+ message += "<table><tr class='test-expected'><th>Expected: </th><td><pre>" +
4003
+ expected +
4004
+ "</pre></td></tr>";
4005
+
4006
+ if ( actual !== expected ) {
4007
+
4008
+ message += "<tr class='test-actual'><th>Result: </th><td><pre>" +
4009
+ actual + "</pre></td></tr>";
4010
+
4011
+ // Don't show diff if actual or expected are booleans
4012
+ if ( !( /^(true|false)$/.test( actual ) ) &&
4013
+ !( /^(true|false)$/.test( expected ) ) ) {
4014
+ diff = QUnit.diff( expected, actual );
4015
+ showDiff = stripHtml( diff ).length !==
4016
+ stripHtml( expected ).length +
4017
+ stripHtml( actual ).length;
4018
+ }
4019
+
4020
+ // Don't show diff if expected and actual are totally different
4021
+ if ( showDiff ) {
4022
+ message += "<tr class='test-diff'><th>Diff: </th><td><pre>" +
4023
+ diff + "</pre></td></tr>";
4024
+ }
4025
+ } else if ( expected.indexOf( "[object Array]" ) !== -1 ||
4026
+ expected.indexOf( "[object Object]" ) !== -1 ) {
4027
+ message += "<tr class='test-message'><th>Message: </th><td>" +
4028
+ "Diff suppressed as the depth of object is more than current max depth (" +
4029
+ QUnit.config.maxDepth + ").<p>Hint: Use <code>QUnit.dump.maxDepth</code> to " +
4030
+ " run with a higher max depth or <a href='" + setUrl({ maxDepth: -1 }) + "'>" +
4031
+ "Rerun</a> without max depth.</p></td></tr>";
4032
+ }
4033
+
4034
+ if ( details.source ) {
4035
+ message += "<tr class='test-source'><th>Source: </th><td><pre>" +
4036
+ escapeText( details.source ) + "</pre></td></tr>";
4037
+ }
4038
+
4039
+ message += "</table>";
4040
+
4041
+ // this occours when pushFailure is set and we have an extracted stack trace
4042
+ } else if ( !details.result && details.source ) {
4043
+ message += "<table>" +
4044
+ "<tr class='test-source'><th>Source: </th><td><pre>" +
4045
+ escapeText( details.source ) + "</pre></td></tr>" +
4046
+ "</table>";
4047
+ }
4048
+
4049
+ assertList = testItem.getElementsByTagName( "ol" )[ 0 ];
4050
+
4051
+ assertLi = document.createElement( "li" );
4052
+ assertLi.className = details.result ? "pass" : "fail";
4053
+ assertLi.innerHTML = message;
4054
+ assertList.appendChild( assertLi );
4055
+ });
4056
+
4057
+ QUnit.testDone(function( details ) {
4058
+ var testTitle, time, testItem, assertList,
4059
+ good, bad, testCounts, skipped, sourceName,
4060
+ tests = id( "qunit-tests" );
4061
+
4062
+ if ( !tests ) {
4063
+ return;
4064
+ }
4065
+
4066
+ testItem = id( "qunit-test-output-" + details.testId );
4067
+
4068
+ assertList = testItem.getElementsByTagName( "ol" )[ 0 ];
4069
+
4070
+ good = details.passed;
4071
+ bad = details.failed;
4072
+
4073
+ // store result when possible
4074
+ if ( config.reorder && defined.sessionStorage ) {
4075
+ if ( bad ) {
4076
+ sessionStorage.setItem( "qunit-test-" + details.module + "-" + details.name, bad );
4077
+ } else {
4078
+ sessionStorage.removeItem( "qunit-test-" + details.module + "-" + details.name );
4079
+ }
4080
+ }
4081
+
4082
+ if ( bad === 0 ) {
4083
+
4084
+ // Collapse the passing tests
4085
+ addClass( assertList, "qunit-collapsed" );
4086
+ } else if ( bad && config.collapse && !collapseNext ) {
4087
+
4088
+ // Skip collapsing the first failing test
4089
+ collapseNext = true;
4090
+ } else {
4091
+
4092
+ // Collapse remaining tests
4093
+ addClass( assertList, "qunit-collapsed" );
4094
+ }
4095
+
4096
+ // testItem.firstChild is the test name
4097
+ testTitle = testItem.firstChild;
4098
+
4099
+ testCounts = bad ?
4100
+ "<b class='failed'>" + bad + "</b>, " + "<b class='passed'>" + good + "</b>, " :
4101
+ "";
4102
+
4103
+ testTitle.innerHTML += " <b class='counts'>(" + testCounts +
4104
+ details.assertions.length + ")</b>";
4105
+
4106
+ if ( details.skipped ) {
4107
+ testItem.className = "skipped";
4108
+ skipped = document.createElement( "em" );
4109
+ skipped.className = "qunit-skipped-label";
4110
+ skipped.innerHTML = "skipped";
4111
+ testItem.insertBefore( skipped, testTitle );
4112
+ } else {
4113
+ addEvent( testTitle, "click", function() {
4114
+ toggleClass( assertList, "qunit-collapsed" );
4115
+ });
4116
+
4117
+ testItem.className = bad ? "fail" : "pass";
4118
+
4119
+ time = document.createElement( "span" );
4120
+ time.className = "runtime";
4121
+ time.innerHTML = details.runtime + " ms";
4122
+ testItem.insertBefore( time, assertList );
4123
+ }
4124
+
4125
+ // Show the source of the test when showing assertions
4126
+ if ( details.source ) {
4127
+ sourceName = document.createElement( "p" );
4128
+ sourceName.innerHTML = "<strong>Source: </strong>" + details.source;
4129
+ addClass( sourceName, "qunit-source" );
4130
+ if ( bad === 0 ) {
4131
+ addClass( sourceName, "qunit-collapsed" );
4132
+ }
4133
+ addEvent( testTitle, "click", function() {
4134
+ toggleClass( sourceName, "qunit-collapsed" );
4135
+ });
4136
+ testItem.appendChild( sourceName );
4137
+ }
4138
+ });
4139
+
4140
+ if ( defined.document ) {
4141
+
4142
+ // Avoid readyState issue with phantomjs
4143
+ // Ref: #818
4144
+ var notPhantom = ( function( p ) {
4145
+ return !( p && p.version && p.version.major > 0 );
4146
+ } )( window.phantom );
4147
+
4148
+ if ( notPhantom && document.readyState === "complete" ) {
4149
+ QUnit.load();
4150
+ } else {
4151
+ addEvent( window, "load", QUnit.load );
4152
+ }
4153
+ } else {
4154
+ config.pageLoaded = true;
4155
+ config.autorun = true;
4156
+ }
4157
+
4158
+ })();