alloy-js-test-san 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/README.rdoc +83 -0
  2. data/Rakefile +27 -0
  3. data/VERSION.yml +4 -0
  4. data/bin/jstest +10 -0
  5. data/lib/js_test_san/runner.rb +70 -0
  6. data/lib/js_test_san/test.rb +17 -0
  7. data/lib/js_test_san/test_case.rb +103 -0
  8. data/lib/js_test_san.rb +2 -0
  9. data/test/fixtures/a_unit_test.html +27 -0
  10. data/test/fixtures/a_unit_test.js +22 -0
  11. data/test/regression/prototype/unit/ajax_test.html +29 -0
  12. data/test/regression/prototype/unit/array_test.html +28 -0
  13. data/test/regression/prototype/unit/assets/prototype.js +4900 -0
  14. data/test/regression/prototype/unit/assets/unittest.css +50 -0
  15. data/test/regression/prototype/unit/assets/unittest.js +615 -0
  16. data/test/regression/prototype/unit/assets/unittest_transport.js +1 -0
  17. data/test/regression/prototype/unit/base_test.html +27 -0
  18. data/test/regression/prototype/unit/class_test.html +27 -0
  19. data/test/regression/prototype/unit/date_test.html +27 -0
  20. data/test/regression/prototype/unit/dom_test.html +304 -0
  21. data/test/regression/prototype/unit/element_mixins_test.html +30 -0
  22. data/test/regression/prototype/unit/enumerable_test.html +35 -0
  23. data/test/regression/prototype/unit/event_test.html +31 -0
  24. data/test/regression/prototype/unit/fixtures/ajax.html +2 -0
  25. data/test/regression/prototype/unit/fixtures/ajax.js +42 -0
  26. data/test/regression/prototype/unit/fixtures/array.html +1 -0
  27. data/test/regression/prototype/unit/fixtures/class.js +83 -0
  28. data/test/regression/prototype/unit/fixtures/content.html +1 -0
  29. data/test/regression/prototype/unit/fixtures/data.json +1 -0
  30. data/test/regression/prototype/unit/fixtures/dom.css +84 -0
  31. data/test/regression/prototype/unit/fixtures/dom.html +278 -0
  32. data/test/regression/prototype/unit/fixtures/dom.js +17 -0
  33. data/test/regression/prototype/unit/fixtures/element_mixins.html +4 -0
  34. data/test/regression/prototype/unit/fixtures/element_mixins.js +2 -0
  35. data/test/regression/prototype/unit/fixtures/empty.html +0 -0
  36. data/test/regression/prototype/unit/fixtures/empty.js +1 -0
  37. data/test/regression/prototype/unit/fixtures/enumerable.html +8 -0
  38. data/test/regression/prototype/unit/fixtures/enumerable.js +23 -0
  39. data/test/regression/prototype/unit/fixtures/event.html +4 -0
  40. data/test/regression/prototype/unit/fixtures/form.html +108 -0
  41. data/test/regression/prototype/unit/fixtures/function.js +13 -0
  42. data/test/regression/prototype/unit/fixtures/hash.js +25 -0
  43. data/test/regression/prototype/unit/fixtures/hello.js +1 -0
  44. data/test/regression/prototype/unit/fixtures/logo.gif +0 -0
  45. data/test/regression/prototype/unit/fixtures/object.html +6 -0
  46. data/test/regression/prototype/unit/fixtures/object.js +7 -0
  47. data/test/regression/prototype/unit/fixtures/position.html +9 -0
  48. data/test/regression/prototype/unit/fixtures/selector.html +71 -0
  49. data/test/regression/prototype/unit/fixtures/string.js +8 -0
  50. data/test/regression/prototype/unit/fixtures/unittest.html +18 -0
  51. data/test/regression/prototype/unit/form_test.html +135 -0
  52. data/test/regression/prototype/unit/function_test.html +27 -0
  53. data/test/regression/prototype/unit/hash_test.html +27 -0
  54. data/test/regression/prototype/unit/number_test.html +27 -0
  55. data/test/regression/prototype/unit/object_test.html +32 -0
  56. data/test/regression/prototype/unit/periodical_executer_test.html +27 -0
  57. data/test/regression/prototype/unit/position_test.html +36 -0
  58. data/test/regression/prototype/unit/prototype_test.html +27 -0
  59. data/test/regression/prototype/unit/range_test.html +27 -0
  60. data/test/regression/prototype/unit/regexp_test.html +27 -0
  61. data/test/regression/prototype/unit/selector_test.html +98 -0
  62. data/test/regression/prototype/unit/string_test.html +27 -0
  63. data/test/regression/prototype/unit/tests/ajax_test.js +379 -0
  64. data/test/regression/prototype/unit/tests/array_test.js +186 -0
  65. data/test/regression/prototype/unit/tests/base_test.js +43 -0
  66. data/test/regression/prototype/unit/tests/class_test.js +136 -0
  67. data/test/regression/prototype/unit/tests/date_test.js +5 -0
  68. data/test/regression/prototype/unit/tests/dom_test.js +1493 -0
  69. data/test/regression/prototype/unit/tests/element_mixins_test.js +32 -0
  70. data/test/regression/prototype/unit/tests/enumerable_test.js +271 -0
  71. data/test/regression/prototype/unit/tests/event_test.js +235 -0
  72. data/test/regression/prototype/unit/tests/form_test.js +382 -0
  73. data/test/regression/prototype/unit/tests/function_test.js +133 -0
  74. data/test/regression/prototype/unit/tests/hash_test.js +178 -0
  75. data/test/regression/prototype/unit/tests/number_test.js +44 -0
  76. data/test/regression/prototype/unit/tests/object_test.js +180 -0
  77. data/test/regression/prototype/unit/tests/periodical_executer_test.js +15 -0
  78. data/test/regression/prototype/unit/tests/position_test.js +44 -0
  79. data/test/regression/prototype/unit/tests/prototype_test.js +43 -0
  80. data/test/regression/prototype/unit/tests/range_test.js +58 -0
  81. data/test/regression/prototype/unit/tests/regexp_test.js +42 -0
  82. data/test/regression/prototype/unit/tests/selector_test.js +408 -0
  83. data/test/regression/prototype/unit/tests/string_test.js +548 -0
  84. data/test/regression/prototype/unit/tests/unittest_test.js +148 -0
  85. data/test/regression/prototype/unit/unittest_test.html +45 -0
  86. data/test/regression/prototype/upstream +1 -0
  87. data/test/test_helper.rb +20 -0
  88. data/test/unit/runner_test.rb +165 -0
  89. data/test/unit/test_case_test.rb +167 -0
  90. data/test/unit/test_test.rb +24 -0
  91. 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
+ });
@@ -0,0 +1,5 @@
1
+ new Test.Unit.Runner({
2
+ testDateToJSON: function() {
3
+ this.assertEqual('\"1970-01-01T00:00:00Z\"', new Date(Date.UTC(1970, 0, 1)).toJSON());
4
+ }
5
+ });