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,136 @@
|
|
1
|
+
new Test.Unit.Runner({
|
2
|
+
testClassCreate: function() {
|
3
|
+
this.assert(Object.isFunction(Animal), 'Animal is not a constructor');
|
4
|
+
this.assertEnumEqual([Cat, Mouse, Dog, Ox], Animal.subclasses);
|
5
|
+
Animal.subclasses.each(function(subclass) {
|
6
|
+
this.assertEqual(Animal, subclass.superclass);
|
7
|
+
}, this);
|
8
|
+
|
9
|
+
var Bird = Class.create(Animal);
|
10
|
+
this.assertEqual(Bird, Animal.subclasses.last());
|
11
|
+
// for..in loop (for some reason) doesn't iterate over the constructor property in top-level classes
|
12
|
+
this.assertEnumEqual(Object.keys(new Animal).sort(), Object.keys(new Bird).without('constructor').sort());
|
13
|
+
},
|
14
|
+
|
15
|
+
testClassInstantiation: function() {
|
16
|
+
var pet = new Animal("Nibbles");
|
17
|
+
this.assertEqual("Nibbles", pet.name, "property not initialized");
|
18
|
+
this.assertEqual('Nibbles: Hi!', pet.say('Hi!'));
|
19
|
+
this.assertEqual(Animal, pet.constructor, "bad constructor reference");
|
20
|
+
this.assertUndefined(pet.superclass);
|
21
|
+
|
22
|
+
var Empty = Class.create();
|
23
|
+
this.assert('object', typeof new Empty);
|
24
|
+
},
|
25
|
+
|
26
|
+
testInheritance: function() {
|
27
|
+
var tom = new Cat('Tom');
|
28
|
+
this.assertEqual(Cat, tom.constructor, "bad constructor reference");
|
29
|
+
this.assertEqual(Animal, tom.constructor.superclass, 'bad superclass reference');
|
30
|
+
this.assertEqual('Tom', tom.name);
|
31
|
+
this.assertEqual('Tom: meow', tom.say('meow'));
|
32
|
+
this.assertEqual('Tom: Yuk! I only eat mice.', tom.eat(new Animal));
|
33
|
+
},
|
34
|
+
|
35
|
+
testSuperclassMethodCall: function() {
|
36
|
+
var tom = new Cat('Tom');
|
37
|
+
this.assertEqual('Tom: Yum!', tom.eat(new Mouse));
|
38
|
+
|
39
|
+
// augment the constructor and test
|
40
|
+
var Dodo = Class.create(Animal, {
|
41
|
+
initialize: function($super, name) {
|
42
|
+
$super(name);
|
43
|
+
this.extinct = true;
|
44
|
+
},
|
45
|
+
|
46
|
+
say: function($super, message) {
|
47
|
+
return $super(message) + " honk honk";
|
48
|
+
}
|
49
|
+
});
|
50
|
+
|
51
|
+
var gonzo = new Dodo('Gonzo');
|
52
|
+
this.assertEqual('Gonzo', gonzo.name);
|
53
|
+
this.assert(gonzo.extinct, 'Dodo birds should be extinct');
|
54
|
+
this.assertEqual("Gonzo: hello honk honk", gonzo.say("hello"));
|
55
|
+
},
|
56
|
+
|
57
|
+
testClassAddMethods: function() {
|
58
|
+
var tom = new Cat('Tom');
|
59
|
+
var jerry = new Mouse('Jerry');
|
60
|
+
|
61
|
+
Animal.addMethods({
|
62
|
+
sleep: function() {
|
63
|
+
return this.say('ZZZ');
|
64
|
+
}
|
65
|
+
});
|
66
|
+
|
67
|
+
Mouse.addMethods({
|
68
|
+
sleep: function($super) {
|
69
|
+
return $super() + " ... no, can't sleep! Gotta steal cheese!";
|
70
|
+
},
|
71
|
+
escape: function(cat) {
|
72
|
+
return this.say('(from a mousehole) Take that, ' + cat.name + '!');
|
73
|
+
}
|
74
|
+
});
|
75
|
+
|
76
|
+
this.assertEqual('Tom: ZZZ', tom.sleep(), "added instance method not available to subclass");
|
77
|
+
this.assertEqual("Jerry: ZZZ ... no, can't sleep! Gotta steal cheese!", jerry.sleep());
|
78
|
+
this.assertEqual("Jerry: (from a mousehole) Take that, Tom!", jerry.escape(tom));
|
79
|
+
// insure that a method has not propagated *up* the prototype chain:
|
80
|
+
this.assertUndefined(tom.escape);
|
81
|
+
this.assertUndefined(new Animal().escape);
|
82
|
+
|
83
|
+
Animal.addMethods({
|
84
|
+
sleep: function() {
|
85
|
+
return this.say('zZzZ');
|
86
|
+
}
|
87
|
+
});
|
88
|
+
|
89
|
+
this.assertEqual("Jerry: zZzZ ... no, can't sleep! Gotta steal cheese!", jerry.sleep());
|
90
|
+
},
|
91
|
+
|
92
|
+
testBaseClassWithMixin: function() {
|
93
|
+
var grass = new Plant('grass', 3);
|
94
|
+
this.assertRespondsTo('getValue', grass);
|
95
|
+
this.assertEqual('#<Plant: grass>', grass.inspect());
|
96
|
+
},
|
97
|
+
|
98
|
+
testSubclassWithMixin: function() {
|
99
|
+
var snoopy = new Dog('Snoopy', 12, 'male');
|
100
|
+
this.assertRespondsTo('reproduce', snoopy);
|
101
|
+
},
|
102
|
+
|
103
|
+
testSubclassWithMixins: function() {
|
104
|
+
var cow = new Ox('cow', 400, 'female');
|
105
|
+
this.assertEqual('#<Ox: cow>', cow.inspect());
|
106
|
+
this.assertRespondsTo('reproduce', cow);
|
107
|
+
this.assertRespondsTo('getValue', cow);
|
108
|
+
},
|
109
|
+
|
110
|
+
testClassWithToStringAndValueOfMethods: function() {
|
111
|
+
var Foo = Class.create({
|
112
|
+
toString: function() { return "toString" },
|
113
|
+
valueOf: function() { return "valueOf" }
|
114
|
+
});
|
115
|
+
|
116
|
+
var Bar = Class.create(Foo, {
|
117
|
+
valueOf: function() { return "myValueOf" }
|
118
|
+
});
|
119
|
+
|
120
|
+
var Parent = Class.create({
|
121
|
+
m1: function(){ return 'm1' },
|
122
|
+
m2: function(){ return 'm2' }
|
123
|
+
});
|
124
|
+
var Child = Class.create(Parent, {
|
125
|
+
m1: function($super) { return 'm1 child' },
|
126
|
+
m2: function($super) { return 'm2 child' }
|
127
|
+
});
|
128
|
+
|
129
|
+
this.assert(new Child().m1.toString().indexOf('m1 child') > -1);
|
130
|
+
|
131
|
+
this.assertEqual("toString", new Foo().toString());
|
132
|
+
this.assertEqual("valueOf", new Foo().valueOf());
|
133
|
+
this.assertEqual("toString", new Bar().toString());
|
134
|
+
this.assertEqual("myValueOf", new Bar().valueOf());
|
135
|
+
}
|
136
|
+
});
|