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,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
|
+
});
|
@@ -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
|
+
});
|
@@ -0,0 +1,58 @@
|
|
1
|
+
new Test.Unit.Runner({
|
2
|
+
|
3
|
+
testInclude: function() {
|
4
|
+
this.assert(!$R(0, 0, true).include(0));
|
5
|
+
this.assert($R(0, 0, false).include(0));
|
6
|
+
|
7
|
+
this.assert($R(0, 5, true).include(0));
|
8
|
+
this.assert($R(0, 5, true).include(4));
|
9
|
+
this.assert(!$R(0, 5, true).include(5));
|
10
|
+
|
11
|
+
this.assert($R(0, 5, false).include(0));
|
12
|
+
this.assert($R(0, 5, false).include(5));
|
13
|
+
this.assert(!$R(0, 5, false).include(6));
|
14
|
+
},
|
15
|
+
|
16
|
+
testEach: function() {
|
17
|
+
var results = [];
|
18
|
+
$R(0, 0, true).each(function(value) {
|
19
|
+
results.push(value);
|
20
|
+
});
|
21
|
+
|
22
|
+
this.assertEnumEqual([], results);
|
23
|
+
|
24
|
+
results = [];
|
25
|
+
$R(0, 3, false).each(function(value) {
|
26
|
+
results.push(value);
|
27
|
+
});
|
28
|
+
|
29
|
+
this.assertEnumEqual([0, 1, 2, 3], results);
|
30
|
+
},
|
31
|
+
|
32
|
+
testAny: function() {
|
33
|
+
this.assert(!$R(1, 1, true).any());
|
34
|
+
this.assert($R(0, 3, false).any(function(value) {
|
35
|
+
return value == 3;
|
36
|
+
}));
|
37
|
+
},
|
38
|
+
|
39
|
+
testAll: function() {
|
40
|
+
this.assert($R(1, 1, true).all());
|
41
|
+
this.assert($R(0, 3, false).all(function(value) {
|
42
|
+
return value <= 3;
|
43
|
+
}));
|
44
|
+
},
|
45
|
+
|
46
|
+
testToArray: function() {
|
47
|
+
this.assertEnumEqual([], $R(0, 0, true).toArray());
|
48
|
+
this.assertEnumEqual([0], $R(0, 0, false).toArray());
|
49
|
+
this.assertEnumEqual([0], $R(0, 1, true).toArray());
|
50
|
+
this.assertEnumEqual([0, 1], $R(0, 1, false).toArray());
|
51
|
+
this.assertEnumEqual([-3, -2, -1, 0, 1, 2], $R(-3, 3, true).toArray());
|
52
|
+
this.assertEnumEqual([-3, -2, -1, 0, 1, 2, 3], $R(-3, 3, false).toArray());
|
53
|
+
},
|
54
|
+
|
55
|
+
testDefaultsToNotExclusive: function() {
|
56
|
+
this.assertEnumEqual($R(-3,3), $R(-3,3,false));
|
57
|
+
}
|
58
|
+
});
|
@@ -0,0 +1,42 @@
|
|
1
|
+
new Test.Unit.Runner({
|
2
|
+
testRegExpEscape: function() {
|
3
|
+
this.assertEqual('word', RegExp.escape('word'));
|
4
|
+
this.assertEqual('\\/slashes\\/', RegExp.escape('/slashes/'));
|
5
|
+
this.assertEqual('\\\\backslashes\\\\', RegExp.escape('\\backslashes\\'));
|
6
|
+
this.assertEqual('\\\\border of word', RegExp.escape('\\border of word'));
|
7
|
+
|
8
|
+
this.assertEqual('\\(\\?\\:non-capturing\\)', RegExp.escape('(?:non-capturing)'));
|
9
|
+
this.assertEqual('non-capturing', new RegExp(RegExp.escape('(?:') + '([^)]+)').exec('(?:non-capturing)')[1]);
|
10
|
+
|
11
|
+
this.assertEqual('\\(\\?\\=positive-lookahead\\)', RegExp.escape('(?=positive-lookahead)'));
|
12
|
+
this.assertEqual('positive-lookahead', new RegExp(RegExp.escape('(?=') + '([^)]+)').exec('(?=positive-lookahead)')[1]);
|
13
|
+
|
14
|
+
this.assertEqual('\\(\\?<\\=positive-lookbehind\\)', RegExp.escape('(?<=positive-lookbehind)'));
|
15
|
+
this.assertEqual('positive-lookbehind', new RegExp(RegExp.escape('(?<=') + '([^)]+)').exec('(?<=positive-lookbehind)')[1]);
|
16
|
+
|
17
|
+
this.assertEqual('\\(\\?\\!negative-lookahead\\)', RegExp.escape('(?!negative-lookahead)'));
|
18
|
+
this.assertEqual('negative-lookahead', new RegExp(RegExp.escape('(?!') + '([^)]+)').exec('(?!negative-lookahead)')[1]);
|
19
|
+
|
20
|
+
this.assertEqual('\\(\\?<\\!negative-lookbehind\\)', RegExp.escape('(?<!negative-lookbehind)'));
|
21
|
+
this.assertEqual('negative-lookbehind', new RegExp(RegExp.escape('(?<!') + '([^)]+)').exec('(?<!negative-lookbehind)')[1]);
|
22
|
+
|
23
|
+
this.assertEqual('\\[\\\\w\\]\\+', RegExp.escape('[\\w]+'));
|
24
|
+
this.assertEqual('character class', new RegExp(RegExp.escape('[') + '([^\\]]+)').exec('[character class]')[1]);
|
25
|
+
|
26
|
+
this.assertEqual('<div>', new RegExp(RegExp.escape('<div>')).exec('<td><div></td>')[0]);
|
27
|
+
|
28
|
+
this.assertEqual('false', RegExp.escape(false));
|
29
|
+
this.assertEqual('undefined', RegExp.escape());
|
30
|
+
this.assertEqual('null', RegExp.escape(null));
|
31
|
+
this.assertEqual('42', RegExp.escape(42));
|
32
|
+
|
33
|
+
this.assertEqual('\\\\n\\\\r\\\\t', RegExp.escape('\\n\\r\\t'));
|
34
|
+
this.assertEqual('\n\r\t', RegExp.escape('\n\r\t'));
|
35
|
+
this.assertEqual('\\{5,2\\}', RegExp.escape('{5,2}'));
|
36
|
+
|
37
|
+
this.assertEqual(
|
38
|
+
'\\/\\(\\[\\.\\*\\+\\?\\^\\=\\!\\:\\$\\{\\}\\(\\)\\|\\[\\\\\\]\\\\\\\/\\\\\\\\\\]\\)\\/g',
|
39
|
+
RegExp.escape('/([.*+?^=!:${}()|[\\]\\/\\\\])/g')
|
40
|
+
);
|
41
|
+
}
|
42
|
+
});
|