opal 0.3.41 → 0.3.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +3 -0
  3. data/CHANGELOG.md +14 -1
  4. data/Gemfile +2 -5
  5. data/Rakefile +41 -3
  6. data/bin/opal +33 -0
  7. data/lib/opal.rb +2 -12
  8. data/lib/opal/core_ext.rb +5 -0
  9. data/lib/opal/grammar.rb +2207 -2138
  10. data/lib/opal/grammar.y +21 -0
  11. data/lib/opal/grammar_helpers.rb +360 -0
  12. data/lib/opal/lexer.rb +55 -401
  13. data/lib/opal/lexer_scope.rb +28 -0
  14. data/lib/opal/parser.rb +155 -171
  15. data/lib/opal/target_scope.rb +257 -0
  16. data/lib/opal/version.rb +1 -1
  17. data/opal.gemspec +6 -2
  18. data/opal/opal-parser.js.erb +3 -2
  19. data/opal/opal.rb +20 -18
  20. data/opal/opal/array.rb +21 -12
  21. data/opal/opal/basic_object.rb +2 -1
  22. data/opal/opal/boolean.rb +3 -0
  23. data/opal/opal/browser_loader.js +57 -0
  24. data/opal/opal/class.rb +51 -13
  25. data/opal/opal/date.rb +1 -20
  26. data/opal/opal/enumerable.rb +66 -33
  27. data/opal/opal/error.rb +2 -0
  28. data/opal/opal/hash.rb +1 -1
  29. data/opal/opal/kernel.rb +14 -3
  30. data/opal/opal/nil_class.rb +4 -0
  31. data/opal/opal/proc.rb +9 -1
  32. data/opal/opal/racc.rb +2 -2
  33. data/opal/opal/regexp.rb +1 -1
  34. data/opal/opal/runtime.js +14 -4
  35. data/opal/opal/string.rb +21 -4
  36. data/opal/opal/time.rb +27 -0
  37. data/spec/core/array/allocate_spec.rb +7 -1
  38. data/spec/core/array/append_spec.rb +18 -3
  39. data/spec/core/array/array_spec.rb +7 -0
  40. data/spec/core/array/assoc_spec.rb +23 -8
  41. data/spec/core/array/at_spec.rb +23 -3
  42. data/spec/core/array/choice_spec.rb +20 -0
  43. data/spec/core/array/clear_spec.rb +45 -4
  44. data/spec/core/array/combination_spec.rb +55 -0
  45. data/spec/core/array/compact_spec.rb +72 -1
  46. data/spec/core/array/constructor_spec.rb +13 -2
  47. data/spec/core/array/count_spec.rb +15 -7
  48. data/spec/core/array/delete_at_spec.rb +44 -1
  49. data/spec/core/array/delete_if_spec.rb +52 -2
  50. data/spec/core/array/delete_spec.rb +83 -2
  51. data/spec/core/array/drop_spec.rb +24 -16
  52. data/spec/core/array/drop_while_spec.rb +17 -0
  53. data/spec/core/array/each_index_spec.rb +11 -1
  54. data/spec/core/array/each_spec.rb +20 -2
  55. data/spec/core/array/empty_spec.rb +4 -1
  56. data/spec/core/array/eql_spec.rb +14 -0
  57. data/spec/core/array/fetch_spec.rb +31 -2
  58. data/spec/core/array/find_index_spec.rb +8 -0
  59. data/spec/core/array/first_spec.rb +45 -8
  60. data/spec/core/array/fixtures/classes.rb +538 -0
  61. data/spec/core/array/flatten_spec.rb +200 -7
  62. data/spec/core/array/frozen_spec.rb +32 -0
  63. data/spec/core/array/include_spec.rb +16 -1
  64. data/spec/core/array/index_spec.rb +5 -25
  65. data/spec/core/array/insert_spec.rb +37 -3
  66. data/spec/core/array/inspect_spec.rb +6 -12
  67. data/spec/core/array/intersection_spec.rb +55 -4
  68. data/spec/core/array/join_spec.rb +29 -4
  69. data/spec/core/array/keep_if_spec.rb +13 -6
  70. data/spec/core/array/last_spec.rb +35 -1
  71. data/spec/core/array/length_spec.rb +7 -4
  72. data/spec/core/array/map_spec.rb +9 -47
  73. data/spec/core/array/minus_spec.rb +68 -4
  74. data/spec/core/array/multiply_spec.rb +138 -6
  75. data/spec/core/array/new_spec.rb +92 -3
  76. data/spec/core/array/ntimes_spec.rb +26 -0
  77. data/spec/core/array/plus_spec.rb +48 -2
  78. data/spec/core/array/pop_spec.rb +159 -39
  79. data/spec/core/array/push_spec.rb +29 -1
  80. data/spec/core/array/rassoc_spec.rb +31 -2
  81. data/spec/core/array/reject_spec.rb +89 -2
  82. data/spec/core/array/replace_spec.rb +7 -29
  83. data/spec/core/array/reverse_each_spec.rb +25 -1
  84. data/spec/core/array/reverse_spec.rb +53 -1
  85. data/spec/core/array/rindex_spec.rb +55 -5
  86. data/spec/core/array/select_spec.rb +35 -8
  87. data/spec/core/array/shared/collect.rb +0 -0
  88. data/spec/core/array/shared/enumeratorize.rb +12 -0
  89. data/spec/core/array/shared/eql.rb +95 -0
  90. data/spec/core/array/shared/index.rb +37 -0
  91. data/spec/core/array/shared/inspect.rb +3 -0
  92. data/spec/core/array/shared/join.rb +7 -0
  93. data/spec/core/array/shared/keep_if.rb +0 -0
  94. data/spec/core/array/shared/length.rb +0 -0
  95. data/spec/core/array/shared/replace.rb +0 -0
  96. data/spec/core/array/shared/slice.rb +0 -0
  97. data/spec/core/array/shift_spec.rb +132 -23
  98. data/spec/core/array/shuffle_spec.rb +82 -6
  99. data/spec/core/array/size_spec.rb +7 -4
  100. data/spec/core/array/slice_spec.rb +132 -1
  101. data/spec/core/array/sort_spec.rb +263 -14
  102. data/spec/core/array/take_spec.rb +24 -16
  103. data/spec/core/array/take_while_spec.rb +14 -10
  104. data/spec/core/array/to_a_spec.rb +18 -1
  105. data/spec/core/array/to_ary_spec.rb +15 -1
  106. data/spec/core/array/try_convert_spec.rb +39 -2
  107. data/spec/core/array/uniq_spec.rb +148 -3
  108. data/spec/core/array/unshift_spec.rb +36 -1
  109. data/spec/core/array/zip_spec.rb +36 -1
  110. data/spec/core/class/new_spec.rb +8 -6
  111. data/spec/core/enumerable/all_spec.rb +37 -9
  112. data/spec/core/enumerable/any_spec.rb +45 -7
  113. data/spec/core/enumerable/collect_spec.rb +4 -1
  114. data/spec/core/enumerable/count_spec.rb +4 -1
  115. data/spec/core/enumerable/detect_spec.rb +2 -2
  116. data/spec/core/enumerable/drop_spec.rb +4 -1
  117. data/spec/core/enumerable/drop_while_spec.rb +4 -1
  118. data/spec/core/enumerable/each_slice_spec.rb +2 -1
  119. data/spec/core/enumerable/each_with_index_spec.rb +4 -1
  120. data/spec/core/enumerable/each_with_object_spec.rb +4 -1
  121. data/spec/core/enumerable/entries_spec.rb +4 -1
  122. data/spec/core/enumerable/find_all_spec.rb +4 -1
  123. data/spec/core/enumerable/find_index_spec.rb +4 -1
  124. data/spec/core/enumerable/find_spec.rb +5 -2
  125. data/spec/core/enumerable/first_spec.rb +4 -1
  126. data/spec/core/enumerable/fixtures/classes.rb +198 -2
  127. data/spec/core/enumerable/grep_spec.rb +4 -1
  128. data/spec/core/enumerable/take_spec.rb +4 -1
  129. data/spec/core/enumerable/to_a_spec.rb +4 -1
  130. data/spec/core/false/and_spec.rb +11 -0
  131. data/spec/core/false/inspect_spec.rb +7 -0
  132. data/spec/core/false/or_spec.rb +11 -0
  133. data/spec/core/false/to_s_spec.rb +7 -0
  134. data/spec/core/false/xor_spec.rb +11 -0
  135. data/spec/core/kernel/rand_spec.rb +5 -5
  136. data/spec/core/module/const_get_spec.rb +4 -4
  137. data/spec/core/module/fixtures/classes.rb +434 -0
  138. data/spec/core/module/method_defined_spec.rb +49 -0
  139. data/spec/core/module/module_function_spec.rb +28 -0
  140. data/spec/core/nil/and_spec.rb +3 -1
  141. data/spec/core/nil/dup_spec.rb +7 -0
  142. data/spec/core/nil/inspect_spec.rb +3 -1
  143. data/spec/core/nil/nil_spec.rb +3 -1
  144. data/spec/core/nil/or_spec.rb +4 -2
  145. data/spec/core/nil/to_a_spec.rb +3 -1
  146. data/spec/core/nil/to_f_spec.rb +3 -1
  147. data/spec/core/nil/to_i_spec.rb +3 -1
  148. data/spec/core/nil/to_s_spec.rb +3 -1
  149. data/spec/core/nil/xor_spec.rb +4 -2
  150. data/spec/core/string/element_reference_spec.rb +14 -1
  151. data/spec/core/string/fixtures/classes.rb +0 -0
  152. data/spec/core/true/and_spec.rb +11 -0
  153. data/spec/core/true/inspect_spec.rb +7 -0
  154. data/spec/core/true/or_spec.rb +11 -0
  155. data/spec/core/true/to_s_spec.rb +7 -0
  156. data/spec/core/true/xor_spec.rb +11 -0
  157. data/spec/{core → core_ext}/array/element_reference_spec.rb +0 -0
  158. data/spec/{core → core_ext}/array/equal_value_spec.rb +0 -0
  159. data/spec/{core → core_ext}/array/fill_spec.rb +0 -0
  160. data/spec/{core → core_ext}/array/reduce_spec.rb +0 -0
  161. data/spec/core_ext/basic_object/send_spec.rb +3 -3
  162. data/spec/{core → core_ext}/boolean/singleton_class_spec.rb +0 -0
  163. data/spec/{core → core_ext}/boolean/to_json_spec.rb +0 -0
  164. data/spec/core_ext/class/_inherited_spec.rb +3 -3
  165. data/spec/core_ext/class/proc_methods_spec.rb +2 -2
  166. data/spec/core_ext/class/singleton_methods_spec.rb +8 -8
  167. data/spec/core_ext/method_missing_spec.rb +3 -3
  168. data/spec/core_ext/native/method_missing_spec.rb +3 -2
  169. data/spec/core_ext/native/to_native_spec.rb +3 -2
  170. data/spec/{core → core_ext}/nil/to_json_spec.rb +0 -0
  171. data/spec/date.rb +0 -0
  172. data/spec/fileutils.rb +0 -0
  173. data/spec/filters/ancestors.rb +4 -0
  174. data/spec/filters/array_delete.rb +3 -0
  175. data/spec/filters/array_fetch.rb +3 -0
  176. data/spec/filters/array_first.rb +3 -0
  177. data/spec/filters/array_flatten.rb +14 -0
  178. data/spec/filters/array_intersection.rb +5 -0
  179. data/spec/filters/array_join.rb +6 -0
  180. data/spec/filters/array_subclasses.rb +4 -0
  181. data/spec/filters/block_args.rb +3 -0
  182. data/spec/filters/coerce_integer.rb +9 -0
  183. data/spec/filters/frozen.rb +4 -0
  184. data/spec/filters/mocks.rb +3 -0
  185. data/spec/filters/should_receive.rb +4 -0
  186. data/spec/filters/tainted.rb +7 -0
  187. data/spec/fixtures/class.rb +124 -0
  188. data/spec/fixtures/class_variables.rb +0 -0
  189. data/spec/fixtures/constants.rb +0 -0
  190. data/spec/grammar/alias_spec.rb +1 -1
  191. data/spec/grammar/def_spec.rb +1 -0
  192. data/spec/grammar/lvar_spec.rb +1 -2
  193. data/spec/grammar/nth_ref_spec.rb +13 -0
  194. data/spec/grammar/sclass_spec.rb +6 -7
  195. data/spec/grammar/str_spec.rb +4 -4
  196. data/spec/grammar/string_spec.rb +8 -0
  197. data/spec/grammar/xstr_spec.rb +4 -4
  198. data/spec/iconv.rb +0 -0
  199. data/spec/language/alias_spec.rb +140 -3
  200. data/spec/language/and_spec.rb +14 -7
  201. data/spec/language/array_spec.rb +57 -5
  202. data/spec/language/block_spec.rb +466 -49
  203. data/spec/language/break_spec.rb +294 -44
  204. data/spec/language/case_spec.rb +151 -3
  205. data/spec/language/class_spec.rb +196 -0
  206. data/spec/language/class_variable_spec.rb +56 -0
  207. data/spec/language/def_spec.rb +507 -4
  208. data/spec/language/defined_spec.rb +19 -7
  209. data/spec/language/ensure_spec.rb +26 -39
  210. data/spec/language/execution_spec.rb +15 -0
  211. data/spec/language/fixtures/array.rb +11 -0
  212. data/spec/language/fixtures/block.rb +57 -0
  213. data/spec/language/fixtures/break.rb +240 -0
  214. data/spec/language/fixtures/ensure.rb +72 -0
  215. data/spec/language/fixtures/literal_lambda.rb +7 -0
  216. data/spec/language/fixtures/metaclass.rb +33 -0
  217. data/spec/language/fixtures/module.rb +24 -0
  218. data/spec/language/fixtures/next.rb +78 -12
  219. data/spec/language/fixtures/return.rb +118 -0
  220. data/spec/language/fixtures/send.rb +110 -0
  221. data/spec/language/fixtures/send_1.9.rb +22 -0
  222. data/spec/language/fixtures/super.rb +308 -0
  223. data/spec/language/fixtures/variables.rb +58 -0
  224. data/spec/language/fixtures/yield.rb +5 -0
  225. data/spec/language/for_spec.rb +192 -0
  226. data/spec/language/hash_spec.rb +29 -5
  227. data/spec/language/if_spec.rb +90 -9
  228. data/spec/language/literal_lambda_spec.rb +1 -47
  229. data/spec/language/loop_spec.rb +39 -2
  230. data/spec/language/metaclass_spec.rb +151 -5
  231. data/spec/language/module_spec.rb +56 -0
  232. data/spec/language/next_spec.rb +370 -12
  233. data/spec/language/not_spec.rb +55 -0
  234. data/spec/language/numbers_spec.rb +56 -0
  235. data/spec/language/or_spec.rb +31 -3
  236. data/spec/language/order_spec.rb +79 -0
  237. data/spec/language/precedence_spec.rb +483 -0
  238. data/spec/language/proc_spec.rb +249 -21
  239. data/spec/language/redo_spec.rb +67 -0
  240. data/spec/language/rescue_spec.rb +121 -0
  241. data/spec/language/retry_spec.rb +56 -0
  242. data/spec/language/return_spec.rb +281 -0
  243. data/spec/language/send_spec.rb +141 -48
  244. data/spec/language/singleton_class_spec.rb +1 -1
  245. data/spec/language/string_spec.rb +11 -0
  246. data/spec/language/super_spec.rb +213 -133
  247. data/spec/language/symbol_spec.rb +2 -1
  248. data/spec/language/undef_spec.rb +3 -1
  249. data/spec/language/unless_spec.rb +6 -2
  250. data/spec/language/until_spec.rb +102 -3
  251. data/spec/language/variables_spec.rb +1212 -16
  252. data/spec/language/versions/array_1.9.rb +39 -0
  253. data/spec/language/versions/case_1.9.rb +20 -0
  254. data/spec/language/versions/hash_1.9.rb +18 -0
  255. data/spec/language/versions/literal_lambda_1.9.rb +143 -0
  256. data/spec/language/versions/not_1.9.rb +22 -0
  257. data/spec/language/versions/send_1.9.rb +241 -0
  258. data/spec/language/versions/symbol_1.9.rb +15 -0
  259. data/spec/language/versions/variables_1.9.rb +8 -0
  260. data/spec/language/while_spec.rb +70 -5
  261. data/spec/language/yield_spec.rb +32 -6
  262. data/spec/mspec/guards/block_device.rb +0 -0
  263. data/spec/mspec/guards/endian.rb +0 -0
  264. data/spec/mspec/helpers/environment.rb +0 -0
  265. data/spec/mspec/helpers/language_version.rb +0 -0
  266. data/spec/mspec/helpers/tmp.rb +0 -0
  267. data/spec/ospec/filter.rb +32 -0
  268. data/spec/ospec/main.rb.erb +18 -0
  269. data/spec/ospec/phantom.rb +97 -0
  270. data/spec/ospec/runner.rb +95 -0
  271. data/spec/ospec/sprockets.js +40 -0
  272. data/spec/pp.rb +3 -0
  273. data/spec/rbconfig.rb +5 -0
  274. data/spec/spec_helper.rb +53 -26
  275. data/spec/yaml.rb +0 -0
  276. metadata +275 -31
  277. data/config.ru +0 -8
  278. data/lib/opal/processor.rb +0 -47
  279. data/lib/opal/scope.rb +0 -236
  280. data/lib/opal/server.rb +0 -94
  281. data/spec/core/boolean/and_spec.rb +0 -17
  282. data/spec/core/boolean/inspect_spec.rb +0 -9
  283. data/spec/core/boolean/or_spec.rb +0 -17
  284. data/spec/core/boolean/to_s_spec.rb +0 -9
  285. data/spec/core/boolean/xor_spec.rb +0 -17
