annotate test/qunit.js @ 11:efe98c3634e4

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