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,178 @@
|
|
1
|
+
new Test.Unit.Runner({
|
2
|
+
testSet: function() {
|
3
|
+
var h = $H({a: 'A'})
|
4
|
+
|
5
|
+
this.assertEqual('B', h.set('b', 'B'));
|
6
|
+
this.assertHashEqual({a: 'A', b: 'B'}, h);
|
7
|
+
|
8
|
+
this.assertUndefined(h.set('c'));
|
9
|
+
this.assertHashEqual({a: 'A', b: 'B', c: undefined}, h);
|
10
|
+
},
|
11
|
+
|
12
|
+
testGet: function() {
|
13
|
+
var h = $H({a: 'A'});
|
14
|
+
this.assertEqual('A', h.get('a'));
|
15
|
+
this.assertUndefined(h.a);
|
16
|
+
this.assertUndefined($H({}).get('a'));
|
17
|
+
|
18
|
+
this.assertUndefined($H({}).get('toString'));
|
19
|
+
this.assertUndefined($H({}).get('constructor'));
|
20
|
+
},
|
21
|
+
|
22
|
+
testUnset: function() {
|
23
|
+
var hash = $H(Fixtures.many);
|
24
|
+
this.assertEqual('B', hash.unset('b'));
|
25
|
+
this.assertHashEqual({a:'A', c: 'C', d:'D#'}, hash);
|
26
|
+
this.assertUndefined(hash.unset('z'));
|
27
|
+
this.assertHashEqual({a:'A', c: 'C', d:'D#'}, hash);
|
28
|
+
// not equivalent to Hash#remove
|
29
|
+
this.assertEqual('A', hash.unset('a', 'c'));
|
30
|
+
this.assertHashEqual({c: 'C', d:'D#'}, hash);
|
31
|
+
},
|
32
|
+
|
33
|
+
testToObject: function() {
|
34
|
+
var hash = $H(Fixtures.many), object = hash.toObject();
|
35
|
+
this.assertInstanceOf(Object, object);
|
36
|
+
this.assertHashEqual(Fixtures.many, object);
|
37
|
+
this.assertNotIdentical(Fixtures.many, object);
|
38
|
+
hash.set('foo', 'bar');
|
39
|
+
this.assertHashNotEqual(object, hash.toObject());
|
40
|
+
},
|
41
|
+
|
42
|
+
testConstruct: function() {
|
43
|
+
var object = Object.clone(Fixtures.one);
|
44
|
+
var h = new Hash(object), h2 = $H(object);
|
45
|
+
this.assertInstanceOf(Hash, h);
|
46
|
+
this.assertInstanceOf(Hash, h2);
|
47
|
+
|
48
|
+
this.assertHashEqual({}, new Hash());
|
49
|
+
this.assertHashEqual(object, h);
|
50
|
+
this.assertHashEqual(object, h2);
|
51
|
+
|
52
|
+
h.set('foo', 'bar');
|
53
|
+
this.assertHashNotEqual(object, h);
|
54
|
+
|
55
|
+
var clone = $H(h);
|
56
|
+
this.assertInstanceOf(Hash, clone);
|
57
|
+
this.assertHashEqual(h, clone);
|
58
|
+
h.set('foo', 'foo');
|
59
|
+
this.assertHashNotEqual(h, clone);
|
60
|
+
this.assertIdentical($H, Hash.from);
|
61
|
+
},
|
62
|
+
|
63
|
+
testKeys: function() {
|
64
|
+
this.assertEnumEqual([], $H({}).keys());
|
65
|
+
this.assertEnumEqual(['a'], $H(Fixtures.one).keys());
|
66
|
+
this.assertEnumEqual($w('a b c d'), $H(Fixtures.many).keys().sort());
|
67
|
+
this.assertEnumEqual($w('plus quad'), $H(Fixtures.functions).keys().sort());
|
68
|
+
},
|
69
|
+
|
70
|
+
testValues: function() {
|
71
|
+
this.assertEnumEqual([], $H({}).values());
|
72
|
+
this.assertEnumEqual(['A#'], $H(Fixtures.one).values());
|
73
|
+
this.assertEnumEqual($w('A B C D#'), $H(Fixtures.many).values().sort());
|
74
|
+
this.assertEnumEqual($w('function function'),
|
75
|
+
$H(Fixtures.functions).values().map(function(i){ return typeof i }));
|
76
|
+
this.assertEqual(9, $H(Fixtures.functions).get('quad')(3));
|
77
|
+
this.assertEqual(6, $H(Fixtures.functions).get('plus')(3));
|
78
|
+
},
|
79
|
+
|
80
|
+
testIndex: function() {
|
81
|
+
this.assertUndefined($H().index('foo'));
|
82
|
+
|
83
|
+
this.assert('a', $H(Fixtures.one).index('A#'));
|
84
|
+
this.assert('a', $H(Fixtures.many).index('A'));
|
85
|
+
this.assertUndefined($H(Fixtures.many).index('Z'))
|
86
|
+
|
87
|
+
var hash = $H({a:1,b:'2',c:1});
|
88
|
+
this.assert(['a','c'].include(hash.index(1)));
|
89
|
+
this.assertUndefined(hash.index('1'));
|
90
|
+
},
|
91
|
+
|
92
|
+
testMerge: function() {
|
93
|
+
var h = $H(Fixtures.many);
|
94
|
+
this.assertNotIdentical(h, h.merge());
|
95
|
+
this.assertNotIdentical(h, h.merge({}));
|
96
|
+
this.assertInstanceOf(Hash, h.merge());
|
97
|
+
this.assertInstanceOf(Hash, h.merge({}));
|
98
|
+
this.assertHashEqual(h, h.merge());
|
99
|
+
this.assertHashEqual(h, h.merge({}));
|
100
|
+
this.assertHashEqual(h, h.merge($H()));
|
101
|
+
this.assertHashEqual({a:'A', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.merge({aaa: 'AAA'}));
|
102
|
+
this.assertHashEqual({a:'A#', b:'B', c:'C', d:'D#' }, h.merge(Fixtures.one));
|
103
|
+
},
|
104
|
+
|
105
|
+
testUpdate: function() {
|
106
|
+
var h = $H(Fixtures.many);
|
107
|
+
this.assertIdentical(h, h.update());
|
108
|
+
this.assertIdentical(h, h.update({}));
|
109
|
+
this.assertHashEqual(h, h.update());
|
110
|
+
this.assertHashEqual(h, h.update({}));
|
111
|
+
this.assertHashEqual(h, h.update($H()));
|
112
|
+
this.assertHashEqual({a:'A', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.update({aaa: 'AAA'}));
|
113
|
+
this.assertHashEqual({a:'A#', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.update(Fixtures.one));
|
114
|
+
},
|
115
|
+
|
116
|
+
testToQueryString: function() {
|
117
|
+
this.assertEqual('', $H({}).toQueryString());
|
118
|
+
this.assertEqual('a%23=A', $H({'a#': 'A'}).toQueryString());
|
119
|
+
this.assertEqual('a=A%23', $H(Fixtures.one).toQueryString());
|
120
|
+
this.assertEqual('a=A&b=B&c=C&d=D%23', $H(Fixtures.many).toQueryString());
|
121
|
+
this.assertEqual("a=b&c", $H(Fixtures.value_undefined).toQueryString());
|
122
|
+
this.assertEqual("a=b&c", $H("a=b&c".toQueryParams()).toQueryString());
|
123
|
+
this.assertEqual("a=b&c=", $H(Fixtures.value_null).toQueryString());
|
124
|
+
this.assertEqual("a=b&c=0", $H(Fixtures.value_zero).toQueryString());
|
125
|
+
this.assertEqual("color=r&color=g&color=b", $H(Fixtures.multiple).toQueryString());
|
126
|
+
this.assertEqual("color=r&color=&color=g&color&color=0", $H(Fixtures.multiple_nil).toQueryString());
|
127
|
+
this.assertEqual("color=&color", $H(Fixtures.multiple_all_nil).toQueryString());
|
128
|
+
this.assertEqual("", $H(Fixtures.multiple_empty).toQueryString());
|
129
|
+
this.assertEqual("", $H({foo: {}, bar: {}}).toQueryString());
|
130
|
+
this.assertEqual("stuff%5B%5D=%24&stuff%5B%5D=a&stuff%5B%5D=%3B", $H(Fixtures.multiple_special).toQueryString());
|
131
|
+
this.assertHashEqual(Fixtures.multiple_special, $H(Fixtures.multiple_special).toQueryString().toQueryParams());
|
132
|
+
this.assertIdentical(Object.toQueryString, Hash.toQueryString);
|
133
|
+
},
|
134
|
+
|
135
|
+
testInspect: function() {
|
136
|
+
this.assertEqual('#<Hash:{}>', $H({}).inspect());
|
137
|
+
this.assertEqual("#<Hash:{'a': 'A#'}>", $H(Fixtures.one).inspect());
|
138
|
+
this.assertEqual("#<Hash:{'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D#'}>", $H(Fixtures.many).inspect());
|
139
|
+
},
|
140
|
+
|
141
|
+
testClone: function() {
|
142
|
+
var h = $H(Fixtures.many);
|
143
|
+
this.assertHashEqual(h, h.clone());
|
144
|
+
this.assertInstanceOf(Hash, h.clone());
|
145
|
+
this.assertNotIdentical(h, h.clone());
|
146
|
+
},
|
147
|
+
|
148
|
+
testToJSON: function() {
|
149
|
+
this.assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}',
|
150
|
+
$H({'b': [undefined, false, true, undefined], c: {a: 'hello!'}}).toJSON());
|
151
|
+
},
|
152
|
+
|
153
|
+
testAbilityToContainAnyKey: function() {
|
154
|
+
var h = $H({ _each: 'E', map: 'M', keys: 'K', pluck: 'P', unset: 'U' });
|
155
|
+
this.assertEnumEqual($w('_each keys map pluck unset'), h.keys().sort());
|
156
|
+
this.assertEqual('U', h.unset('unset'));
|
157
|
+
this.assertHashEqual({ _each: 'E', map: 'M', keys: 'K', pluck: 'P' }, h);
|
158
|
+
},
|
159
|
+
|
160
|
+
testHashToTemplateReplacements: function() {
|
161
|
+
var template = new Template("#{a} #{b}"), hash = $H({ a: "hello", b: "world" });
|
162
|
+
this.assertEqual("hello world", template.evaluate(hash.toObject()));
|
163
|
+
this.assertEqual("hello world", template.evaluate(hash));
|
164
|
+
this.assertEqual("hello", "#{a}".interpolate(hash));
|
165
|
+
},
|
166
|
+
|
167
|
+
testPreventIterationOverShadowedProperties: function() {
|
168
|
+
// redundant now that object is systematically cloned.
|
169
|
+
var FooMaker = function(value) {
|
170
|
+
this.key = value;
|
171
|
+
};
|
172
|
+
FooMaker.prototype.key = 'foo';
|
173
|
+
var foo = new FooMaker('bar');
|
174
|
+
this.assertEqual("key=bar", new Hash(foo).toQueryString());
|
175
|
+
this.assertEqual("key=bar", new Hash(new Hash(foo)).toQueryString());
|
176
|
+
}
|
177
|
+
|
178
|
+
});
|
@@ -0,0 +1,44 @@
|
|
1
|
+
new Test.Unit.Runner({
|
2
|
+
|
3
|
+
testNumberMathMethods: function() {
|
4
|
+
this.assertEqual(1, (0.9).round());
|
5
|
+
this.assertEqual(-2, (-1.9).floor());
|
6
|
+
this.assertEqual(-1, (-1.9).ceil());
|
7
|
+
|
8
|
+
$w('abs floor round ceil').each(function(method) {
|
9
|
+
this.assertEqual(Math[method](Math.PI), Math.PI[method]());
|
10
|
+
}, this);
|
11
|
+
},
|
12
|
+
|
13
|
+
testNumberToColorPart: function() {
|
14
|
+
this.assertEqual('00', (0).toColorPart());
|
15
|
+
this.assertEqual('0a', (10).toColorPart());
|
16
|
+
this.assertEqual('ff', (255).toColorPart());
|
17
|
+
},
|
18
|
+
|
19
|
+
testNumberToPaddedString: function() {
|
20
|
+
this.assertEqual('00', (0).toPaddedString(2, 16));
|
21
|
+
this.assertEqual('0a', (10).toPaddedString(2, 16));
|
22
|
+
this.assertEqual('ff', (255).toPaddedString(2, 16));
|
23
|
+
this.assertEqual('000', (0).toPaddedString(3));
|
24
|
+
this.assertEqual('010', (10).toPaddedString(3));
|
25
|
+
this.assertEqual('100', (100).toPaddedString(3));
|
26
|
+
this.assertEqual('1000', (1000).toPaddedString(3));
|
27
|
+
},
|
28
|
+
|
29
|
+
testNumberToJSON: function() {
|
30
|
+
this.assertEqual('null', Number.NaN.toJSON());
|
31
|
+
this.assertEqual('0', (0).toJSON());
|
32
|
+
this.assertEqual('-293', (-293).toJSON());
|
33
|
+
},
|
34
|
+
|
35
|
+
testNumberTimes: function() {
|
36
|
+
var results = [];
|
37
|
+
(5).times(function(i) { results.push(i) });
|
38
|
+
this.assertEnumEqual($R(0, 4), results);
|
39
|
+
|
40
|
+
results = [];
|
41
|
+
(5).times(function(i) { results.push(i * this.i) }, { i: 2 });
|
42
|
+
this.assertEnumEqual([0, 2, 4, 6, 8], results);
|
43
|
+
}
|
44
|
+
});
|
@@ -0,0 +1,180 @@
|
|
1
|
+
new Test.Unit.Runner({
|
2
|
+
testObjectExtend: function() {
|
3
|
+
var object = {foo: 'foo', bar: [1, 2, 3]};
|
4
|
+
this.assertIdentical(object, Object.extend(object));
|
5
|
+
this.assertHashEqual({foo: 'foo', bar: [1, 2, 3]}, object);
|
6
|
+
this.assertIdentical(object, Object.extend(object, {bla: 123}));
|
7
|
+
this.assertHashEqual({foo: 'foo', bar: [1, 2, 3], bla: 123}, object);
|
8
|
+
this.assertHashEqual({foo: 'foo', bar: [1, 2, 3], bla: null},
|
9
|
+
Object.extend(object, {bla: null}));
|
10
|
+
},
|
11
|
+
|
12
|
+
testObjectToQueryString: function() {
|
13
|
+
this.assertEqual('a=A&b=B&c=C&d=D%23', Object.toQueryString({a: 'A', b: 'B', c: 'C', d: 'D#'}));
|
14
|
+
},
|
15
|
+
|
16
|
+
testObjectClone: function() {
|
17
|
+
var object = {foo: 'foo', bar: [1, 2, 3]};
|
18
|
+
this.assertNotIdentical(object, Object.clone(object));
|
19
|
+
this.assertHashEqual(object, Object.clone(object));
|
20
|
+
this.assertHashEqual({}, Object.clone());
|
21
|
+
var clone = Object.clone(object);
|
22
|
+
delete clone.bar;
|
23
|
+
this.assertHashEqual({foo: 'foo'}, clone,
|
24
|
+
"Optimizing Object.clone perf using prototyping doesn't allow properties to be deleted.");
|
25
|
+
},
|
26
|
+
|
27
|
+
testObjectInspect: function() {
|
28
|
+
this.assertEqual('undefined', Object.inspect());
|
29
|
+
this.assertEqual('undefined', Object.inspect(undefined));
|
30
|
+
this.assertEqual('null', Object.inspect(null));
|
31
|
+
this.assertEqual("'foo\\\\b\\\'ar'", Object.inspect('foo\\b\'ar'));
|
32
|
+
this.assertEqual('[]', Object.inspect([]));
|
33
|
+
this.assertNothingRaised(function() { Object.inspect(window.Node) });
|
34
|
+
},
|
35
|
+
|
36
|
+
testObjectToJSON: function() {
|
37
|
+
this.assertUndefined(Object.toJSON(undefined));
|
38
|
+
this.assertUndefined(Object.toJSON(Prototype.K));
|
39
|
+
this.assertEqual('\"\"', Object.toJSON(''));
|
40
|
+
this.assertEqual('[]', Object.toJSON([]));
|
41
|
+
this.assertEqual('[\"a\"]', Object.toJSON(['a']));
|
42
|
+
this.assertEqual('[\"a\", 1]', Object.toJSON(['a', 1]));
|
43
|
+
this.assertEqual('[\"a\", {\"b\": null}]', Object.toJSON(['a', {'b': null}]));
|
44
|
+
this.assertEqual('{\"a\": \"hello!\"}', Object.toJSON({a: 'hello!'}));
|
45
|
+
this.assertEqual('{}', Object.toJSON({}));
|
46
|
+
this.assertEqual('{}', Object.toJSON({a: undefined, b: undefined, c: Prototype.K}));
|
47
|
+
this.assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}',
|
48
|
+
Object.toJSON({'b': [undefined, false, true, undefined], c: {a: 'hello!'}}));
|
49
|
+
this.assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}',
|
50
|
+
Object.toJSON($H({'b': [undefined, false, true, undefined], c: {a: 'hello!'}})));
|
51
|
+
this.assertEqual('true', Object.toJSON(true));
|
52
|
+
this.assertEqual('false', Object.toJSON(false));
|
53
|
+
this.assertEqual('null', Object.toJSON(null));
|
54
|
+
var sam = new Person('sam');
|
55
|
+
this.assertEqual('-sam', Object.toJSON(sam));
|
56
|
+
this.assertEqual('-sam', sam.toJSON());
|
57
|
+
var element = $('test');
|
58
|
+
this.assertUndefined(Object.toJSON(element));
|
59
|
+
element.toJSON = function(){return 'I\'m a div with id test'};
|
60
|
+
this.assertEqual('I\'m a div with id test', Object.toJSON(element));
|
61
|
+
},
|
62
|
+
|
63
|
+
testObjectToHTML: function() {
|
64
|
+
this.assertIdentical('', Object.toHTML());
|
65
|
+
this.assertIdentical('', Object.toHTML(''));
|
66
|
+
this.assertIdentical('', Object.toHTML(null));
|
67
|
+
this.assertIdentical('0', Object.toHTML(0));
|
68
|
+
this.assertIdentical('123', Object.toHTML(123));
|
69
|
+
this.assertEqual('hello world', Object.toHTML('hello world'));
|
70
|
+
this.assertEqual('hello world', Object.toHTML({toHTML: function() { return 'hello world' }}));
|
71
|
+
},
|
72
|
+
|
73
|
+
testObjectIsArray: function() {
|
74
|
+
this.assert(Object.isArray([]));
|
75
|
+
this.assert(Object.isArray([0]));
|
76
|
+
this.assert(Object.isArray([0, 1]));
|
77
|
+
this.assert(!Object.isArray({}));
|
78
|
+
this.assert(!Object.isArray($('list').childNodes));
|
79
|
+
this.assert(!Object.isArray());
|
80
|
+
this.assert(!Object.isArray(''));
|
81
|
+
this.assert(!Object.isArray('foo'));
|
82
|
+
this.assert(!Object.isArray(0));
|
83
|
+
this.assert(!Object.isArray(1));
|
84
|
+
this.assert(!Object.isArray(null));
|
85
|
+
this.assert(!Object.isArray(true));
|
86
|
+
this.assert(!Object.isArray(false));
|
87
|
+
this.assert(!Object.isArray(undefined));
|
88
|
+
},
|
89
|
+
|
90
|
+
testObjectIsHash: function() {
|
91
|
+
this.assert(Object.isHash($H()));
|
92
|
+
this.assert(Object.isHash(new Hash()));
|
93
|
+
this.assert(!Object.isHash({}));
|
94
|
+
this.assert(!Object.isHash(null));
|
95
|
+
this.assert(!Object.isHash());
|
96
|
+
this.assert(!Object.isHash(''));
|
97
|
+
this.assert(!Object.isHash(2));
|
98
|
+
this.assert(!Object.isHash(false));
|
99
|
+
this.assert(!Object.isHash(true));
|
100
|
+
this.assert(!Object.isHash([]));
|
101
|
+
},
|
102
|
+
|
103
|
+
testObjectIsElement: function() {
|
104
|
+
this.assert(Object.isElement(document.createElement('div')));
|
105
|
+
this.assert(Object.isElement(new Element('div')));
|
106
|
+
this.assert(Object.isElement($('testlog')));
|
107
|
+
this.assert(!Object.isElement(document.createTextNode('bla')));
|
108
|
+
|
109
|
+
// falsy variables should not mess up return value type
|
110
|
+
this.assertIdentical(false, Object.isElement(0));
|
111
|
+
this.assertIdentical(false, Object.isElement(''));
|
112
|
+
this.assertIdentical(false, Object.isElement(NaN));
|
113
|
+
this.assertIdentical(false, Object.isElement(null));
|
114
|
+
this.assertIdentical(false, Object.isElement(undefined));
|
115
|
+
},
|
116
|
+
|
117
|
+
testObjectIsFunction: function() {
|
118
|
+
this.assert(Object.isFunction(function() { }));
|
119
|
+
this.assert(Object.isFunction(Class.create()));
|
120
|
+
this.assert(!Object.isFunction("a string"));
|
121
|
+
this.assert(!Object.isFunction($("testlog")));
|
122
|
+
this.assert(!Object.isFunction([]));
|
123
|
+
this.assert(!Object.isFunction({}));
|
124
|
+
this.assert(!Object.isFunction(0));
|
125
|
+
this.assert(!Object.isFunction(false));
|
126
|
+
this.assert(!Object.isFunction(undefined));
|
127
|
+
},
|
128
|
+
|
129
|
+
testObjectIsString: function() {
|
130
|
+
this.assert(!Object.isString(function() { }));
|
131
|
+
this.assert(Object.isString("a string"));
|
132
|
+
this.assert(Object.isString(new String("a string")));
|
133
|
+
this.assert(!Object.isString(0));
|
134
|
+
this.assert(!Object.isString([]));
|
135
|
+
this.assert(!Object.isString({}));
|
136
|
+
this.assert(!Object.isString(false));
|
137
|
+
this.assert(!Object.isString(undefined));
|
138
|
+
this.assert(!Object.isString(document), 'host objects should return false rather than throw exceptions');
|
139
|
+
},
|
140
|
+
|
141
|
+
testObjectIsNumber: function() {
|
142
|
+
this.assert(Object.isNumber(0));
|
143
|
+
this.assert(Object.isNumber(1.0));
|
144
|
+
this.assert(Object.isNumber(new Number(0)));
|
145
|
+
this.assert(Object.isNumber(new Number(1.0)));
|
146
|
+
this.assert(!Object.isNumber(function() { }));
|
147
|
+
this.assert(!Object.isNumber({ test: function() { return 3 } }));
|
148
|
+
this.assert(!Object.isNumber("a string"));
|
149
|
+
this.assert(!Object.isNumber([]));
|
150
|
+
this.assert(!Object.isNumber({}));
|
151
|
+
this.assert(!Object.isNumber(false));
|
152
|
+
this.assert(!Object.isNumber(undefined));
|
153
|
+
this.assert(!Object.isNumber(document), 'host objects should return false rather than throw exceptions');
|
154
|
+
},
|
155
|
+
|
156
|
+
testObjectIsUndefined: function() {
|
157
|
+
this.assert(Object.isUndefined(undefined));
|
158
|
+
this.assert(!Object.isUndefined(null));
|
159
|
+
this.assert(!Object.isUndefined(false));
|
160
|
+
this.assert(!Object.isUndefined(0));
|
161
|
+
this.assert(!Object.isUndefined(""));
|
162
|
+
this.assert(!Object.isUndefined(function() { }));
|
163
|
+
this.assert(!Object.isUndefined([]));
|
164
|
+
this.assert(!Object.isUndefined({}));
|
165
|
+
},
|
166
|
+
|
167
|
+
// sanity check
|
168
|
+
testDoesntExtendObjectPrototype: function() {
|
169
|
+
// for-in is supported with objects
|
170
|
+
var iterations = 0, obj = { a: 1, b: 2, c: 3 };
|
171
|
+
for(property in obj) iterations++;
|
172
|
+
this.assertEqual(3, iterations);
|
173
|
+
|
174
|
+
// for-in is not supported with arrays
|
175
|
+
iterations = 0;
|
176
|
+
var arr = [1,2,3];
|
177
|
+
for(property in arr) iterations++;
|
178
|
+
this.assert(iterations > 3);
|
179
|
+
}
|
180
|
+
});
|
@@ -0,0 +1,15 @@
|
|
1
|
+
new Test.Unit.Runner({
|
2
|
+
testPeriodicalExecuterStop: function() {
|
3
|
+
var peEventCount = 0;
|
4
|
+
function peEventFired(pe) {
|
5
|
+
if (++peEventCount > 2) pe.stop();
|
6
|
+
}
|
7
|
+
|
8
|
+
// peEventFired will stop the PeriodicalExecuter after 3 callbacks
|
9
|
+
new PeriodicalExecuter(peEventFired, 0.05);
|
10
|
+
|
11
|
+
this.wait(600, function() {
|
12
|
+
this.assertEqual(3, peEventCount);
|
13
|
+
});
|
14
|
+
}
|
15
|
+
});
|
@@ -0,0 +1,44 @@
|
|
1
|
+
var testVar = 'to be updated';
|
2
|
+
|
3
|
+
new Test.Unit.Runner({
|
4
|
+
|
5
|
+
setup: function() {
|
6
|
+
scrollTo(0,0);
|
7
|
+
Position.prepare();
|
8
|
+
Position.includeScrollOffsets = false;
|
9
|
+
},
|
10
|
+
|
11
|
+
teardown: function() {
|
12
|
+
scrollTo(0,0);
|
13
|
+
Position.prepare();
|
14
|
+
Position.includeScrollOffsets = false;
|
15
|
+
},
|
16
|
+
|
17
|
+
testPrepare: function() {
|
18
|
+
Position.prepare();
|
19
|
+
this.assertEqual(0, Position.deltaX);
|
20
|
+
this.assertEqual(0, Position.deltaY);
|
21
|
+
scrollTo(20,30);
|
22
|
+
Position.prepare();
|
23
|
+
this.assertEqual(20, Position.deltaX);
|
24
|
+
this.assertEqual(30, Position.deltaY);
|
25
|
+
},
|
26
|
+
|
27
|
+
testWithin: function() {
|
28
|
+
[true, false].each(function(withScrollOffsets) {
|
29
|
+
Position.includeScrollOffsets = withScrollOffsets;
|
30
|
+
this.assert(!Position.within($('body_absolute'), 9, 9), 'outside left/top');
|
31
|
+
this.assert(Position.within($('body_absolute'), 10, 10), 'left/top corner');
|
32
|
+
this.assert(Position.within($('body_absolute'), 10, 19), 'left/bottom corner');
|
33
|
+
this.assert(!Position.within($('body_absolute'), 10, 20), 'outside bottom');
|
34
|
+
}, this);
|
35
|
+
|
36
|
+
scrollTo(20,30);
|
37
|
+
Position.prepare();
|
38
|
+
Position.includeScrollOffsets = true;
|
39
|
+
this.assert(!Position.within($('body_absolute'), 9, 9), 'outside left/top');
|
40
|
+
this.assert(Position.within($('body_absolute'), 10, 10), 'left/top corner');
|
41
|
+
this.assert(Position.within($('body_absolute'), 10, 19), 'left/bottom corner');
|
42
|
+
this.assert(!Position.within($('body_absolute'), 10, 20), 'outside bottom');
|
43
|
+
}
|
44
|
+
});
|