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