middleman 2.0.9 → 2.0.10

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