opal 0.3.41 → 0.3.42

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,23 +1,27 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
1
3
  describe "The '&&' statement" do
4
+
2
5
  it "short-circuits evaluation at the first condition to be false" do
3
6
  x = nil
4
7
  true && false && x = 1
5
8
  x.should be_nil
6
9
  end
7
10
 
8
- it "evaluates to the first condition not to be true" do
11
+ it "evalutes to the first condition not to be true" do
9
12
  ("yes" && 1 && nil && true).should == nil
10
13
  ("yes" && 1 && false && true).should == false
11
14
  end
12
15
 
13
- it "evaluates to the last condition if all are true" do
16
+ it "evalutes to the last condition if all are true" do
14
17
  ("yes" && 1).should == 1
15
18
  (1 && "yes").should == "yes"
16
19
  end
17
20
 
18
21
  it "evaluates the full set of chained conditions during assignment" do
19
- x = y = nil
22
+ x, y = nil
20
23
  x = 1 && y = 2
24
+ # "1 && y = 2" is evaluated and then assigned to x
21
25
  x.should == 2
22
26
  end
23
27
 
@@ -26,6 +30,7 @@ describe "The '&&' statement" do
26
30
  (true && ()).should be_nil
27
31
  (() && ()).should be_nil
28
32
  end
33
+
29
34
  end
30
35
 
31
36
  describe "The 'and' statement" do
@@ -35,19 +40,20 @@ describe "The 'and' statement" do
35
40
  x.should be_nil
36
41
  end
37
42
 
38
- it "evaluates to the first condition not to be true" do
43
+ it "evalutes to the first condition not to be true" do
39
44
  ("yes" and 1 and nil and true).should == nil
40
45
  ("yes" and 1 and false and true).should == false
41
46
  end
42
47
 
43
- it "evaluates to the last condition if all are true" do
48
+ it "evalutes to the last condition if all are true" do
44
49
  ("yes" and 1).should == 1
45
50
  (1 and "yes").should == "yes"
46
51
  end
47
52
 
48
53
  it "when used in assignment, evaluates and assigns expressions individually" do
49
- x = y = nil
54
+ x, y = nil
50
55
  x = 1 and y = 2
56
+ # evaluates (x=1) and (y=2)
51
57
  x.should == 1
52
58
  end
53
59
 
@@ -56,4 +62,5 @@ describe "The 'and' statement" do
56
62
  (true and ()).should be_nil
57
63
  (() and ()).should be_nil
58
64
  end
59
- end
65
+
66
+ end
@@ -1,3 +1,6 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+ require File.expand_path('../fixtures/array', __FILE__)
3
+
1
4
  describe "Array literals" do
2
5
  it "[] should return a new array populated with the given elements" do
3
6
  array = [1, 'a', nil]
@@ -22,7 +25,7 @@ describe "Array literals" do
22
25
  end
23
26
  end
24
27
 
25
- describe "Barewood array literal" do
28
+ describe "Bareword array literal" do
26
29
  it "%w() transforms unquoted barewords into an array" do
27
30
  a = 3
