headless-squirrel 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +55 -0
- data/Rakefile +27 -0
- data/bin/jstest +10 -0
- data/lib/headless_squirrel.rb +2 -0
- data/lib/headless_squirrel/console.rb +24 -0
- data/lib/headless_squirrel/runner.rb +70 -0
- data/lib/headless_squirrel/test.rb +17 -0
- data/lib/headless_squirrel/test_case.rb +158 -0
- data/test/fixtures/a_unit_test.html +27 -0
- data/test/fixtures/a_unit_test.js +22 -0
- data/test/fixtures/syntax_error.html +27 -0
- data/test/fixtures/syntax_error.js +5 -0
- data/test/fixtures/type_error.html +27 -0
- data/test/fixtures/type_error.js +1 -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/regression/scriptaculous/unit/_ajax_inplaceeditor_ipce_alt_text.html +1 -0
- data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_ipce_collection.js +1 -0
- data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_result.html +1 -0
- data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_result2.html +1 -0
- data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_tagged.html +1 -0
- data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_text.html +1 -0
- data/test/regression/scriptaculous/unit/_ajax_updater_result.html +20 -0
- data/test/regression/scriptaculous/unit/_autocomplete_result.html +11 -0
- data/test/regression/scriptaculous/unit/_autocomplete_result_nobr.html +1 -0
- data/test/regression/scriptaculous/unit/ajax_autocompleter_test.html +243 -0
- data/test/regression/scriptaculous/unit/ajax_inplaceeditor_test.html +895 -0
- data/test/regression/scriptaculous/unit/assets/builder.js +134 -0
- data/test/regression/scriptaculous/unit/assets/controls.js +963 -0
- data/test/regression/scriptaculous/unit/assets/dragdrop.js +973 -0
- data/test/regression/scriptaculous/unit/assets/effects.js +1122 -0
- data/test/regression/scriptaculous/unit/assets/javascripttest.rb +203 -0
- data/test/regression/scriptaculous/unit/assets/prototype.js +4320 -0
- data/test/regression/scriptaculous/unit/assets/scriptaculous.js +66 -0
- data/test/regression/scriptaculous/unit/assets/slider.js +273 -0
- data/test/regression/scriptaculous/unit/assets/sound.js +57 -0
- data/test/regression/scriptaculous/unit/assets/unittest.js +566 -0
- data/test/regression/scriptaculous/unit/bdd_test.html +150 -0
- data/test/regression/scriptaculous/unit/builder_test.html +262 -0
- data/test/regression/scriptaculous/unit/dragdrop_test.html +131 -0
- data/test/regression/scriptaculous/unit/effects_test.html +547 -0
- data/test/regression/scriptaculous/unit/element_test.html +116 -0
- data/test/regression/scriptaculous/unit/icon.png +0 -0
- data/test/regression/scriptaculous/unit/index.html +70 -0
- data/test/regression/scriptaculous/unit/loading_test.html +41 -0
- data/test/regression/scriptaculous/unit/position_clone_test.html +312 -0
- data/test/regression/scriptaculous/unit/slider_test.html +437 -0
- data/test/regression/scriptaculous/unit/sortable_test.html +205 -0
- data/test/regression/scriptaculous/unit/string_test.html +71 -0
- data/test/regression/scriptaculous/unit/unittest_test.html +154 -0
- data/test/regression/scriptaculous/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 +207 -0
- data/test/unit/test_test.rb +24 -0
- metadata +209 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
new Test.Unit.Runner({
|
2
|
+
testInput: function() {
|
3
|
+
this.assert($("input").present != null);
|
4
|
+
this.assert(typeof $("input").present == 'function');
|
5
|
+
this.assert($("input").select != null);
|
6
|
+
this.assertRespondsTo('present', Form.Element);
|
7
|
+
this.assertRespondsTo('present', Form.Element.Methods);
|
8
|
+
this.assertRespondsTo('coffee', $('input'));
|
9
|
+
this.assertIdentical(Prototype.K, Form.Element.coffee);
|
10
|
+
this.assertIdentical(Prototype.K, Form.Element.Methods.coffee);
|
11
|
+
},
|
12
|
+
|
13
|
+
testForm: function() {
|
14
|
+
this.assert($("form").reset != null);
|
15
|
+
this.assert($("form").getInputs().length == 2);
|
16
|
+
},
|
17
|
+
|
18
|
+
testEvent: function() {
|
19
|
+
this.assert($("form").observe != null)
|
20
|
+
// Can't really test this one with TestUnit...
|
21
|
+
$('form').observe("submit", function(e) {
|
22
|
+
alert("yeah!");
|
23
|
+
Event.stop(e);
|
24
|
+
});
|
25
|
+
},
|
26
|
+
|
27
|
+
testCollections: function() {
|
28
|
+
this.assert($$("input").all(function(input) {
|
29
|
+
return (input.focus != null);
|
30
|
+
}));
|
31
|
+
}
|
32
|
+
});
|
@@ -0,0 +1,271 @@
|
|
1
|
+
function prime(value) {
|
2
|
+
for (var i = 2; i < value; i++)
|
3
|
+
if (value % i == 0) return false;
|
4
|
+
return true;
|
5
|
+
}
|
6
|
+
|
7
|
+
new Test.Unit.Runner({
|
8
|
+
testEachBreak: function() {
|
9
|
+
var result = 0;
|
10
|
+
Fixtures.Basic.each(function(value) {
|
11
|
+
if ((result = value) == 2) throw $break;
|
12
|
+
});
|
13
|
+
|
14
|
+
this.assertEqual(2, result);
|
15
|
+
},
|
16
|
+
|
17
|
+
testEachReturnActsAsContinue: function() {
|
18
|
+
var results = [];
|
19
|
+
Fixtures.Basic.each(function(value) {
|
20
|
+
if (value == 2) return;
|
21
|
+
results.push(value);
|
22
|
+
});
|
23
|
+
|
24
|
+
this.assertEqual('1, 3', results.join(', '));
|
25
|
+
},
|
26
|
+
|
27
|
+
testEachChaining: function() {
|
28
|
+
this.assertEqual(Fixtures.Primes, Fixtures.Primes.each(Prototype.emptyFunction));
|
29
|
+
this.assertEqual(3, Fixtures.Basic.each(Prototype.emptyFunction).length);
|
30
|
+
},
|
31
|
+
|
32
|
+
testEnumContext: function() {
|
33
|
+
var results = [];
|
34
|
+
Fixtures.Basic.each(function(value) {
|
35
|
+
results.push(value * this.i);
|
36
|
+
}, { i: 2 });
|
37
|
+
|
38
|
+
this.assertEqual('2 4 6', results.join(' '));
|
39
|
+
|
40
|
+
this.assert(Fixtures.Basic.all(function(value){
|
41
|
+
return value >= this.min && value <= this.max;
|
42
|
+
}, { min: 1, max: 3 }));
|
43
|
+
this.assert(!Fixtures.Basic.all(function(value){
|
44
|
+
return value >= this.min && value <= this.max;
|
45
|
+
}));
|
46
|
+
this.assert(Fixtures.Basic.any(function(value){
|
47
|
+
return value == this.target_value;
|
48
|
+
}, { target_value: 2 }));
|
49
|
+
},
|
50
|
+
|
51
|
+
testAny: function() {
|
52
|
+
this.assert(!([].any()));
|
53
|
+
|
54
|
+
this.assert([true, true, true].any());
|
55
|
+
this.assert([true, false, false].any());
|
56
|
+
this.assert(![false, false, false].any());
|
57
|
+
|
58
|
+
this.assert(Fixtures.Basic.any(function(value) {
|
59
|
+
return value > 2;
|
60
|
+
}));
|
61
|
+
this.assert(!Fixtures.Basic.any(function(value) {
|
62
|
+
return value > 5;
|
63
|
+
}));
|
64
|
+
},
|
65
|
+
|
66
|
+
testAll: function() {
|
67
|
+
this.assert([].all());
|
68
|
+
|
69
|
+
this.assert([true, true, true].all());
|
70
|
+
this.assert(![true, false, false].all());
|
71
|
+
this.assert(![false, false, false].all());
|
72
|
+
|
73
|
+
this.assert(Fixtures.Basic.all(function(value) {
|
74
|
+
return value > 0;
|
75
|
+
}));
|
76
|
+
this.assert(!Fixtures.Basic.all(function(value) {
|
77
|
+
return value > 1;
|
78
|
+
}));
|
79
|
+
},
|
80
|
+
|
81
|
+
testCollect: function() {
|
82
|
+
this.assertEqual(Fixtures.Nicknames.join(', '),
|
83
|
+
Fixtures.People.collect(function(person) {
|
84
|
+
return person.nickname;
|
85
|
+
}).join(", "));
|
86
|
+
|
87
|
+
this.assertEqual(26, Fixtures.Primes.map().length);
|
88
|
+
},
|
89
|
+
|
90
|
+
testDetect: function() {
|
91
|
+
this.assertEqual('Marcel Molina Jr.',
|
92
|
+
Fixtures.People.detect(function(person) {
|
93
|
+
return person.nickname.match(/no/);
|
94
|
+
}).name);
|
95
|
+
},
|
96
|
+
|
97
|
+
testEachSlice: function() {
|
98
|
+
this.assertEnumEqual([], [].eachSlice(2));
|
99
|
+
this.assertEqual(1, [1].eachSlice(1).length);
|
100
|
+
this.assertEnumEqual([1], [1].eachSlice(1)[0]);
|
101
|
+
this.assertEqual(2, Fixtures.Basic.eachSlice(2).length);
|
102
|
+
this.assertEnumEqual(
|
103
|
+
[3, 2, 1, 11, 7, 5, 19, 17, 13, 31, 29, 23, 43, 41, 37, 59, 53, 47, 71, 67, 61, 83, 79, 73, 97, 89],
|
104
|
+
Fixtures.Primes.eachSlice( 3, function(slice){ return slice.reverse() }).flatten()
|
105
|
+
);
|
106
|
+
this.assertEnumEqual(Fixtures.Basic, Fixtures.Basic.eachSlice(-10));
|
107
|
+
this.assertEnumEqual(Fixtures.Basic, Fixtures.Basic.eachSlice(0));
|
108
|
+
this.assertNotIdentical(Fixtures.Basic, Fixtures.Basic.eachSlice(0));
|
109
|
+
},
|
110
|
+
|
111
|
+
testEachWithIndex: function() {
|
112
|
+
var nicknames = [], indexes = [];
|
113
|
+
Fixtures.People.each(function(person, index) {
|
114
|
+
nicknames.push(person.nickname);
|
115
|
+
indexes.push(index);
|
116
|
+
});
|
117
|
+
|
118
|
+
this.assertEqual(Fixtures.Nicknames.join(', '),
|
119
|
+
nicknames.join(', '));
|
120
|
+
this.assertEqual('0, 1, 2, 3', indexes.join(', '));
|
121
|
+
},
|
122
|
+
|
123
|
+
testFindAll: function() {
|
124
|
+
this.assertEqual(Fixtures.Primes.join(', '),
|
125
|
+
Fixtures.Z.findAll(prime).join(', '));
|
126
|
+
},
|
127
|
+
|
128
|
+
testGrep: function() {
|
129
|
+
this.assertEqual('noradio, htonl',
|
130
|
+
Fixtures.Nicknames.grep(/o/).join(", "));
|
131
|
+
|
132
|
+
this.assertEqual('NORADIO, HTONL',
|
133
|
+
Fixtures.Nicknames.grep(/o/, function(nickname) {
|
134
|
+
return nickname.toUpperCase();
|
135
|
+
}).join(", "))
|
136
|
+
|
137
|
+
this.assertEnumEqual($('grepHeader', 'grepCell'),
|
138
|
+
$('grepTable', 'grepTBody', 'grepRow', 'grepHeader', 'grepCell').grep(new Selector('.cell')));
|
139
|
+
|
140
|
+
// troublesome characters
|
141
|
+
this.assertEnumEqual(['?a', 'c?'], ['?a','b','c?'].grep('?'));
|
142
|
+
this.assertEnumEqual(['*a', 'c*'], ['*a','b','c*'].grep('*'));
|
143
|
+
this.assertEnumEqual(['+a', 'c+'], ['+a','b','c+'].grep('+'));
|
144
|
+
this.assertEnumEqual(['{1}a', 'c{1}'], ['{1}a','b','c{1}'].grep('{1}'));
|
145
|
+
this.assertEnumEqual(['(a', 'c('], ['(a','b','c('].grep('('));
|
146
|
+
this.assertEnumEqual(['|a', 'c|'], ['|a','b','c|'].grep('|'));
|
147
|
+
},
|
148
|
+
|
149
|
+
testInclude: function() {
|
150
|
+
this.assert(Fixtures.Nicknames.include('sam-'));
|
151
|
+
this.assert(Fixtures.Nicknames.include('noradio'));
|
152
|
+
this.assert(!Fixtures.Nicknames.include('gmosx'));
|
153
|
+
this.assert(Fixtures.Basic.include(2));
|
154
|
+
this.assert(Fixtures.Basic.include('2'));
|
155
|
+
this.assert(!Fixtures.Basic.include('4'));
|
156
|
+
},
|
157
|
+
|
158
|
+
testInGroupsOf: function() {
|
159
|
+
this.assertEnumEqual([], [].inGroupsOf(3));
|
160
|
+
|
161
|
+
var arr = [1, 2, 3, 4, 5, 6].inGroupsOf(3);
|
162
|
+
this.assertEqual(2, arr.length);
|
163
|
+
this.assertEnumEqual([1, 2, 3], arr[0]);
|
164
|
+
this.assertEnumEqual([4, 5, 6], arr[1]);
|
165
|
+
|
166
|
+
arr = [1, 2, 3, 4, 5, 6].inGroupsOf(4);
|
167
|
+
this.assertEqual(2, arr.length);
|
168
|
+
this.assertEnumEqual([1, 2, 3, 4], arr[0]);
|
169
|
+
this.assertEnumEqual([5, 6, null, null], arr[1]);
|
170
|
+
|
171
|
+
var basic = Fixtures.Basic
|
172
|
+
|
173
|
+
arr = basic.inGroupsOf(4,'x');
|
174
|
+
this.assertEqual(1, arr.length);
|
175
|
+
this.assertEnumEqual([1, 2, 3, 'x'], arr[0]);
|
176
|
+
|
177
|
+
this.assertEnumEqual([1,2,3,'a'], basic.inGroupsOf(2, 'a').flatten());
|
178
|
+
|
179
|
+
arr = basic.inGroupsOf(5, '');
|
180
|
+
this.assertEqual(1, arr.length);
|
181
|
+
this.assertEnumEqual([1, 2, 3, '', ''], arr[0]);
|
182
|
+
|
183
|
+
this.assertEnumEqual([1,2,3,0], basic.inGroupsOf(2, 0).flatten());
|
184
|
+
this.assertEnumEqual([1,2,3,false], basic.inGroupsOf(2, false).flatten());
|
185
|
+
},
|
186
|
+
|
187
|
+
testInject: function() {
|
188
|
+
this.assertEqual(1061,
|
189
|
+
Fixtures.Primes.inject(0, function(sum, value) {
|
190
|
+
return sum + value;
|
191
|
+
}));
|
192
|
+
},
|
193
|
+
|
194
|
+
testInvoke: function() {
|
195
|
+
var result = [[2, 1, 3], [6, 5, 4]].invoke('sort');
|
196
|
+
this.assertEqual(2, result.length);
|
197
|
+
this.assertEqual('1, 2, 3', result[0].join(', '));
|
198
|
+
this.assertEqual('4, 5, 6', result[1].join(', '));
|
199
|
+
|
200
|
+
result = result.invoke('invoke', 'toString', 2);
|
201
|
+
this.assertEqual('1, 10, 11', result[0].join(', '));
|
202
|
+
this.assertEqual('100, 101, 110', result[1].join(', '));
|
203
|
+
},
|
204
|
+
|
205
|
+
testMax: function() {
|
206
|
+
this.assertEqual(100, Fixtures.Z.max());
|
207
|
+
this.assertEqual(97, Fixtures.Primes.max());
|
208
|
+
this.assertEqual(2, [ -9, -8, -7, -6, -4, -3, -2, 0, -1, 2 ].max());
|
209
|
+
this.assertEqual('sam-', Fixtures.Nicknames.max()); // ?s > ?U
|
210
|
+
},
|
211
|
+
|
212
|
+
testMin: function() {
|
213
|
+
this.assertEqual(1, Fixtures.Z.min());
|
214
|
+
this.assertEqual(0, [ 1, 2, 3, 4, 5, 6, 7, 8, 0, 9 ].min());
|
215
|
+
this.assertEqual('Ulysses', Fixtures.Nicknames.min()); // ?U < ?h
|
216
|
+
},
|
217
|
+
|
218
|
+
testPartition: function() {
|
219
|
+
var result = Fixtures.People.partition(function(person) {
|
220
|
+
return person.name.length < 15;
|
221
|
+
}).invoke('pluck', 'nickname');
|
222
|
+
|
223
|
+
this.assertEqual(2, result.length);
|
224
|
+
this.assertEqual('sam-, htonl', result[0].join(', '));
|
225
|
+
this.assertEqual('noradio, Ulysses', result[1].join(', '));
|
226
|
+
},
|
227
|
+
|
228
|
+
testPluck: function() {
|
229
|
+
this.assertEqual(Fixtures.Nicknames.join(', '),
|
230
|
+
Fixtures.People.pluck('nickname').join(', '));
|
231
|
+
},
|
232
|
+
|
233
|
+
testReject: function() {
|
234
|
+
this.assertEqual(0,
|
235
|
+
Fixtures.Nicknames.reject(Prototype.K).length);
|
236
|
+
|
237
|
+
this.assertEqual('sam-, noradio, htonl',
|
238
|
+
Fixtures.Nicknames.reject(function(nickname) {
|
239
|
+
return nickname != nickname.toLowerCase();
|
240
|
+
}).join(', '));
|
241
|
+
},
|
242
|
+
|
243
|
+
testSortBy: function() {
|
244
|
+
this.assertEqual('htonl, noradio, sam-, Ulysses',
|
245
|
+
Fixtures.People.sortBy(function(value) {
|
246
|
+
return value.nickname.toLowerCase();
|
247
|
+
}).pluck('nickname').join(', '));
|
248
|
+
},
|
249
|
+
|
250
|
+
testToArray: function() {
|
251
|
+
var result = Fixtures.People.toArray();
|
252
|
+
this.assert(result != Fixtures.People); // they're different objects...
|
253
|
+
this.assertEqual(Fixtures.Nicknames.join(', '),
|
254
|
+
result.pluck('nickname').join(', ')); // but the values are the same
|
255
|
+
},
|
256
|
+
|
257
|
+
testZip: function() {
|
258
|
+
var result = [1, 2, 3].zip([4, 5, 6], [7, 8, 9]);
|
259
|
+
this.assertEqual('[[1, 4, 7], [2, 5, 8], [3, 6, 9]]', result.inspect());
|
260
|
+
|
261
|
+
result = [1, 2, 3].zip([4, 5, 6], [7, 8, 9], function(array) { return array.reverse() });
|
262
|
+
this.assertEqual('[[7, 4, 1], [8, 5, 2], [9, 6, 3]]', result.inspect());
|
263
|
+
},
|
264
|
+
|
265
|
+
testSize: function() {
|
266
|
+
this.assertEqual(4, Fixtures.People.size());
|
267
|
+
this.assertEqual(4, Fixtures.Nicknames.size());
|
268
|
+
this.assertEqual(26, Fixtures.Primes.size());
|
269
|
+
this.assertEqual(0, [].size());
|
270
|
+
}
|
271
|
+
});
|
@@ -0,0 +1,235 @@
|
|
1
|
+
var documentLoaded = document.loaded;
|
2
|
+
|
3
|
+
new Test.Unit.Runner({
|
4
|
+
|
5
|
+
// test firing an event and observing it on the element it's fired from
|
6
|
+
testCustomEventFiring: function() {
|
7
|
+
var span = $("span"), fired = false, observer = function(event) {
|
8
|
+
this.assertEqual(span, event.element());
|
9
|
+
this.assertEqual(1, event.memo.index);
|
10
|
+
fired = true;
|
11
|
+
}.bind(this);
|
12
|
+
|
13
|
+
span.observe("test:somethingHappened", observer);
|
14
|
+
span.fire("test:somethingHappened", { index: 1 });
|
15
|
+
this.assert(fired);
|
16
|
+
|
17
|
+
fired = false;
|
18
|
+
span.fire("test:somethingElseHappened");
|
19
|
+
this.assert(!fired);
|
20
|
+
|
21
|
+
span.stopObserving("test:somethingHappened", observer);
|
22
|
+
span.fire("test:somethingHappened");
|
23
|
+
this.assert(!fired);
|
24
|
+
},
|
25
|
+
|
26
|
+
// test firing an event and observing it on a containing element
|
27
|
+
testCustomEventBubbling: function() {
|
28
|
+
var span = $("span"), outer = $("outer"), fired = false, observer = function(event) {
|
29
|
+
this.assertEqual(span, event.element());
|
30
|
+
fired = true;
|
31
|
+
}.bind(this);
|
32
|
+
|
33
|
+
outer.observe("test:somethingHappened", observer);
|
34
|
+
span.fire("test:somethingHappened");
|
35
|
+
this.assert(fired);
|
36
|
+
|
37
|
+
fired = false;
|
38
|
+
span.fire("test:somethingElseHappened");
|
39
|
+
this.assert(!fired);
|
40
|
+
|
41
|
+
outer.stopObserving("test:somethingHappened", observer);
|
42
|
+
span.fire("test:somethingHappened");
|
43
|
+
this.assert(!fired);
|
44
|
+
},
|
45
|
+
|
46
|
+
testCustomEventCanceling: function() {
|
47
|
+
var span = $("span"), outer = $("outer"), inner = $("inner");
|
48
|
+
var fired = false, stopped = false;
|
49
|
+
|
50
|
+
function outerObserver(event) {
|
51
|
+
fired = span == event.element();
|
52
|
+
}
|
53
|
+
|
54
|
+
function innerObserver(event) {
|
55
|
+
event.stop();
|
56
|
+
stopped = true;
|
57
|
+
}
|
58
|
+
|
59
|
+
inner.observe("test:somethingHappened", innerObserver);
|
60
|
+
outer.observe("test:somethingHappened", outerObserver);
|
61
|
+
span.fire("test:somethingHappened");
|
62
|
+
this.assert(stopped);
|
63
|
+
this.assert(!fired);
|
64
|
+
|
65
|
+
fired = stopped = false;
|
66
|
+
inner.stopObserving("test:somethingHappened", innerObserver);
|
67
|
+
span.fire("test:somethingHappened");
|
68
|
+
this.assert(!stopped);
|
69
|
+
this.assert(fired);
|
70
|
+
|
71
|
+
outer.stopObserving("test:somethingHappened", outerObserver);
|
72
|
+
},
|
73
|
+
|
74
|
+
testEventObjectIsExtended: function() {
|
75
|
+
var span = $("span"), event, observedEvent, observer = function(e) { observedEvent = e };
|
76
|
+
span.observe("test:somethingHappened", observer);
|
77
|
+
event = span.fire("test:somethingHappened");
|
78
|
+
this.assertEqual(event, observedEvent);
|
79
|
+
this.assertEqual(Event.Methods.stop.methodize(), event.stop);
|
80
|
+
span.stopObserving("test:somethingHappened", observer);
|
81
|
+
|
82
|
+
event = span.fire("test:somethingHappenedButNoOneIsListening");
|
83
|
+
this.assertEqual(Event.Methods.stop.methodize(), event.stop);
|
84
|
+
},
|
85
|
+
|
86
|
+
testEventObserversAreBoundToTheObservedElement: function() {
|
87
|
+
var span = $("span"), target, observer = function() { target = this };
|
88
|
+
|
89
|
+
span.observe("test:somethingHappened", observer);
|
90
|
+
span.fire("test:somethingHappened");
|
91
|
+
span.stopObserving("test:somethingHappened", observer);
|
92
|
+
this.assertEqual(span, target);
|
93
|
+
target = null;
|
94
|
+
|
95
|
+
var outer = $("outer");
|
96
|
+
outer.observe("test:somethingHappened", observer);
|
97
|
+
span.fire("test:somethingHappened");
|
98
|
+
outer.stopObserving("test:somethingHappened", observer);
|
99
|
+
this.assertEqual(outer, target);
|
100
|
+
},
|
101
|
+
|
102
|
+
testMultipleCustomEventObserversWithTheSameHandler: function() {
|
103
|
+
var span = $("span"), count = 0, observer = function() { count++ };
|
104
|
+
|
105
|
+
span.observe("test:somethingHappened", observer);
|
106
|
+
span.observe("test:somethingElseHappened", observer);
|
107
|
+
span.fire("test:somethingHappened");
|
108
|
+
this.assertEqual(1, count);
|
109
|
+
span.fire("test:somethingElseHappened");
|
110
|
+
this.assertEqual(2, count);
|
111
|
+
},
|
112
|
+
|
113
|
+
testStopObservingWithoutArguments: function() {
|
114
|
+
var span = $("span"), count = 0, observer = function() { count++ };
|
115
|
+
|
116
|
+
span.observe("test:somethingHappened", observer);
|
117
|
+
span.observe("test:somethingElseHappened", observer);
|
118
|
+
span.stopObserving();
|
119
|
+
span.fire("test:somethingHappened");
|
120
|
+
this.assertEqual(0, count);
|
121
|
+
span.fire("test:somethingElseHappened");
|
122
|
+
this.assertEqual(0, count);
|
123
|
+
},
|
124
|
+
|
125
|
+
testStopObservingWithoutHandlerArgument: function() {
|
126
|
+
var span = $("span"), count = 0, observer = function() { count++ };
|
127
|
+
|
128
|
+
span.observe("test:somethingHappened", observer);
|
129
|
+
span.observe("test:somethingElseHappened", observer);
|
130
|
+
span.stopObserving("test:somethingHappened");
|
131
|
+
span.fire("test:somethingHappened");
|
132
|
+
this.assertEqual(0, count);
|
133
|
+
span.fire("test:somethingElseHappened");
|
134
|
+
this.assertEqual(1, count);
|
135
|
+
span.stopObserving("test:somethingElseHappened");
|
136
|
+
span.fire("test:somethingElseHappened");
|
137
|
+
this.assertEqual(1, count);
|
138
|
+
},
|
139
|
+
|
140
|
+
testStopObservingRemovesHandlerFromCache: function() {
|
141
|
+
var span = $("span"), observer = Prototype.emptyFunction, eventID;
|
142
|
+
|
143
|
+
span.observe("test:somethingHappened", observer);
|
144
|
+
|
145
|
+
var registry = span.getStorage().get('prototype_event_registry');
|
146
|
+
|
147
|
+
this.assert(registry);
|
148
|
+
this.assert(Object.isArray(registry.get('test:somethingHappened')));
|
149
|
+
this.assertEqual(1, registry.get('test:somethingHappened').length);
|
150
|
+
|
151
|
+
span.stopObserving("test:somethingHappened", observer);
|
152
|
+
|
153
|
+
registry = span.getStorage().get('prototype_event_registry');
|
154
|
+
|
155
|
+
this.assert(registry);
|
156
|
+
this.assert(Object.isArray(registry.get('test:somethingHappened')));
|
157
|
+
this.assertEqual(0, registry.get('test:somethingHappened').length);
|
158
|
+
},
|
159
|
+
|
160
|
+
testObserveAndStopObservingAreChainable: function() {
|
161
|
+
var span = $("span"), observer = Prototype.emptyFunction;
|
162
|
+
|
163
|
+
this.assertEqual(span, span.observe("test:somethingHappened", observer));
|
164
|
+
this.assertEqual(span, span.stopObserving("test:somethingHappened", observer));
|
165
|
+
|
166
|
+
span.observe("test:somethingHappened", observer);
|
167
|
+
this.assertEqual(span, span.stopObserving("test:somethingHappened"));
|
168
|
+
|
169
|
+
span.observe("test:somethingHappened", observer);
|
170
|
+
this.assertEqual(span, span.stopObserving());
|
171
|
+
this.assertEqual(span, span.stopObserving()); // assert it again, after there are no observers
|
172
|
+
|
173
|
+
span.observe("test:somethingHappened", observer);
|
174
|
+
this.assertEqual(span, span.observe("test:somethingHappened", observer)); // try to reuse the same observer
|
175
|
+
span.stopObserving();
|
176
|
+
},
|
177
|
+
|
178
|
+
testDocumentLoaded: function() {
|
179
|
+
this.assert(!documentLoaded);
|
180
|
+
this.assert(document.loaded);
|
181
|
+
},
|
182
|
+
|
183
|
+
testDocumentContentLoadedEventFiresBeforeWindowLoad: function() {
|
184
|
+
this.assert(eventResults.contentLoaded, "contentLoaded");
|
185
|
+
this.assert(eventResults.contentLoaded.endOfDocument, "contentLoaded.endOfDocument");
|
186
|
+
this.assert(!eventResults.contentLoaded.windowLoad, "!contentLoaded.windowLoad");
|
187
|
+
this.assert(eventResults.windowLoad, "windowLoad");
|
188
|
+
this.assert(eventResults.windowLoad.endOfDocument, "windowLoad.endOfDocument");
|
189
|
+
this.assert(eventResults.windowLoad.contentLoaded, "windowLoad.contentLoaded");
|
190
|
+
},
|
191
|
+
|
192
|
+
testEventStopped: function() {
|
193
|
+
var span = $("span"), event;
|
194
|
+
|
195
|
+
span.observe("test:somethingHappened", Prototype.emptyFunction);
|
196
|
+
event = span.fire("test:somethingHappened");
|
197
|
+
this.assert(!event.stopped, "event.stopped should be false with an empty observer");
|
198
|
+
span.stopObserving("test:somethingHappened");
|
199
|
+
|
200
|
+
span.observe("test:somethingHappened", function(e) { e.stop() });
|
201
|
+
event = span.fire("test:somethingHappened");
|
202
|
+
this.assert(event.stopped, "event.stopped should be true for an observer that calls stop");
|
203
|
+
span.stopObserving("test:somethingHappened");
|
204
|
+
},
|
205
|
+
|
206
|
+
testEventFindElement: function() {
|
207
|
+
var span = $("span"), event;
|
208
|
+
event = span.fire("test:somethingHappened");
|
209
|
+
this.assertElementMatches(event.findElement(), 'span#span');
|
210
|
+
this.assertElementMatches(event.findElement('span'), 'span#span');
|
211
|
+
this.assertElementMatches(event.findElement('p'), 'p#inner');
|
212
|
+
this.assertEqual(null, event.findElement('div.does_not_exist'));
|
213
|
+
this.assertElementMatches(event.findElement('.does_not_exist, span'), 'span#span');
|
214
|
+
},
|
215
|
+
|
216
|
+
testEventIDDuplication: function() {
|
217
|
+
$('container').down().observe("test:somethingHappened", Prototype.emptyFunction);
|
218
|
+
$('container').innerHTML += $('container').innerHTML;
|
219
|
+
this.assertUndefined($('container').down(1)._prototypeEventID);
|
220
|
+
}
|
221
|
+
});
|
222
|
+
|
223
|
+
document.observe("dom:loaded", function(event) {
|
224
|
+
eventResults.contentLoaded = {
|
225
|
+
endOfDocument: eventResults.endOfDocument,
|
226
|
+
windowLoad: eventResults.windowLoad
|
227
|
+
};
|
228
|
+
});
|
229
|
+
|
230
|
+
Event.observe(window, "load", function(event) {
|
231
|
+
eventResults.windowLoad = {
|
232
|
+
endOfDocument: eventResults.endOfDocument,
|
233
|
+
contentLoaded: eventResults.contentLoaded
|
234
|
+
};
|
235
|
+
});
|