annotate jquery-ui/development-bundle/external/qunit.js @ 0:b2e4605f20b2

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