28
31
  %w(a #{3+a} 3).should == ["a", '#{3+a}', "3"]
@@ -40,7 +43,7 @@ describe "Barewood array literal" do
40
43
 
41
44
  it "treats consecutive whitespace characters the same as one" do
42
45
  %w(a b c d).should == ["a", "b", "c", "d"]
43
- %w(hello
46
+ %W(hello
44
47
  world).should == ["hello", "world"]
45
48
  end
46
49
 
@@ -54,12 +57,61 @@ c d).should == ["a", "b\nc", "d"]
54
57
  end
55
58
 
56
59
  describe "The unpacking splat operator (*)" do
57
- it "when applied to a literal nested array, unpacks its elements into then containing array" do
60
+ it "when applied to a literal nested array, unpacks its elements into the containing array" do
58
61
  [1, 2, *[3, 4, 5]].should == [1, 2, 3, 4, 5]
59
62
  end
60
63
 
61
- it "when applied to a nested references array, unpacks its elements into the containing array" do
64
+ it "when applied to a nested referenced array, unpacks its elements into the containing array" do
62
65
  splatted_array = [3, 4, 5]
63
66
  [1, 2, *splatted_array].should == [1, 2, 3, 4, 5]
64
67
  end
65
- end
68
+
69
+ ruby_bug "#5124", "1.9.3.194" do
70
+ pending "returns a new array containing the same values when applied to an array inside an empty array" do
71
+ splatted_array = [3, 4, 5]
72
+ [*splatted_array].should == splatted_array
73
+ [*splatted_array].should_not equal(splatted_array)
74
+ end
75
+ end
76
+
77
+ pending "unpacks the start and count arguments in an array slice assignment" do
78
+ alphabet_1 = ['a'..'z'].to_a
79
+ alphabet_2 = alphabet_1.dup
80
+ start_and_count_args = [1, 10]
81
+
82
+ alphabet_1[1, 10] = 'a'
83
+ alphabet_2[*start_and_count_args] = 'a'
84
+
85
+ alphabet_1.should == alphabet_2
86
+ end
87
+
88
+ pending "unpacks arguments as if they were listed statically" do
89
+ static = [1,2,3,4]
90
+ receiver = static.dup
91
+ args = [0,1]
92
+ static[0,1] = []
93
+ static.should == [2,3,4]
94
+ receiver[*args] = []
95
+ receiver.should == static
96
+ end
97
+
98
+ it "unpacks a literal array into arguments in a method call" do
99
+ tester = ArraySpec::Splat.new
100
+ tester.unpack_3args(*[1, 2, 3]).should == [1, 2, 3]
101
+ tester.unpack_4args(1, 2, *[3, 4]).should == [1, 2, 3, 4]
102
+ tester.unpack_4args("a", %w(b c), *%w(d e)).should == ["a", ["b", "c"], "d", "e"]
103
+ end
104
+
105
+ it "unpacks a referenced array into arguments in a method call" do
106
+ args = [1, 2, 3]
107
+ tester = ArraySpec::Splat.new
108
+ tester.unpack_3args(*args).should == [1, 2, 3]
109
+ tester.unpack_4args(0, *args).should == [0, 1, 2, 3]
110
+ end
111
+ end
112
+
113
+ describe "The packing splat operator (*)" do
114
+
115
+ end
116
+
117
+ # language_version __FILE__, "array"
@@ -1,22 +1,5 @@
1
- module BlockSpecs
2
- class Yielder
3
- def z
4
- yield
5
- end
6
-
7
- def m(*a)
8
- yield(*a)
9
- end
10
-
11
- def s(a)
12
- yield(a)
13
- end
14
-
15
- def r(a)
16
- yield(*a)
17
- end
18
- end
19
- end
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+ require File.expand_path('../fixtures/block', __FILE__)
20
3
 
21
4
  describe "A block" do
22
5
  before :each do
@@ -28,17 +11,33 @@ describe "A block" do
28
11
  @y.z { var }.should == 1
29
12
  end
30
13
 
31
- it "does not capture a local when an argument has the same name" do
32
- var = 1
33
- @y.s(2) { |var| var }.should == 2
34
- var.should == 1
14
+ pending "allows for a leading space before the arguments" do
15
+ # res = @y.s (:a){ 1 }
16
+ # res.should == 1
35
17
  end
36
18
 
37
- describe "taking zero arguments" do
38
- before :each do
39
- @y = BlockSpecs::Yielder.new
19
+ pending "allows to define a block variable with the same name as the enclosing block" do
20
+ o = BlockSpecs::OverwriteBlockVariable.new
21
+ o.z { 1 }.should == 1
22
+ end
23
+
24
+ ruby_version_is ""..."1.9" do
25
+ it "overwrites a captured local when used as an argument" do
26
+ var = 1
27
+ @y.s(2) { |var| var }.should == 2
28
+ var.should == 2
40
29
  end
30
+ end
41
31
 
32
+ ruby_version_is "1.9" do
33
+ it "does not capture a local when an argument has the same name" do
34
+ var = 1
35
+ @y.s(2) { |var| var }.should == 2
36
+ var.should == 1
37
+ end
38
+ end
39
+
40
+ describe "taking zero arguments" do
42
41
  it "does not raise an exception when no values are yielded" do
43
42
  @y.z { 1 }.should == 1
44
43
  end
@@ -49,10 +48,6 @@ describe "A block" do
49
48
  end
50
49
 
51
50
  describe "taking || arguments" do
52
- before :each do
53
- @y = BlockSpecs::Yielder.new
54
- end
55
-
56
51
  it "does not raise an exception when no values are yielded" do
57
52
  @y.z { || 1 }.should == 1
58
53
  end
@@ -63,10 +58,6 @@ describe "A block" do
63
58
  end
64
59
 
65
60
  describe "taking |a| arguments" do
66
- before :each do
67
- @y = BlockSpecs::Yielder.new
68
- end
69
-
70
61
  it "assigns nil to the argument when no values are yielded" do
71
62
  @y.z { |a| a }.should be_nil
72
63
  end
@@ -75,21 +66,32 @@ describe "A block" do
75
66
  @y.s(1) { |a| a }.should == 1
76
67
  end
77
68
 
78
- it "assigns the first value yielded to the argument" do
79
- @y.m(1, 2) { |a| a }.should == 1
69
+ pending "does not call #to_ary to convert a single yielded object to an Array" do
70
+ obj = mock("block yield to_ary")
71
+ obj.should_not_receive(:to_ary)
72
+
73
+ @y.s(obj) { |a| a }.should equal(obj)
74
+ end
75
+
76
+ ruby_version_is ""..."1.9" do
77
+ it "assigns all the values yielded to the argument as an Array" do
78
+ @y.m(1, 2) { |a| a }.should == [1, 2]
79
+ end
80
+ end
81
+
82
+ ruby_version_is "1.9" do
83
+ it "assigns the first value yielded to the argument" do
84
+ @y.m(1, 2) { |a| a }.should == 1
85
+ end
80
86
  end
81
87
 
82
- it "does not deconstruct a single Array value" do
88
+ it "does not destructure a single Array value" do
83
89
  @y.s([1, 2]) { |a| a }.should == [1, 2]
84
90
  end
85
91
  end
86
92
 
87
93
  describe "taking |a, b| arguments" do
88
- before :each do
89
- @y = BlockSpecs::Yielder.new
90
- end
91
-
92
- it "assigns nil to the arguments when no values are yielded" do
94
+ it "assgins nil to the arguments when no values are yielded" do
93
95
  @y.z { |a, b| [a, b] }.should == [nil, nil]
94
96
  end
95
97
 
@@ -101,22 +103,437 @@ describe "A block" do
101
103
  @y.m(1, 2, 3) { |a, b| [a, b] }.should == [1, 2]
102
104
  end
103
105
 
104
- it "does not destructive an Array value as one of the several values yielded" do
106
+ it "does not destructure an Array value as one of several values yielded" do
105
107
  @y.m([1, 2], 3, 4) { |a, b| [a, b] }.should == [[1, 2], 3]
106
108
  end
107
- end
108
109
 
109
- describe "taking |a, *b| arguments" do
110
- before :each do
111
- @y = BlockSpecs::Yielder.new
110
+ pending "assigns 'nil' and 'nil' to the arguments when a single, empty Array is yielded" do
111
+ @y.s([]) { |a, b| [a, b] }.should == [nil, nil]
112
+ end
113
+
114
+ pending "assigns the element of a single element Array to the first argument" do
115
+ @y.s([1]) { |a, b| [a, b] }.should == [1, nil]
116
+ @y.s([nil]) { |a, b| [a, b] }.should == [nil, nil]
117
+ @y.s([[]]) { |a, b| [a, b] }.should == [[], nil]
118
+ end
119
+
120
+ pending "destructures a single Array value yielded" do
121
+ @y.s([1, 2, 3]) { |a, b| [a, b] }.should == [1, 2]
122
+ end
123
+
124
+ ruby_version_is ""..."1.9" do
125
+ it "does not destructure a splatted Array" do
126
+ @y.r([[]]) { |a, b| [a, b] }.should == [[], nil]
127
+ @y.r([[1]]) { |a, b| [a, b] }.should == [[1], nil]
128
+ end
129
+ end
130
+
131
+ ruby_version_is "1.9" do
132
+ pending "destructures a splatted Array" do
133
+ @y.r([[]]) { |a, b| [a, b] }.should == [nil, nil]
134
+ @y.r([[1]]) { |a, b| [a, b] }.should == [1, nil]
135
+ end
136
+ end
137
+
138
+ pending "calls #to_ary to convert a single yielded object to an Array" do
139
+ obj = mock("block yield to_ary")
140
+ obj.should_receive(:to_ary).and_return([1, 2])
141
+
142
+ @y.s(obj) { |a, b| [a, b] }.should == [1, 2]
112
143
  end
113
144
 
145
+ pending "does not call #to_ary if the single yielded object is an Array" do
146
+ obj = [1, 2]
147
+ obj.should_not_receive(:to_ary)
148
+
149
+ @y.s(obj) { |a, b| [a, b] }.should == [1, 2]
150
+ end
151
+
152
+ it "does not call #to_ary if the object does not respond to #to_ary" do
153
+ obj = mock("block yield no to_ary")
154
+
155
+ @y.s(obj) { |a, b| [a, b] }.should == [obj, nil]
156
+ end
157
+
158
+ pending "raises an TypeError if #to_ary does not return an Array" do
159
+ obj = mock("block yield to_ary invalid")
160
+ obj.should_receive(:to_ary).and_return(1)
161
+
162
+ lambda { @y.s(obj) { |a, b| } }.should raise_error(TypeError)
163
+ end
164
+ end
165
+
166
+ describe "taking |a, *b| arguments" do
114
167
  it "assigns 'nil' and '[]' to the arguments when no values are yielded" do
115
168
  @y.z { |a, *b| [a, b] }.should == [nil, []]
116
169
  end
117
170
 
118
- it "assigns all yielded values after the first to the rest arguments" do
171
+ it "assigns all yielded values after the first to the rest argument" do
119
172
  @y.m(1, 2, 3) { |a, *b| [a, b] }.should == [1, [2, 3]]
120
173
  end
174
+
175
+ pending "assigns 'nil' and '[]' to the arguments when a single, empty Array is yielded" do
176
+ @y.s([]) { |a, *b| [a, b] }.should == [nil, []]
177
+ end
178
+
179
+ pending "assigns the element of a single element Array to the first argument" do
180
+ @y.s([1]) { |a, *b| [a, b] }.should == [1, []]
181
+ @y.s([nil]) { |a, *b| [a, b] }.should == [nil, []]
182
+ @y.s([[]]) { |a, *b| [a, b] }.should == [[], []]
183
+ end
184
+
185
+ ruby_version_is ""..."1.9" do
186
+ it "does not destructure a splatted Array" do
187
+ @y.r([[]]) { |a, *b| [a, b] }.should == [[], []]
188
+ @y.r([[1]]) { |a, *b| [a, b] }.should == [[1], []]
189
+ end
190
+ end
191
+
192
+ ruby_version_is "1.9" do
193
+ pending "destructures a splatted Array" do
194
+ @y.r([[]]) { |a, *b| [a, b] }.should == [nil, []]
195
+ @y.r([[1]]) { |a, *b| [a, b] }.should == [1, []]
196
+ end
197
+ end
198
+
199
+ pending "destructures a single Array value assigning the remaining values to the rest argument" do
200
+ @y.s([1, 2, 3]) { |a, *b| [a, b] }.should == [1, [2, 3]]
201
+ end
202
+
203
+ pending "calls #to_ary to convert a single yielded object to an Array" do
204
+ obj = mock("block yield to_ary")
205
+ obj.should_receive(:to_ary).and_return([1, 2])
206
+
207
+ @y.s(obj) { |a, *b| [a, b] }.should == [1, [2]]
208
+ end
209
+
210
+ pending "does not call #to_ary if the single yielded object is an Array" do
211
+ obj = [1, 2]
212
+ obj.should_not_receive(:to_ary)
213
+
214
+ @y.s(obj) { |a, *b| [a, b] }.should == [1, [2]]
215
+ end
216
+
217
+ it "does not call #to_ary if the object does not respond to #to_ary" do
218
+ obj = mock("block yield no to_ary")
219
+
220
+ @y.s(obj) { |a, *b| [a, b] }.should == [obj, []]
221
+ end
222
+
223
+ pending "raises an TypeError if #to_ary does not return an Array" do
224
+ obj = mock("block yield to_ary invalid")
225
+ obj.should_receive(:to_ary).and_return(1)
226
+
227
+ lambda { @y.s(obj) { |a, *b| } }.should raise_error(TypeError)
228
+ end
229
+ end
230
+
231
+ describe "taking |*| arguments" do
232
+ pending "does not raise an exception when no values are yielded" do
233
+ # @y.z { |*| 1 }.should == 1
234
+ end
235
+
236
+ pending "does not raise an exception when values are yielded" do
237
+ # @y.s(0) { |*| 1 }.should == 1
238
+ end
239
+
240
+ pending "does not call #to_ary if the single yielded object is an Array" do
241
+ obj = [1, 2]
242
+ obj.should_not_receive(:to_ary)
243
+
244
+ # @y.s(obj) { |*| 1 }.should == 1
245
+ end
246
+
247
+ pending "does not call #to_ary if the object does not respond to #to_ary" do
248
+ obj = mock("block yield no to_ary")
249
+
250
+ # @y.s(obj) { |*| 1 }.should == 1
251
+ end
252
+
253
+ ruby_version_is ""..."1.9" do
254
+ it "calls #to_ary to convert a single yielded object to an Array" do
255
+ obj = mock("block yield to_ary")
256
+ obj.should_receive(:to_ary).and_return([1, 2])
257
+
258
+ # @y.s(obj) { |*| 1 }.should == 1
259
+ end
260
+
261
+ pending "does not raise a TypeError if #to_ary returns nil" do
262
+ obj = mock("block yield to_ary nil")
263
+ obj.should_receive(:to_ary).and_return(nil)
264
+
265
+ # @y.s(obj) { |*o| o }.should == [obj]
266
+ end
267
+
268
+ pending "raises an TypeError if #to_ary does not return an Array" do
269
+ obj = mock("block yield to_ary invalid")
270
+ obj.should_receive(:to_ary).and_return(1)
271
+
272
+ # lambda { @y.s(obj) { |*| } }.should raise_error(TypeError)
273
+ end
274
+ end
275
+
276
+ ruby_version_is "1.9" do
277
+ pending "does not call #to_ary to convert a single yielded object to an Array" do
278
+ obj = mock("block yield to_ary")
279
+ obj.should_not_receive(:to_ary)
280
+
281
+ # @y.s(obj) { |*| 1 }.should == 1
282
+ end
283
+ end
284
+ end
285
+
286
+ describe "taking |*a| arguments" do
287
+ it "assigns '[]' to the argument when no values are yielded" do
288
+ @y.z { |*a| a }.should == []
289
+ end
290
+
291
+ it "assigns a single value yielded to the argument as an Array" do
292
+ @y.s(1) { |*a| a }.should == [1]
293
+ end
294
+
295
+ it "assigns all the values passed to the argument as an Array" do
296
+ @y.m(1, 2, 3) { |*a| a }.should == [1, 2, 3]
297
+ end
298
+
299
+ it "assigns '[[]]' to the argument when passed an empty Array" do
300
+ @y.s([]) { |*a| a }.should == [[]]
301
+ end
302
+
303
+ it "assigns a single Array value passed to the argument by wrapping it in an Array" do
304
+ @y.s([1, 2, 3]) { |*a| a }.should == [[1, 2, 3]]
305
+ end
306
+
307
+ pending "does not call #to_ary if the single yielded object is an Array" do
308
+ obj = [1, 2]
309
+ obj.should_not_receive(:to_ary)
310
+
311
+ @y.s(obj) { |*a| a }.should == [[1, 2]]
312
+ end
313
+
314
+ it "does not call #to_ary if the object does not respond to #to_ary" do
315
+ obj = mock("block yield no to_ary")
316
+
317
+ @y.s(obj) { |*a| a }.should == [obj]
318
+ end
319
+
320
+ ruby_version_is ""..."1.9" do
321
+ it "calls #to_ary to convert a single yielded object to an Array" do
322
+ obj = mock("block yield to_ary")
323
+ obj.should_receive(:to_ary).and_return([1, 2])
324
+
325
+ @y.s(obj) { |*a| a }.should == [obj]
326
+ end
327
+
328
+ it "raises an TypeError if #to_ary does not return an Array" do
329
+ obj = mock("block yield to_ary invalid")
330
+ obj.should_receive(:to_ary).and_return(1)
331
+
332
+ lambda { @y.s(obj) { |*a| } }.should raise_error(TypeError)
333
+ end
334
+ end
335
+
336
+ ruby_version_is "1.9" do
337
+ pending "does not call #to_ary to convert a single yielded object to an Array" do
338
+ obj = mock("block yield to_ary")
339
+ obj.should_not_receive(:to_ary)
340
+
341
+ @y.s(obj) { |*a| a }.should == [obj]
342
+ end
343
+ end
344
+ end
345
+
346
+ describe "taking |a, | arguments" do
347
+ pending "assigns nil to the argument when no values are yielded" do
348
+ # @y.z { |a, | a }.should be_nil
349
+ end
350
+
351
+ pending "assgins the argument a single value yielded" do
352
+ # @y.s(1) { |a, | a }.should == 1
353
+ end
354
+
355
+ pending "assigns the argument the first value yielded" do
356
+ # @y.m(1, 2) { |a, | a }.should == 1
357
+ end
358
+
359
+ pending "assigns the argument the first of several values yielded when it is an Array" do
360
+ # @y.m([1, 2], 3) { |a, | a }.should == [1, 2]
361
+ end
362
+
363
+ pending "assigns nil to the argument when passed an empty Array" do
364
+ # @y.s([]) { |a, | a }.should be_nil
365
+ end
366
+
367
+ pending "assigns the argument the first element of the Array when passed a single Array" do
368
+ # @y.s([1, 2]) { |a, | a }.should == 1
369
+ end
370
+
371
+ pending "calls #to_ary to convert a single yielded object to an Array" do
372
+ # obj = mock("block yield to_ary")
373
+ # obj.should_receive(:to_ary).and_return([1, 2])
374
+
375
+ # @y.s(obj) { |a, | a }.should == 1
376
+ end
377
+
378
+ pending "does not call #to_ary if the single yielded object is an Array" do
379
+ # obj = [1, 2]
380
+ # obj.should_not_receive(:to_ary)
381
+
382
+ # @y.s(obj) { |a, | a }.should == 1
383
+ end
384
+
385
+ pending "does not call #to_ary if the object does not respond to #to_ary" do
386
+ # obj = mock("block yield no to_ary")
387
+
388
+ # @y.s(obj) { |a, | a }.should == obj
389
+ end
390
+
391
+ pending "raises an TypeError if #to_ary does not return an Array" do
392
+ # obj = mock("block yield to_ary invalid")
393
+ # obj.should_receive(:to_ary).and_return(1)
394
+
395
+ # lambda { @y.s(obj) { |a, | } }.should raise_error(TypeError)
396
+ end
397
+ end
398
+
399
+ describe "taking |(a, b)| arguments" do
400
+ pending "assigns nil to the arguments when yielded no values" do
401
+ # @y.z { |(a, b)| [a, b] }.should == [nil, nil]
402
+ end
403
+
404
+ pending "destructures a single Array value yielded" do
405
+ # @y.s([1, 2]) { |(a, b)| [a, b] }.should == [1, 2]
406
+ end
407
+
408
+ pending "calls #to_ary to convert a single yielded object to an Array" do
409
+ obj = mock("block yield to_ary")
410
+ obj.should_receive(:to_ary).and_return([1, 2])
411
+
412
+ # @y.s(obj) { |(a, b)| [a, b] }.should == [1, 2]
413
+ end
414
+
415
+ pending "does not call #to_ary if the single yielded object is an Array" do
416
+ obj = [1, 2]
417
+ obj.should_not_receive(:to_ary)
418
+
419
+ # @y.s(obj) { |(a, b)| [a, b] }.should == [1, 2]
420
+ end
421
+
422
+ pending "does not call #to_ary if the object does not respond to #to_ary" do
423
+ obj = mock("block yield no to_ary")
424
+
425
+ # @y.s(obj) { |(a, b)| [a, b] }.should == [obj, nil]
426
+ end
427
+
428
+ pending "raises an TypeError if #to_ary does not return an Array" do
429
+ obj = mock("block yield to_ary invalid")
430
+ obj.should_receive(:to_ary).and_return(1)
431
+
432
+ # lambda { @y.s(obj) { |(a, b)| } }.should raise_error(TypeError)
433
+ end
121
434
  end
122
- end
435
+
436
+ describe "taking |(a, b), c| arguments" do
437
+ pending "assigns nil to the arguments when yielded no values" do
438
+ # @y.z { |(a, b), c| [a, b, c] }.should == [nil, nil, nil]
439
+ end
440
+
441
+ pending "destructures a single one-level Array value yielded" do
442
+ # @y.s([1, 2]) { |(a, b), c| [a, b, c] }.should == [1, nil, 2]
443
+ end
444
+
445
+ pending "destructures a single multi-level Array value yielded" do
446
+ # @y.s([[1, 2, 3], 4]) { |(a, b), c| [a, b, c] }.should == [1, 2, 4]
447
+ end
448
+
449
+ pending "calls #to_ary to convert a single yielded object to an Array" do
450
+ obj = mock("block yield to_ary")
451
+ obj.should_receive(:to_ary).and_return([1, 2])
452
+
453
+ # @y.s(obj) { |(a, b), c| [a, b, c] }.should == [1, nil, 2]
454
+ end
455
+
456
+ pending "does not call #to_ary if the single yielded object is an Array" do
457
+ obj = [1, 2]
458
+ obj.should_not_receive(:to_ary)
459
+
460
+ # @y.s(obj) { |(a, b), c| [a, b, c] }.should == [1, nil, 2]
461
+ end
462
+
463
+ pending "does not call #to_ary if the object does not respond to #to_ary" do
464
+ obj = mock("block yield no to_ary")
465
+
466
+ # @y.s(obj) { |(a, b), c| [a, b, c] }.should == [obj, nil, nil]
467
+ end
468
+
469
+ pending "raises an TypeError if #to_ary does not return an Array" do
470
+ obj = mock("block yield to_ary invalid")
471
+ obj.should_receive(:to_ary).and_return(1)
472
+
473
+ # lambda { @y.s(obj) { |(a, b), c| } }.should raise_error(TypeError)
474
+ end
475
+ end
476
+
477
+ describe "taking nested |a, (b, (c, d))|" do
478
+ pending "assigns nil to the arguments when yielded no values" do
479
+ # @y.m { |a, (b, (c, d))| [a, b, c, d] }.should == [nil, nil, nil, nil]
480
+ end
481
+
482
+ pending "destructures separate yielded values" do
483
+ # @y.m(1, 2) { |a, (b, (c, d))| [a, b, c, d] }.should == [1, 2, nil, nil]
484
+ end
485
+
486
+ pending "destructures a single multi-level Array value yielded" do
487
+ # @y.m(1, [2, 3]) { |a, (b, (c, d))| [a, b, c, d] }.should == [1, 2, 3, nil]
488
+ end
489
+
490
+ pending "destructures a single multi-level Array value yielded" do
491
+ # @y.m(1, [2, [3, 4]]) { |a, (b, (c, d))| [a, b, c, d] }.should == [1, 2, 3, 4]
492
+ end
493
+ end
494
+
495
+ describe "taking nested |a, ((b, c), d)|" do
496
+ pending "assigns nil to the arguments when yielded no values" do
497
+ # @y.m { |a, ((b, c), d)| [a, b, c, d] }.should == [nil, nil, nil, nil]
498
+ end
499
+
500
+ pending "destructures separate yielded values" do
501
+ # @y.m(1, 2) { |a, ((b, c), d)| [a, b, c, d] }.should == [1, 2, nil, nil]
502
+ end
503
+
504
+ pending "destructures a single multi-level Array value yielded" do
505
+ # @y.m(1, [2, 3]) { |a, ((b, c), d)| [a, b, c, d] }.should == [1, 2, nil, 3]
506
+ end
507
+
508
+ pending "destructures a single multi-level Array value yielded" do
509
+ # @y.m(1, [[2, 3], 4]) { |a, ((b, c), d)| [a, b, c, d] }.should == [1, 2, 3, 4]
510
+ end
511
+ end
512
+
513
+ describe "arguments with _" do
514
+
515
+ ruby_version_is ""..."1.9" do
516
+ it "extracts arguments with _" do
517
+ # @y.m([[1, 2, 3], 4]) { |(_, a, _), _| a }.should == 4
518
+ end
519
+
520
+ it "assigns the last variable named" do
521
+ # @y.m(1, 2) { |_, _| _ }.should == 2
522
+ end
523
+ end
524
+
525
+ ruby_version_is "1.9" do
526
+ pending "extracts arguments with _" do
527
+ # @y.m([[1, 2, 3], 4]) { |(_, a, _), _| a }.should == 2
528
+ end
529
+
530
+ pending "assigns the first variable named" do
531
+ # @y.m(1, 2) { |_, _| _ }.should == 1
532
+ end
533
+ end
534
+
535
+ end
536
+
537
+ end
538
+
539
+ # language_version __FILE__, "block"