@@ -0,0 +1,22 @@
1
+ module LangSendSpecs
2
+ # module_function
3
+
4
+ def self.fooR(*r); r; end
5
+ # def self.fooM0RQ1(*r, q); [r, q]; end
6
+ # def self.fooM0RQ2(*r, s, q); [r, s, q]; end
7
+ # def self.fooM1RQ1(a, *r, q); [a, r, q]; end
8
+ # def self.fooM1O1RQ1(a, b=9, *r, q); [a, b, r, q]; end
9
+ # def self.fooM1O1RQ2(a, b=9, *r, q, t); [a, b, r, q, t]; end
10
+
11
+ # def self.fooO1Q1(a=1, b); [a,b]; end
12
+ # def self.fooM1O1Q1(a,b=2,c); [a,b,c]; end
13
+ # def self.fooM2O1Q1(a,b,c=3,d); [a,b,c,d]; end
14
+ # def self.fooM2O2Q1(a,b,c=3,d=4,e); [a,b,c,d,e]; end
15
+ # def self.fooO4Q1(a=1,b=2,c=3,d=4,e); [a,b,c,d,e]; end
16
+ # def self.fooO4Q2(a=1,b=2,c=3,d=4,e,f); [a,b,c,d,e,f]; end
17
+
18
+ # def self.destructure2((a,b)); a+b; end
19
+ # def self.destructure2b((a,b)); [a,b]; end
20
+ # def self.destructure4r((a,b,*c,d,e)); [a,b,c,d,e]; end
21
+
22
+ end
@@ -0,0 +1,308 @@
1
+ module Super
2
+ module S1
3
+ class A
4
+ def foo(a)
5
+ a << "A#foo"
6
+ bar(a)
7
+ end
8
+ def bar(a)
9
+ a << "A#bar"
10
+ end
11
+ end
12
+ class B < A
13
+ def foo(a)
14
+ a << "B#foo"
15
+ super(a)
16
+ end
17
+ def bar(a)
18
+ a << "B#bar"
19
+ super(a)
20
+ end
21
+ end
22
+ end
23
+
24
+ module S2
25
+ class A
26
+ def baz(a)
27
+ a << "A#baz"
28
+ end
29
+ end
30
+ class B < A
31
+ def foo(a)
32
+ a << "B#foo"
33
+ baz(a)
34
+ end
35
+ end
36
+ class C < B
37
+ def baz(a)
38
+ a << "C#baz"
39
+ super(a)
40
+ end
41
+ end
42
+ end
43
+
44
+ module S3
45
+ class A
46
+ def foo(a)
47
+ a << "A#foo"
48
+ end
49
+ def self.foo(a)
50
+ a << "A::foo"
51
+ end
52
+ def self.bar(a)
53
+ a << "A::bar"
54
+ foo(a)
55
+ end
56
+ end
57
+ class B < A
58
+ def self.foo(a)
59
+ a << "B::foo"
60
+ super(a)
61
+ end
62
+ def self.bar(a)
63
+ a << "B::bar"
64
+ super(a)
65
+ end
66
+ end
67
+ end
68
+
69
+ module S4
70
+ class A
71
+ def foo(a)
72
+ a << "A#foo"
73
+ end
74
+ end
75
+ class B < A
76
+ def foo(a, b)
77
+ a << "B#foo(a,#{b})"
78
+ super(a)
79
+ end
80
+ end
81
+ end
82
+
83
+ class S5
84
+ def here
85
+ :good
86
+ end
87
+ end
88
+
89
+ class S6 < S5
90
+ def under
91
+ yield
92
+ end
93
+
94
+ def here
95
+ under {
96
+ super
97
+ }
98
+ end
99
+ end
100
+
101
+ class S7 < S5
102
+ define_method(:here) { super() }
103
+ end
104
+
105
+ module MS1
106
+ module ModA
107
+ def foo(a)
108
+ a << "ModA#foo"
109
+ bar(a)
110
+ end
111
+ def bar(a)
112
+ a << "ModA#bar"
113
+ end
114
+ end
115
+ class A
116
+ include ModA
117
+ end
118
+ module ModB
119
+ def bar(a)
120
+ a << "ModB#bar"
121
+ super(a)
122
+ end
123
+ end
124
+ class B < A
125
+ def foo(a)
126
+ a << "B#foo"
127
+ super(a)
128
+ end
129
+ include ModB
130
+ end
131
+ end
132
+
133
+ module MS2
134
+ class A
135
+ def baz(a)
136
+ a << "A#baz"
137
+ end
138
+ end
139
+ module ModB
140
+ def foo(a)
141
+ a << "ModB#foo"
142
+ baz(a)
143
+ end
144
+ end
145
+ class B < A
146
+ include ModB
147
+ end
148
+ class C < B
149
+ def baz(a)
150
+ a << "C#baz"
151
+ super(a)
152
+ end
153
+ end
154
+ end
155
+
156
+ module MS3
157
+ module ModA
158
+ def foo(a)
159
+ a << "ModA#foo"
160
+ end
161
+ def bar(a)
162
+ a << "ModA#bar"
163
+ foo(a)
164
+ end
165
+ end
166
+ class A
167
+ def foo(a)
168
+ a << "A#foo"
169
+ end
170
+ class << self
171
+ #include ModA
172
+ end
173
+ end
174
+ class B < A
175
+ def self.foo(a)
176
+ a << "B::foo"
177
+ super(a)
178
+ end
179
+ def self.bar(a)
180
+ a << "B::bar"
181
+ super(a)
182
+ end
183
+ end
184
+ end
185
+
186
+ module MS4
187
+ module Layer1
188
+ def example
189
+ 5
190
+ end
191
+ end
192
+
193
+ module Layer2
194
+ include Layer1
195
+ def example
196
+ super
197
+ end
198
+ end
199
+
200
+ class A
201
+ include Layer2
202
+ public :example
203
+ end
204
+ end
205
+
206
+ class MM_A
207
+ undef_method :is_a?
208
+ end
209
+
210
+ class MM_B < MM_A
211
+ def is_a?(blah)
212
+ # should fire the method_missing below
213
+ super
214
+ end
215
+
216
+ def method_missing(*)
217
+ false
218
+ end
219
+ end
220
+
221
+ class Alias1
222
+ def name
223
+ [:alias1]
224
+ end
225
+ end
226
+
227
+ class Alias2 < Alias1
228
+ def initialize
229
+ @times = 0
230
+ end
231
+
232
+ def name
233
+ if @times >= 10
234
+ raise "runaway super"
235
+ end
236
+
237
+ @times += 1
238
+
239
+ # Use this so that we can see collect all supers that we see.
240
+ # One bug that arises is that we call Alias2#name from Alias2#name
241
+ # as it's superclass. In that case, either we get a runaway recursion
242
+ # super OR we get the return value being [:alias2, :alias2, :alias1]
243
+ # rather than [:alias2, :alias1].
244
+ #
245
+ # Which one depends on caches and how super is implemented.
246
+ [:alias2] + super
247
+ end
248
+ end
249
+
250
+ class Alias3 < Alias2
251
+ alias_method :name3, :name
252
+ # In the method table for Alias3 now should be a special alias entry
253
+ # that references Alias2 and Alias2#name (probably as an object).
254
+ #
255
+ # When name3 is called then, Alias2 (NOT Alias3) is presented as the
256
+ # current module to Alias2#name, so that when super is called,
257
+ # Alias2->superclass is next.
258
+ #
259
+ # Otherwise, Alias2 is next, which is where name was to begin with,
260
+ # causing the wrong #name method to be called.
261
+ end
262
+
263
+ module AliasWithSuper
264
+ module AS1
265
+ def foo
266
+ :a
267
+ end
268
+ end
269
+
270
+ module BS1
271
+ def foo
272
+ [:b, super]
273
+ end
274
+ end
275
+
276
+ class Base
277
+ extend AS1
278
+ extend BS1
279
+ end
280
+
281
+ class Trigger < Base
282
+ class << self
283
+ def foo_quux
284
+ foo_baz
285
+ end
286
+
287
+ alias_method :foo_baz, :foo
288
+ alias_method :foo, :foo_quux
289
+ end
290
+ end
291
+ end
292
+
293
+ module RestArgsWithSuper
294
+ class A
295
+ def a(*args)
296
+ args
297
+ end
298
+ end
299
+
300
+ class B < A
301
+ def a(*args)
302
+ args << "foo"
303
+
304
+ super
305
+ end
306
+ end
307
+ end
308
+ end
@@ -0,0 +1,58 @@
1
+ module VariablesSpecs
2
+ class ParAsgn
3
+ attr_accessor :x
4
+
5
+ def initialize
6
+ @x = 0
7
+ end
8
+
9
+ def inc
10
+ @x += 1
11
+ end
12
+
13
+ def to_ary
14
+ [1,2,3,4]
15
+ end
16
+ end
17
+
18
+ class OpAsgn
19
+ attr_accessor :a, :b, :side_effect
20
+
21
+ def do_side_effect
22
+ self.side_effect = true
23
+ return @a
24
+ end
25
+
26
+ def do_more_side_effects
27
+ @a += 5
28
+ self
29
+ end
30
+
31
+ def do_bool_side_effects
32
+ @b += 1
33
+ self
34
+ end
35
+ end
36
+
37
+ class Hashalike
38
+ def [](k) k end
39
+ def []=(k, v) [k, v] end
40
+ end
41
+
42
+ def self.reverse_foo(a, b)
43
+ return b, a
44
+ end
45
+
46
+ class ArrayLike
47
+ def initialize(array)
48
+ @array = array
49
+ end
50
+
51
+ def to_a
52
+ @array
53
+ end
54
+ end
55
+
56
+ class ArraySubclass < Array
57
+ end
58
+ end
@@ -4,6 +4,11 @@ module YieldSpecs
4
4
  yield
