qunited 0.2.1 → 0.3.0

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