alloy-js-test-san 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +83 -0
- data/Rakefile +27 -0
- data/VERSION.yml +4 -0
- data/bin/jstest +10 -0
- data/lib/js_test_san/runner.rb +70 -0
- data/lib/js_test_san/test.rb +17 -0
- data/lib/js_test_san/test_case.rb +103 -0
- data/lib/js_test_san.rb +2 -0
- data/test/fixtures/a_unit_test.html +27 -0
- data/test/fixtures/a_unit_test.js +22 -0
- data/test/regression/prototype/unit/ajax_test.html +29 -0
- data/test/regression/prototype/unit/array_test.html +28 -0
- data/test/regression/prototype/unit/assets/prototype.js +4900 -0
- data/test/regression/prototype/unit/assets/unittest.css +50 -0
- data/test/regression/prototype/unit/assets/unittest.js +615 -0
- data/test/regression/prototype/unit/assets/unittest_transport.js +1 -0
- data/test/regression/prototype/unit/base_test.html +27 -0
- data/test/regression/prototype/unit/class_test.html +27 -0
- data/test/regression/prototype/unit/date_test.html +27 -0
- data/test/regression/prototype/unit/dom_test.html +304 -0
- data/test/regression/prototype/unit/element_mixins_test.html +30 -0
- data/test/regression/prototype/unit/enumerable_test.html +35 -0
- data/test/regression/prototype/unit/event_test.html +31 -0
- data/test/regression/prototype/unit/fixtures/ajax.html +2 -0
- data/test/regression/prototype/unit/fixtures/ajax.js +42 -0
- data/test/regression/prototype/unit/fixtures/array.html +1 -0
- data/test/regression/prototype/unit/fixtures/class.js +83 -0
- data/test/regression/prototype/unit/fixtures/content.html +1 -0
- data/test/regression/prototype/unit/fixtures/data.json +1 -0
- data/test/regression/prototype/unit/fixtures/dom.css +84 -0
- data/test/regression/prototype/unit/fixtures/dom.html +278 -0
- data/test/regression/prototype/unit/fixtures/dom.js +17 -0
- data/test/regression/prototype/unit/fixtures/element_mixins.html +4 -0
- data/test/regression/prototype/unit/fixtures/element_mixins.js +2 -0
- data/test/regression/prototype/unit/fixtures/empty.html +0 -0
- data/test/regression/prototype/unit/fixtures/empty.js +1 -0
- data/test/regression/prototype/unit/fixtures/enumerable.html +8 -0
- data/test/regression/prototype/unit/fixtures/enumerable.js +23 -0
- data/test/regression/prototype/unit/fixtures/event.html +4 -0
- data/test/regression/prototype/unit/fixtures/form.html +108 -0
- data/test/regression/prototype/unit/fixtures/function.js +13 -0
- data/test/regression/prototype/unit/fixtures/hash.js +25 -0
- data/test/regression/prototype/unit/fixtures/hello.js +1 -0
- data/test/regression/prototype/unit/fixtures/logo.gif +0 -0
- data/test/regression/prototype/unit/fixtures/object.html +6 -0
- data/test/regression/prototype/unit/fixtures/object.js +7 -0
- data/test/regression/prototype/unit/fixtures/position.html +9 -0
- data/test/regression/prototype/unit/fixtures/selector.html +71 -0
- data/test/regression/prototype/unit/fixtures/string.js +8 -0
- data/test/regression/prototype/unit/fixtures/unittest.html +18 -0
- data/test/regression/prototype/unit/form_test.html +135 -0
- data/test/regression/prototype/unit/function_test.html +27 -0
- data/test/regression/prototype/unit/hash_test.html +27 -0
- data/test/regression/prototype/unit/number_test.html +27 -0
- data/test/regression/prototype/unit/object_test.html +32 -0
- data/test/regression/prototype/unit/periodical_executer_test.html +27 -0
- data/test/regression/prototype/unit/position_test.html +36 -0
- data/test/regression/prototype/unit/prototype_test.html +27 -0
- data/test/regression/prototype/unit/range_test.html +27 -0
- data/test/regression/prototype/unit/regexp_test.html +27 -0
- data/test/regression/prototype/unit/selector_test.html +98 -0
- data/test/regression/prototype/unit/string_test.html +27 -0
- data/test/regression/prototype/unit/tests/ajax_test.js +379 -0
- data/test/regression/prototype/unit/tests/array_test.js +186 -0
- data/test/regression/prototype/unit/tests/base_test.js +43 -0
- data/test/regression/prototype/unit/tests/class_test.js +136 -0
- data/test/regression/prototype/unit/tests/date_test.js +5 -0
- data/test/regression/prototype/unit/tests/dom_test.js +1493 -0
- data/test/regression/prototype/unit/tests/element_mixins_test.js +32 -0
- data/test/regression/prototype/unit/tests/enumerable_test.js +271 -0
- data/test/regression/prototype/unit/tests/event_test.js +235 -0
- data/test/regression/prototype/unit/tests/form_test.js +382 -0
- data/test/regression/prototype/unit/tests/function_test.js +133 -0
- data/test/regression/prototype/unit/tests/hash_test.js +178 -0
- data/test/regression/prototype/unit/tests/number_test.js +44 -0
- data/test/regression/prototype/unit/tests/object_test.js +180 -0
- data/test/regression/prototype/unit/tests/periodical_executer_test.js +15 -0
- data/test/regression/prototype/unit/tests/position_test.js +44 -0
- data/test/regression/prototype/unit/tests/prototype_test.js +43 -0
- data/test/regression/prototype/unit/tests/range_test.js +58 -0
- data/test/regression/prototype/unit/tests/regexp_test.js +42 -0
- data/test/regression/prototype/unit/tests/selector_test.js +408 -0
- data/test/regression/prototype/unit/tests/string_test.js +548 -0
- data/test/regression/prototype/unit/tests/unittest_test.js +148 -0
- data/test/regression/prototype/unit/unittest_test.html +45 -0
- data/test/regression/prototype/upstream +1 -0
- data/test/test_helper.rb +20 -0
- data/test/unit/runner_test.rb +165 -0
- data/test/unit/test_case_test.rb +167 -0
- data/test/unit/test_test.rb +24 -0
- metadata +145 -0
@@ -0,0 +1,379 @@
|
|
1
|
+
var extendDefault = function(options) {
|
2
|
+
return Object.extend({
|
3
|
+
asynchronous: false,
|
4
|
+
method: 'get',
|
5
|
+
onException: function(e) { throw e }
|
6
|
+
}, options);
|
7
|
+
};
|
8
|
+
|
9
|
+
new Test.Unit.Runner({
|
10
|
+
setup: function() {
|
11
|
+
$('content').update('');
|
12
|
+
$('content2').update('');
|
13
|
+
},
|
14
|
+
|
15
|
+
teardown: function() {
|
16
|
+
// hack to cleanup responders
|
17
|
+
Ajax.Responders.responders = [Ajax.Responders.responders[0]];
|
18
|
+
},
|
19
|
+
|
20
|
+
testSynchronousRequest: function() {
|
21
|
+
this.assertEqual("", $("content").innerHTML);
|
22
|
+
|
23
|
+
this.assertEqual(0, Ajax.activeRequestCount);
|
24
|
+
new Ajax.Request("../fixtures/hello.js", {
|
25
|
+
asynchronous: false,
|
26
|
+
method: 'GET',
|
27
|
+
evalJS: 'force'
|
28
|
+
});
|
29
|
+
this.assertEqual(0, Ajax.activeRequestCount);
|
30
|
+
|
31
|
+
var h2 = $("content").firstChild;
|
32
|
+
this.assertEqual("Hello world!", h2.innerHTML);
|
33
|
+
},
|
34
|
+
|
35
|
+
testAsynchronousRequest: function() {
|
36
|
+
this.assertEqual("", $("content").innerHTML);
|
37
|
+
|
38
|
+
new Ajax.Request("../fixtures/hello.js", {
|
39
|
+
asynchronous: true,
|
40
|
+
method: 'get',
|
41
|
+
evalJS: 'force'
|
42
|
+
});
|
43
|
+
this.wait(1000, function() {
|
44
|
+
var h2 = $("content").firstChild;
|
45
|
+
this.assertEqual("Hello world!", h2.innerHTML);
|
46
|
+
});
|
47
|
+
},
|
48
|
+
|
49
|
+
testUpdater: function() {
|
50
|
+
this.assertEqual("", $("content").innerHTML);
|
51
|
+
|
52
|
+
new Ajax.Updater("content", "../fixtures/content.html", { method:'get' });
|
53
|
+
|
54
|
+
this.wait(1000, function() {
|
55
|
+
this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
|
56
|
+
|
57
|
+
$('content').update('');
|
58
|
+
this.assertEqual("", $("content").innerHTML);
|
59
|
+
|
60
|
+
new Ajax.Updater({ success:"content", failure:"content2" },
|
61
|
+
"../fixtures/content.html", { method:'get', parameters:{ pet:'monkey' } });
|
62
|
+
|
63
|
+
new Ajax.Updater("", "../fixtures/content.html", { method:'get', parameters:"pet=monkey" });
|
64
|
+
|
65
|
+
this.wait(1000, function() {
|
66
|
+
this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
|
67
|
+
this.assertEqual("", $("content2").innerHTML);
|
68
|
+
});
|
69
|
+
});
|
70
|
+
},
|
71
|
+
|
72
|
+
testUpdaterWithInsertion: function() {
|
73
|
+
$('content').update();
|
74
|
+
new Ajax.Updater("content", "../fixtures/content.html", { method:'get', insertion: Insertion.Top });
|
75
|
+
this.wait(1000, function() {
|
76
|
+
this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
|
77
|
+
$('content').update();
|
78
|
+
new Ajax.Updater("content", "../fixtures/content.html", { method:'get', insertion: 'bottom' });
|
79
|
+
this.wait(1000, function() {
|
80
|
+
this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
|
81
|
+
|
82
|
+
$('content').update();
|
83
|
+
new Ajax.Updater("content", "../fixtures/content.html", { method:'get', insertion: 'after' });
|
84
|
+
this.wait(1000, function() {
|
85
|
+
this.assertEqual('five dozen', $("content").next().innerHTML.strip().toLowerCase());
|
86
|
+
});
|
87
|
+
});
|
88
|
+
});
|
89
|
+
},
|
90
|
+
|
91
|
+
testUpdaterOptions: function() {
|
92
|
+
var options = {
|
93
|
+
method: 'get',
|
94
|
+
asynchronous: false,
|
95
|
+
evalJS: 'force',
|
96
|
+
onComplete: Prototype.emptyFunction
|
97
|
+
}
|
98
|
+
var request = new Ajax.Updater("content", "../fixtures/hello.js", options);
|
99
|
+
request.options.onComplete = Prototype.emptyFunction;
|
100
|
+
this.assertIdentical(Prototype.emptyFunction, options.onComplete);
|
101
|
+
},
|
102
|
+
|
103
|
+
testResponders: function(){
|
104
|
+
// check for internal responder
|
105
|
+
this.assertEqual(1, Ajax.Responders.responders.length);
|
106
|
+
|
107
|
+
var dummyResponder = {
|
108
|
+
onComplete: Prototype.emptyFunction
|
109
|
+
};
|
110
|
+
|
111
|
+
Ajax.Responders.register(dummyResponder);
|
112
|
+
this.assertEqual(2, Ajax.Responders.responders.length);
|
113
|
+
|
114
|
+
// don't add twice
|
115
|
+
Ajax.Responders.register(dummyResponder);
|
116
|
+
this.assertEqual(2, Ajax.Responders.responders.length);
|
117
|
+
|
118
|
+
Ajax.Responders.unregister(dummyResponder);
|
119
|
+
this.assertEqual(1, Ajax.Responders.responders.length);
|
120
|
+
|
121
|
+
var responder = {
|
122
|
+
onCreate: function(req){ responderCounter++ },
|
123
|
+
onLoading: function(req){ responderCounter++ },
|
124
|
+
onComplete: function(req){ responderCounter++ }
|
125
|
+
};
|
126
|
+
Ajax.Responders.register(responder);
|
127
|
+
|
128
|
+
this.assertEqual(0, responderCounter);
|
129
|
+
this.assertEqual(0, Ajax.activeRequestCount);
|
130
|
+
new Ajax.Request("../fixtures/content.html", { method:'get', parameters:"pet=monkey" });
|
131
|
+
this.assertEqual(1, responderCounter);
|
132
|
+
this.assertEqual(1, Ajax.activeRequestCount);
|
133
|
+
|
134
|
+
this.wait(1000,function() {
|
135
|
+
this.assertEqual(3, responderCounter);
|
136
|
+
this.assertEqual(0, Ajax.activeRequestCount);
|
137
|
+
});
|
138
|
+
},
|
139
|
+
|
140
|
+
testEvalResponseShouldBeCalledBeforeOnComplete: function() {
|
141
|
+
if (this.isRunningFromRake) {
|
142
|
+
this.assertEqual("", $("content").innerHTML);
|
143
|
+
|
144
|
+
this.assertEqual(0, Ajax.activeRequestCount);
|
145
|
+
new Ajax.Request("../fixtures/hello.js", extendDefault({
|
146
|
+
onComplete: function(response) { this.assertNotEqual("", $("content").innerHTML) }.bind(this)
|
147
|
+
}));
|
148
|
+
this.assertEqual(0, Ajax.activeRequestCount);
|
149
|
+
|
150
|
+
var h2 = $("content").firstChild;
|
151
|
+
this.assertEqual("Hello world!", h2.innerHTML);
|
152
|
+
} else {
|
153
|
+
this.info(message);
|
154
|
+
}
|
155
|
+
},
|
156
|
+
|
157
|
+
testContentTypeSetForSimulatedVerbs: function() {
|
158
|
+
if (this.isRunningFromRake) {
|
159
|
+
new Ajax.Request('/inspect', extendDefault({
|
160
|
+
method: 'put',
|
161
|
+
contentType: 'application/bogus',
|
162
|
+
onComplete: function(response) {
|
163
|
+
this.assertEqual('application/bogus; charset=UTF-8', response.responseJSON.headers['content-type']);
|
164
|
+
}.bind(this)
|
165
|
+
}));
|
166
|
+
} else {
|
167
|
+
this.info(message);
|
168
|
+
}
|
169
|
+
},
|
170
|
+
|
171
|
+
testOnCreateCallback: function() {
|
172
|
+
new Ajax.Request("../fixtures/content.html", extendDefault({
|
173
|
+
onCreate: function(transport) { this.assertEqual(0, transport.readyState) }.bind(this),
|
174
|
+
onComplete: function(transport) { this.assertNotEqual(0, transport.readyState) }.bind(this)
|
175
|
+
}));
|
176
|
+
},
|
177
|
+
|
178
|
+
testEvalJS: function() {
|
179
|
+
if (this.isRunningFromRake) {
|
180
|
+
|
181
|
+
$('content').update();
|
182
|
+
new Ajax.Request("/response", extendDefault({
|
183
|
+
parameters: Fixtures.js,
|
184
|
+
onComplete: function(transport) {
|
185
|
+
var h2 = $("content").firstChild;
|
186
|
+
this.assertEqual("Hello world!", h2.innerHTML);
|
187
|
+
}.bind(this)
|
188
|
+
}));
|
189
|
+
|
190
|
+
$('content').update();
|
191
|
+
new Ajax.Request("/response", extendDefault({
|
192
|
+
evalJS: false,
|
193
|
+
parameters: Fixtures.js,
|
194
|
+
onComplete: function(transport) {
|
195
|
+
this.assertEqual("", $("content").innerHTML);
|
196
|
+
}.bind(this)
|
197
|
+
}));
|
198
|
+
} else {
|
199
|
+
this.info(message);
|
200
|
+
}
|
201
|
+
|
202
|
+
$('content').update();
|
203
|
+
new Ajax.Request("../fixtures/hello.js", extendDefault({
|
204
|
+
evalJS: 'force',
|
205
|
+
onComplete: function(transport) {
|
206
|
+
var h2 = $("content").firstChild;
|
207
|
+
this.assertEqual("Hello world!", h2.innerHTML);
|
208
|
+
}.bind(this)
|
209
|
+
}));
|
210
|
+
},
|
211
|
+
|
212
|
+
testCallbacks: function() {
|
213
|
+
var options = extendDefault({
|
214
|
+
onCreate: function(transport) { this.assertInstanceOf(Ajax.Response, transport) }.bind(this)
|
215
|
+
});
|
216
|
+
|
217
|
+
Ajax.Request.Events.each(function(state){
|
218
|
+
options['on' + state] = options.onCreate;
|
219
|
+
});
|
220
|
+
|
221
|
+
new Ajax.Request("../fixtures/content.html", options);
|
222
|
+
},
|
223
|
+
|
224
|
+
testResponseText: function() {
|
225
|
+
new Ajax.Request("../fixtures/empty.html", extendDefault({
|
226
|
+
onComplete: function(transport) { this.assertEqual('', transport.responseText) }.bind(this)
|
227
|
+
}));
|
228
|
+
|
229
|
+
new Ajax.Request("../fixtures/content.html", extendDefault({
|
230
|
+
onComplete: function(transport) { this.assertEqual(sentence, transport.responseText.toLowerCase()) }.bind(this)
|
231
|
+
}));
|
232
|
+
},
|
233
|
+
|
234
|
+
testResponseXML: function() {
|
235
|
+
if (this.isRunningFromRake) {
|
236
|
+
new Ajax.Request("/response", extendDefault({
|
237
|
+
parameters: Fixtures.xml,
|
238
|
+
onComplete: function(transport) {
|
239
|
+
this.assertEqual('foo', transport.responseXML.getElementsByTagName('name')[0].getAttribute('attr'))
|
240
|
+
}.bind(this)
|
241
|
+
}));
|
242
|
+
} else {
|
243
|
+
this.info(message);
|
244
|
+
}
|
245
|
+
},
|
246
|
+
|
247
|
+
testResponseJSON: function() {
|
248
|
+
if (this.isRunningFromRake) {
|
249
|
+
new Ajax.Request("/response", extendDefault({
|
250
|
+
parameters: Fixtures.json,
|
251
|
+
onComplete: function(transport) { this.assertEqual(123, transport.responseJSON.test) }.bind(this)
|
252
|
+
}));
|
253
|
+
|
254
|
+
new Ajax.Request("/response", extendDefault({
|
255
|
+
parameters: {
|
256
|
+
'Content-Length': 0,
|
257
|
+
'Content-Type': 'application/json'
|
258
|
+
},
|
259
|
+
onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this)
|
260
|
+
}));
|
261
|
+
|
262
|
+
new Ajax.Request("/response", extendDefault({
|
263
|
+
evalJSON: false,
|
264
|
+
parameters: Fixtures.json,
|
265
|
+
onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this)
|
266
|
+
}));
|
267
|
+
|
268
|
+
new Ajax.Request("/response", extendDefault({
|
269
|
+
parameters: Fixtures.jsonWithoutContentType,
|
270
|
+
onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this)
|
271
|
+
}));
|
272
|
+
|
273
|
+
new Ajax.Request("/response", extendDefault({
|
274
|
+
sanitizeJSON: true,
|
275
|
+
parameters: Fixtures.invalidJson,
|
276
|
+
onException: function(request, error) {
|
277
|
+
this.assert(error.message.include('Badly formed JSON string'));
|
278
|
+
this.assertInstanceOf(Ajax.Request, request);
|
279
|
+
}.bind(this)
|
280
|
+
}));
|
281
|
+
} else {
|
282
|
+
this.info(message);
|
283
|
+
}
|
284
|
+
|
285
|
+
new Ajax.Request("../fixtures/data.json", extendDefault({
|
286
|
+
evalJSON: 'force',
|
287
|
+
onComplete: function(transport) { this.assertEqual(123, transport.responseJSON.test) }.bind(this)
|
288
|
+
}));
|
289
|
+
},
|
290
|
+
|
291
|
+
testHeaderJSON: function() {
|
292
|
+
if (this.isRunningFromRake) {
|
293
|
+
new Ajax.Request("/response", extendDefault({
|
294
|
+
parameters: Fixtures.headerJson,
|
295
|
+
onComplete: function(transport, json) {
|
296
|
+
this.assertEqual('hello #éà', transport.headerJSON.test);
|
297
|
+
this.assertEqual('hello #éà', json.test);
|
298
|
+
}.bind(this)
|
299
|
+
}));
|
300
|
+
|
301
|
+
new Ajax.Request("/response", extendDefault({
|
302
|
+
onComplete: function(transport, json) {
|
303
|
+
this.assertNull(transport.headerJSON)
|
304
|
+
this.assertNull(json)
|
305
|
+
}.bind(this)
|
306
|
+
}));
|
307
|
+
} else {
|
308
|
+
this.info(message);
|
309
|
+
}
|
310
|
+
},
|
311
|
+
|
312
|
+
testGetHeader: function() {
|
313
|
+
if (this.isRunningFromRake) {
|
314
|
+
new Ajax.Request("/response", extendDefault({
|
315
|
+
parameters: { 'X-TEST': 'some value' },
|
316
|
+
onComplete: function(transport) {
|
317
|
+
this.assertEqual('some value', transport.getHeader('X-Test'));
|
318
|
+
this.assertNull(transport.getHeader('X-Inexistant'));
|
319
|
+
}.bind(this)
|
320
|
+
}));
|
321
|
+
} else {
|
322
|
+
this.info(message);
|
323
|
+
}
|
324
|
+
},
|
325
|
+
|
326
|
+
testParametersCanBeHash: function() {
|
327
|
+
if (this.isRunningFromRake) {
|
328
|
+
new Ajax.Request("/response", extendDefault({
|
329
|
+
parameters: $H({ "one": "two", "three": "four" }),
|
330
|
+
onComplete: function(transport) {
|
331
|
+
this.assertEqual("two", transport.getHeader("one"));
|
332
|
+
this.assertEqual("four", transport.getHeader("three"));
|
333
|
+
this.assertNull(transport.getHeader("toObject"));
|
334
|
+
}.bind(this)
|
335
|
+
}));
|
336
|
+
} else {
|
337
|
+
this.info(message);
|
338
|
+
}
|
339
|
+
},
|
340
|
+
|
341
|
+
testIsSameOriginMethod: function() {
|
342
|
+
var isSameOrigin = Ajax.Request.prototype.isSameOrigin;
|
343
|
+
this.assert(isSameOrigin.call({ url: '/foo/bar.html' }), '/foo/bar.html');
|
344
|
+
this.assert(isSameOrigin.call({ url: window.location.toString() }), window.location);
|
345
|
+
this.assert(!isSameOrigin.call({ url: 'http://example.com' }), 'http://example.com');
|
346
|
+
|
347
|
+
if (this.isRunningFromRake) {
|
348
|
+
Ajax.Request.prototype.isSameOrigin = function() {
|
349
|
+
return false
|
350
|
+
};
|
351
|
+
|
352
|
+
$("content").update('same origin policy');
|
353
|
+
new Ajax.Request("/response", extendDefault({
|
354
|
+
parameters: Fixtures.js,
|
355
|
+
onComplete: function(transport) {
|
356
|
+
this.assertEqual("same origin policy", $("content").innerHTML);
|
357
|
+
}.bind(this)
|
358
|
+
}));
|
359
|
+
|
360
|
+
new Ajax.Request("/response", extendDefault({
|
361
|
+
parameters: Fixtures.invalidJson,
|
362
|
+
onException: function(request, error) {
|
363
|
+
this.assert(error.message.include('Badly formed JSON string'));
|
364
|
+
}.bind(this)
|
365
|
+
}));
|
366
|
+
|
367
|
+
new Ajax.Request("/response", extendDefault({
|
368
|
+
parameters: { 'X-JSON': '{});window.attacked = true;({}' },
|
369
|
+
onException: function(request, error) {
|
370
|
+
this.assert(error.message.include('Badly formed JSON string'));
|
371
|
+
}.bind(this)
|
372
|
+
}));
|
373
|
+
|
374
|
+
Ajax.Request.prototype.isSameOrigin = isSameOrigin;
|
375
|
+
} else {
|
376
|
+
this.info(message);
|
377
|
+
}
|
378
|
+
}
|
379
|
+
});
|
@@ -0,0 +1,186 @@
|
|
1
|
+
var globalArgsTest = 'nothing to see here';
|
2
|
+
|
3
|
+
new Test.Unit.Runner({
|
4
|
+
test$A: function(){
|
5
|
+
this.assertEnumEqual([], $A({}));
|
6
|
+
},
|
7
|
+
|
8
|
+
testToArrayOnArguments: function(){
|
9
|
+
function toArrayOnArguments(){
|
10
|
+
globalArgsTest = $A(arguments);
|
11
|
+
}
|
12
|
+
toArrayOnArguments();
|
13
|
+
this.assertEnumEqual([], globalArgsTest);
|
14
|
+
toArrayOnArguments('foo');
|
15
|
+
this.assertEnumEqual(['foo'], globalArgsTest);
|
16
|
+
toArrayOnArguments('foo','bar');
|
17
|
+
this.assertEnumEqual(['foo','bar'], globalArgsTest);
|
18
|
+
},
|
19
|
+
|
20
|
+
testToArrayOnNodeList: function(){
|
21
|
+
// direct HTML
|
22
|
+
this.assertEqual(3, $A($('test_node').childNodes).length);
|
23
|
+
|
24
|
+
// DOM
|
25
|
+
var element = document.createElement('div');
|
26
|
+
element.appendChild(document.createTextNode('22'));
|
27
|
+
(2).times(function(){ element.appendChild(document.createElement('span')) });
|
28
|
+
this.assertEqual(3, $A(element.childNodes).length);
|
29
|
+
|
30
|
+
// HTML String
|
31
|
+
element = document.createElement('div');
|
32
|
+
$(element).update('22<span></span><span></span');
|
33
|
+
this.assertEqual(3, $A(element.childNodes).length);
|
34
|
+
},
|
35
|
+
|
36
|
+
testClear: function(){
|
37
|
+
this.assertEnumEqual([], [].clear());
|
38
|
+
this.assertEnumEqual([], [1].clear());
|
39
|
+
this.assertEnumEqual([], [1,2].clear());
|
40
|
+
},
|
41
|
+
|
42
|
+
testClone: function(){
|
43
|
+
this.assertEnumEqual([], [].clone());
|
44
|
+
this.assertEnumEqual([1], [1].clone());
|
45
|
+
this.assertEnumEqual([1,2], [1,2].clone());
|
46
|
+
this.assertEnumEqual([0,1,2], [0,1,2].clone());
|
47
|
+
var a = [0,1,2];
|
48
|
+
var b = a;
|
49
|
+
this.assertIdentical(a, b);
|
50
|
+
b = a.clone();
|
51
|
+
this.assertNotIdentical(a, b);
|
52
|
+
},
|
53
|
+
|
54
|
+
testFirst: function(){
|
55
|
+
this.assertUndefined([].first());
|
56
|
+
this.assertEqual(1, [1].first());
|
57
|
+
this.assertEqual(1, [1,2].first());
|
58
|
+
},
|
59
|
+
|
60
|
+
testLast: function(){
|
61
|
+
this.assertUndefined([].last());
|
62
|
+
this.assertEqual(1, [1].last());
|
63
|
+
this.assertEqual(2, [1,2].last());
|
64
|
+
},
|
65
|
+
|
66
|
+
testCompact: function(){
|
67
|
+
this.assertEnumEqual([], [].compact());
|
68
|
+
this.assertEnumEqual([1,2,3], [1,2,3].compact());
|
69
|
+
this.assertEnumEqual([0,1,2,3], [0,null,1,2,undefined,3].compact());
|
70
|
+
this.assertEnumEqual([1,2,3], [null,1,2,3,null].compact());
|
71
|
+
},
|
72
|
+
|
73
|
+
testFlatten: function(){
|
74
|
+
this.assertEnumEqual([], [].flatten());
|
75
|
+
this.assertEnumEqual([1,2,3], [1,2,3].flatten());
|
76
|
+
this.assertEnumEqual([1,2,3], [1,[[[2,3]]]].flatten());
|
77
|
+
this.assertEnumEqual([1,2,3], [[1],[2],[3]].flatten());
|
78
|
+
this.assertEnumEqual([1,2,3], [[[[[[[1]]]]]],2,3].flatten());
|
79
|
+
},
|
80
|
+
|
81
|
+
testIndexOf: function(){
|
82
|
+
this.assertEqual(-1, [].indexOf(1));
|
83
|
+
this.assertEqual(-1, [0].indexOf(1));
|
84
|
+
this.assertEqual(0, [1].indexOf(1));
|
85
|
+
this.assertEqual(1, [0,1,2].indexOf(1));
|
86
|
+
this.assertEqual(0, [1,2,1].indexOf(1));
|
87
|
+
this.assertEqual(2, [1,2,1].indexOf(1, -1));
|
88
|
+
this.assertEqual(1, [undefined,null].indexOf(null));
|
89
|
+
},
|
90
|
+
|
91
|
+
testLastIndexOf: function(){
|
92
|
+
this.assertEqual(-1,[].lastIndexOf(1));
|
93
|
+
this.assertEqual(-1, [0].lastIndexOf(1));
|
94
|
+
this.assertEqual(0, [1].lastIndexOf(1));
|
95
|
+
this.assertEqual(2, [0,2,4,6].lastIndexOf(4));
|
96
|
+
this.assertEqual(3, [4,4,2,4,6].lastIndexOf(4));
|
97
|
+
this.assertEqual(3, [0,2,4,6].lastIndexOf(6,3));
|
98
|
+
this.assertEqual(-1, [0,2,4,6].lastIndexOf(6,2));
|
99
|
+
this.assertEqual(0, [6,2,4,6].lastIndexOf(6,2));
|
100
|
+
|
101
|
+
var fixture = [1,2,3,4,3];
|
102
|
+
this.assertEqual(4, fixture.lastIndexOf(3));
|
103
|
+
this.assertEnumEqual([1,2,3,4,3],fixture);
|
104
|
+
|
105
|
+
//tests from http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:lastIndexOf
|
106
|
+
var array = [2, 5, 9, 2];
|
107
|
+
this.assertEqual(3,array.lastIndexOf(2));
|
108
|
+
this.assertEqual(-1,array.lastIndexOf(7));
|
109
|
+
this.assertEqual(3,array.lastIndexOf(2,3));
|
110
|
+
this.assertEqual(0,array.lastIndexOf(2,2));
|
111
|
+
this.assertEqual(0,array.lastIndexOf(2,-2));
|
112
|
+
this.assertEqual(3,array.lastIndexOf(2,-1));
|
113
|
+
},
|
114
|
+
|
115
|
+
testInspect: function(){
|
116
|
+
this.assertEqual('[]',[].inspect());
|
117
|
+
this.assertEqual('[1]',[1].inspect());
|
118
|
+
this.assertEqual('[\'a\']',['a'].inspect());
|
119
|
+
this.assertEqual('[\'a\', 1]',['a',1].inspect());
|
120
|
+
},
|
121
|
+
|
122
|
+
testIntersect: function(){
|
123
|
+
this.assertEnumEqual([1,3], [1,1,3,5].intersect([1,2,3]));
|
124
|
+
this.assertEnumEqual([1], [1,1].intersect([1,1]));
|
125
|
+
this.assertEnumEqual([], [1,1,3,5].intersect([4]));
|
126
|
+
this.assertEnumEqual([], [1].intersect(['1']));
|
127
|
+
|
128
|
+
this.assertEnumEqual(
|
129
|
+
['B','C','D'],
|
130
|
+
$R('A','Z').toArray().intersect($R('B','D').toArray())
|
131
|
+
);
|
132
|
+
},
|
133
|
+
|
134
|
+
testToJSON: function(){
|
135
|
+
this.assertEqual('[]', [].toJSON());
|
136
|
+
this.assertEqual('[\"a\"]', ['a'].toJSON());
|
137
|
+
this.assertEqual('[\"a\", 1]', ['a', 1].toJSON());
|
138
|
+
this.assertEqual('[\"a\", {\"b\": null}]', ['a', {'b': null}].toJSON());
|
139
|
+
},
|
140
|
+
|
141
|
+
testReverse: function(){
|
142
|
+
this.assertEnumEqual([], [].reverse());
|
143
|
+
this.assertEnumEqual([1], [1].reverse());
|
144
|
+
this.assertEnumEqual([2,1], [1,2].reverse());
|
145
|
+
this.assertEnumEqual([3,2,1], [1,2,3].reverse());
|
146
|
+
},
|
147
|
+
|
148
|
+
testSize: function(){
|
149
|
+
this.assertEqual(4, [0, 1, 2, 3].size());
|
150
|
+
this.assertEqual(0, [].size());
|
151
|
+
},
|
152
|
+
|
153
|
+
testUniq: function(){
|
154
|
+
this.assertEnumEqual([1], [1, 1, 1].uniq());
|
155
|
+
this.assertEnumEqual([1], [1].uniq());
|
156
|
+
this.assertEnumEqual([], [].uniq());
|
157
|
+
this.assertEnumEqual([0, 1, 2, 3], [0, 1, 2, 2, 3, 0, 2].uniq());
|
158
|
+
this.assertEnumEqual([0, 1, 2, 3], [0, 0, 1, 1, 2, 3, 3, 3].uniq(true));
|
159
|
+
},
|
160
|
+
|
161
|
+
testWithout: function(){
|
162
|
+
this.assertEnumEqual([], [].without(0));
|
163
|
+
this.assertEnumEqual([], [0].without(0));
|
164
|
+
this.assertEnumEqual([1], [0,1].without(0));
|
165
|
+
this.assertEnumEqual([1,2], [0,1,2].without(0));
|
166
|
+
},
|
167
|
+
|
168
|
+
test$w: function(){
|
169
|
+
this.assertEnumEqual(['a', 'b', 'c', 'd'], $w('a b c d'));
|
170
|
+
this.assertEnumEqual([], $w(' '));
|
171
|
+
this.assertEnumEqual([], $w(''));
|
172
|
+
this.assertEnumEqual([], $w(null));
|
173
|
+
this.assertEnumEqual([], $w(undefined));
|
174
|
+
this.assertEnumEqual([], $w());
|
175
|
+
this.assertEnumEqual([], $w(10));
|
176
|
+
this.assertEnumEqual(['a'], $w('a'));
|
177
|
+
this.assertEnumEqual(['a'], $w('a '));
|
178
|
+
this.assertEnumEqual(['a'], $w(' a'));
|
179
|
+
this.assertEnumEqual(['a', 'b', 'c', 'd'], $w(' a b\nc\t\nd\n'));
|
180
|
+
},
|
181
|
+
|
182
|
+
testConcat: function(){
|
183
|
+
var args = (function() { return [].concat(arguments) })(1, 2);
|
184
|
+
this.assertIdentical(1, args[0][0]);
|
185
|
+
}
|
186
|
+
});
|
@@ -0,0 +1,43 @@
|
|
1
|
+
new Test.Unit.Runner({
|
2
|
+
testBrowserDetection: function() {
|
3
|
+
var results = $H(Prototype.Browser).map(function(engine){
|
4
|
+
return engine;
|
5
|
+
}).partition(function(engine){
|
6
|
+
return engine[1] === true
|
7
|
+
});
|
8
|
+
var trues = results[0], falses = results[1];
|
9
|
+
|
10
|
+
this.info('User agent string is: ' + navigator.userAgent);
|
11
|
+
|
12
|
+
this.assert(trues.size() == 0 || trues.size() == 1,
|
13
|
+
'There should be only one or no browser detected.');
|
14
|
+
|
15
|
+
// we should have definite trues or falses here
|
16
|
+
trues.each(function(result) {
|
17
|
+
this.assert(result[1] === true);
|
18
|
+
}, this);
|
19
|
+
falses.each(function(result) {
|
20
|
+
this.assert(result[1] === false);
|
21
|
+
}, this);
|
22
|
+
|
23
|
+
if(navigator.userAgent.indexOf('AppleWebKit/') > -1) {
|
24
|
+
this.info('Running on WebKit');
|
25
|
+
this.assert(Prototype.Browser.WebKit);
|
26
|
+
}
|
27
|
+
|
28
|
+
if(!!window.opera) {
|
29
|
+
this.info('Running on Opera');
|
30
|
+
this.assert(Prototype.Browser.Opera);
|
31
|
+
}
|
32
|
+
|
33
|
+
if(!!(window.attachEvent && !window.opera)) {
|
34
|
+
this.info('Running on IE');
|
35
|
+
this.assert(Prototype.Browser.IE);
|
36
|
+
}
|
37
|
+
|
38
|
+
if(navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1) {
|
39
|
+
this.info('Running on Gecko');
|
40
|
+
this.assert(Prototype.Browser.Gecko);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
});
|