5
5
  end
6
6
 
7
+ def ze(&block)
8
+ block = proc { block }
9
+ yield
10
+ end
11
+
7
12
  def s(a)
8
13
  yield(a)
9
14
  end
@@ -0,0 +1,192 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ # for name[, name]... in expr [do]
4
+ # body
5
+ # end
6
+ describe "The for expression" do
7
+ pending "iterates over an Enumerable passing each element to the block" do
8
+ # j = 0
9
+ # for i in 1..3
10
+ # j += i
11
+ # end
12
+ # j.should == 6
13
+ end
14
+
15
+ pending "iterates over an Hash passing each key-value pair to the block" do
16
+ # k = 0
17
+ # l = 0
18
+
19
+ # for i, j in { 1 => 10, 2 => 20 }
20
+ # k += i
21
+ # l += j
22
+ # end
23
+
24
+ # k.should == 3
25
+ # l.should == 30
26
+ end
27
+
28
+ pending "iterates over any object responding to 'each'" do
29
+ # class XYZ
30
+ # def each
31
+ # (0..10).each { |i| yield i }
32
+ # end
33
+ # end
34
+
35
+ # j = 0
36
+ # for i in XYZ.new
37
+ # j += i
38
+ # end
39
+ # j.should == 55
40
+ end
41
+
42
+ pending "allows an instance variable as an iterator name" do
43
+ # m = [1,2,3]
44
+ # n = 0
45
+ # for @var in m
46
+ # n += 1
47
+ # end
48
+ # @var.should == 3
49
+ # n.should == 3
50
+ end
51
+
52
+ pending "allows a class variable as an iterator name" do
53
+ # class OFor
54
+ # m = [1,2,3]
55
+ # n = 0
56
+ # for @@var in m
57
+ # n += 1
58
+ # end
59
+ # @@var.should == 3
60
+ # n.should == 3
61
+ # end
62
+ end
63
+
64
+ pending "allows a constant as an iterator name" do
65
+ # class OFor
66
+ # m = [1,2,3]
67
+ # n = 0
68
+ # for CONST in m
69
+ # n += 1
70
+ # end
71
+ # CONST.should == 3
72
+ # n.should == 3
73
+ # end
74
+ end
75
+
76
+ ruby_version_is ""..."1.9" do
77
+ it "splats multiple arguments together if there are fewer arguments than values" do
78
+ # class OFor
79
+ # def each
80
+ # [[1,2,3], [4,5,6]].each do |a|
81
+ # yield(a[0],a[1],a[2])
82
+ # end
83
+ # end
84
+ # end
85
+ # o = OFor.new
86
+ # qs = []
87
+ # for q in o
88
+ # qs << q
89
+ # end
90
+ # qs.should == [[1,2,3], [4,5,6]]
91
+ # q.should == [4,5,6]
92
+ end
93
+ end
94
+
95
+ # 1.9 behaviour verified by nobu in
96
+ # http://redmine.ruby-lang.org/issues/show/2053
97
+ ruby_version_is "1.9" do
98
+ pending "yields only as many values as there are arguments" do
99
+ # class OFor
100
+ # def each
101
+ # [[1,2,3], [4,5,6]].each do |a|
102
+ # yield(a[0],a[1],a[2])
103
+ # end
104
+ # end
105
+ # end
106
+ # o = OFor.new
107
+ # qs = []
108
+ # for q in o
109
+ # qs << q
110
+ # end
111
+ # qs.should == [1, 4]
112
+ # q.should == 4
113
+ end
114
+ end
115
+
116
+ pending "optionally takes a 'do' after the expression" do
117
+ # j = 0
118
+ # for i in 1..3 do
119
+ # j += i
120
+ # end
121
+ # j.should == 6
122
+ end
123
+
124
+ pending "allows body begin on the same line if do is used" do
125
+ # j = 0
126
+ # for i in 1..3 do j += i
127
+ # end
128
+ # j.should == 6
129
+ end
130
+
131
+ pending "executes code in containing variable scope" do
132
+ # for i in 1..2
133
+ # a = 123
134
+ # end
135
+
136
+ # a.should == 123
137
+ end
138
+
139
+ pending "executes code in containing variable scope with 'do'" do
140
+ # for i in 1..2 do
141
+ # a = 123
142
+ # end
143
+
144
+ # a.should == 123
145
+ end
146
+
147
+ pending "returns expr" do
148
+ # for i in 1..3; end.should == (1..3)
149
+ # for i,j in { 1 => 10, 2 => 20 }; end.should == { 1 => 10, 2 => 20 }
150
+ end
151
+
152
+ pending "breaks out of a loop upon 'break', returning nil" do
153
+ # j = 0
154
+ # for i in 1..3
155
+ # j += i
156
+
157
+ # break if i == 2
158
+ # end.should == nil
159
+
160
+ # j.should == 3
161
+ end
162
+
163
+ pending "allows 'break' to have an argument which becomes the value of the for expression" do
164
+ # for i in 1..3
165
+ # break 10 if i == 2
166
+ # end.should == 10
167
+ end
168
+
169
+ pending "starts the next iteration with 'next'" do
170
+ # j = 0
171
+ # for i in 1..5
172
+ # next if i == 2
173
+
174
+ # j += i
175
+ # end
176
+
177
+ # j.should == 13
178
+ end
179
+
180
+ pending "repeats current iteration with 'redo'" do
181
+ # j = 0
182
+ # for i in 1..3
183
+ # j += i
184
+
185
+ # redo if i == 2 && j < 4
186
+ # end
187
+
188
+ # j.should == 8
189
+ end
190
+ end
191
+
192
+ # language_version __FILE__, "for"