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
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+
4
+ # Array#nitems was removed from Ruby 1.9.
5
+ ruby_version_is '' ... '1.9' do
6
+ describe "Array#nitems" do
7
+ it "returns the number of non-nil elements" do
8
+ [nil].nitems.should == 0
9
+ [].nitems.should == 0
10
+ [1, 2, 3, nil].nitems.should == 3
11
+ [1, 2, 3].nitems.should == 3
12
+ [1, nil, 2, 3, nil, nil, 4].nitems.should == 4
13
+ [1, nil, 2, false, 3, nil, nil, 4].nitems.should == 5
14
+ end
15
+
16
+ it "properly handles recursive arrays" do
17
+ empty = ArraySpecs.empty_recursive_array
18
+ empty.nitems.should == 1
19
+
20
+ array = ArraySpecs.recursive_array
21
+ array.nitems.should == 8
22
+
23
+ [nil, empty, array].nitems.should == 2
24
+ end
25
+ end
26
+ end
@@ -1,6 +1,9 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+
1
4
  describe "Array#+" do
2
5
  it "concatenates two arrays" do
3
- ([ 1, 2, 3 ] + [ 3, 4, 5 ] ).should == [1, 2, 3, 3, 4, 5]
6
+ ([ 1, 2, 3 ] + [ 3, 4, 5 ]).should == [1, 2, 3, 3, 4, 5]
4
7
  ([ 1, 2, 3 ] + []).should == [1, 2, 3]
5
8
  ([] + [ 1, 2, 3 ]).should == [1, 2, 3]
6
9
  ([] + []).should == []
@@ -10,4 +13,47 @@ describe "Array#+" do
10
13
  ary = [1, 2, 3]
11
14
  (ary + ary).should == [1, 2, 3, 1, 2, 3]
12
15
  end
13
- end
16
+
17
+ pending "tries to convert the passed argument to an Array using #to_ary" do
18
+ obj = mock('["x", "y"]')
19
+ obj.should_receive(:to_ary).and_return(["x", "y"])
20
+ ([1, 2, 3] + obj).should == [1, 2, 3, "x", "y"]
21
+ end
22
+
23
+ pending "properly handles recursive arrays" do
24
+ empty = ArraySpecs.empty_recursive_array
25
+ (empty + empty).should == [empty, empty]
26
+
27
+ array = ArraySpecs.recursive_array
28
+ (empty + array).should == [empty, 1, 'two', 3.0, array, array, array, array, array]
29
+ (array + array).should == [
30
+ 1, 'two', 3.0, array, array, array, array, array,
31
+ 1, 'two', 3.0, array, array, array, array, array]
32
+ end
33
+
34
+ it "does return subclass instances with Array subclasses" do
35
+ (ArraySpecs::MyArray[1, 2, 3] + []).should be_kind_of(Array)
36
+ (ArraySpecs::MyArray[1, 2, 3] + ArraySpecs::MyArray[]).should be_kind_of(Array)
37
+ ([1, 2, 3] + ArraySpecs::MyArray[]).should be_kind_of(Array)
38
+ end
39
+
40
+ it "does not call to_ary on array subclasses" do
41
+ ([5, 6] + ArraySpecs::ToAryArray[1, 2]).should == [5, 6, 1, 2]
42
+ end
43
+
44
+ pending "does not get infected even if an original array is tainted" do
45
+ ([1, 2] + [3, 4]).tainted?.should be_false
46
+ ([1, 2].taint + [3, 4]).tainted?.should be_false
47
+ ([1, 2] + [3, 4].taint).tainted?.should be_false
48
+ ([1, 2].taint + [3, 4].taint).tainted?.should be_false
49
+ end
50
+
51
+ ruby_version_is '1.9' do
52
+ pending "does not infected even if an original array is untrusted" do
53
+ ([1, 2] + [3, 4]).untrusted?.should be_false
54
+ ([1, 2].untrust + [3, 4]).untrusted?.should be_false
55
+ ([1, 2] + [3, 4].untrust).untrusted?.should be_false
56
+ ([1, 2].untrust + [3, 4].untrust).untrusted?.should be_false
57
+ end
58
+ end
59
+ end
@@ -1,3 +1,6 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+
1
4
  describe "Array#pop" do
2
5
  it "removes and returns the last element of the array" do
3
6
  a = ["a", 1, nil, true]
@@ -19,58 +22,175 @@ describe "Array#pop" do
19
22
  [].pop.should == nil
20
23
  end
21
24
 
22
- describe "passed a number n as an argument" do
23
- it "removes and returns an array with the last n elements of the array" do
24
- a = [1, 2, 3, 4, 5, 6]
25
-
26
- a.pop(0).should == []
27
- a.should == [1, 2, 3, 4, 5, 6]
25
+ pending "properly handles recursive arrays" do
26
+ empty = ArraySpecs.empty_recursive_array
27
+ empty.pop.should == []
28
28
 
29
- a.pop(1).should == [6]
30
- a.should == [1, 2, 3, 4, 5]
29
+ array = ArraySpecs.recursive_array
30
+ array.pop.should == [1, 'two', 3.0, array, array, array, array]
31
+ end
31
32
 
32
- a.pop(2).should == [4, 5]
33
- a.should == [1, 2, 3]
33
+ pending "keeps taint status" do
34
+ a = [1, 2].taint
35
+ a.pop
36
+ a.tainted?.should be_true
37
+ a.pop
38
+ a.tainted?.should be_true
39
+ end
34
40
 
35
- a.pop(3).should == [1, 2, 3]
36
- a.should == []
41
+ ruby_version_is '' ... '1.9' do
42
+ it "raises a TypeError on a frozen array" do
43
+ lambda { ArraySpecs.frozen_array.pop }.should raise_error(TypeError)
37
44
  end
38
-
39
- it "returns an array wih the last n elements even if shift was invoked" do
40
- a = [1, 2, 3, 4]
41
- a.shift
42
- a.pop(3).should == [2, 3, 4]
45
+ it "raises a TypeError on an empty frozen array" do
46
+ lambda { ArraySpecs.empty_frozen_array.pop }.should raise_error(TypeError)
43
47
  end
48
+ end
44
49
 
45
- it "returns a new empty array if there are no more elmeents" do
46
- a = []
47
- popped1 = a.pop(1)
48
- popped1.should == []
49
- a.should == []
50
-
51
- popped2 = a.pop(2)
52
- popped2.should == []
53
- a.should == []
50
+ ruby_version_is '1.9' do
51
+ it "raises a RuntimeError on a frozen array" do
52
+ lambda { ArraySpecs.frozen_array.pop }.should raise_error(RuntimeError)
53
+ end
54
54
 
55
- popped1.should_not equal(popped2)
55
+ it "raises a RuntimeError on an empty frozen array" do
56
+ lambda { ArraySpecs.empty_frozen_array.pop }.should raise_error(RuntimeError)
56
57
  end
57
58
 
58
- it "returns whole elements if n exceeds size of the array" do
59
- a = [1, 2, 3, 4, 5]
60
- a.pop(6).should == [1, 2, 3, 4, 5]
61
- a.should == []
59
+ pending "keeps untrusted status" do
60
+ a = [1, 2].untrust
61
+ a.pop
62
+ a.untrusted?.should be_true
63
+ a.pop
64
+ a.untrusted?.should be_true
62
65
  end
66
+ end
63
67
 
64
- it "does not return self even when it returns whole elements" do
65
- a = [1, 2, 3, 4, 5]
66
- a.pop(5).should_not equal(a)
68
+ ruby_version_is '' ... '1.8.7' do
69
+ it "raises an ArgumentError if passed an argument" do
70
+ lambda{ [1, 2].pop(1) }.should raise_error(ArgumentError)
71
+ end
72
+ end
67
73
 
68
- a = [1, 2, 3, 4, 5]
69
- a.pop(6).should_not equal(a)
74
+ describe "passed a number n as an argument" do
75
+ ruby_version_is '1.8.7' do
76
+ it "removes and returns an array with the last n elements of the array" do
77
+ a = [1, 2, 3, 4, 5, 6]
78
+
79
+ a.pop(0).should == []
80
+ a.should == [1, 2, 3, 4, 5, 6]
81
+
82
+ a.pop(1).should == [6]
83
+ a.should == [1, 2, 3, 4, 5]
84
+
85
+ a.pop(2).should == [4, 5]
86
+ a.should == [1, 2, 3]
87
+
88
+ a.pop(3).should == [1, 2, 3]
89
+ a.should == []
90
+ end
91
+
92
+ it "returns an array with the last n elements even if shift was invoked" do
93
+ a = [1, 2, 3, 4]
94
+ a.shift
95
+ a.pop(3).should == [2, 3, 4]
96
+ end
97
+
98
+ it "returns a new empty array if there are no more elements" do
99
+ a = []
100
+ popped1 = a.pop(1)
101
+ popped1.should == []
102
+ a.should == []
103
+
104
+ popped2 = a.pop(2)
105
+ popped2.should == []
106
+ a.should == []
107
+
108
+ popped1.should_not equal(popped2)
109
+ end
110
+
111
+ it "returns whole elements if n exceeds size of the array" do
112
+ a = [1, 2, 3, 4, 5]
113
+ a.pop(6).should == [1, 2, 3, 4, 5]
114
+ a.should == []
115
+ end
116
+
117
+ it "does not return self even when it returns whole elements" do
118
+ a = [1, 2, 3, 4, 5]
119
+ a.pop(5).should_not equal(a)
120
+
121
+ a = [1, 2, 3, 4, 5]
122
+ a.pop(6).should_not equal(a)
123
+ end
124
+
125
+ it "raises an ArgumentError if n is negative" do
126
+ lambda{ [1, 2, 3].pop(-1) }.should raise_error(ArgumentError)
127
+ end
128
+
129
+ it "tries to convert n to an Integer using #to_int" do
130
+ a = [1, 2, 3, 4]
131
+ a.pop(2.3).should == [3, 4]
132
+
133
+ obj = mock('to_int')
134
+ obj.should_receive(:to_int).and_return(2)
135
+ a.should == [1, 2]
136
+ a.pop(obj).should == [1, 2]
137
+ a.should == []
138
+ end
139
+
140
+ it "raises a TypeError when the passed n can be coerced to Integer" do
141
+ lambda{ [1, 2].pop("cat") }.should raise_error(TypeError)
142
+ lambda{ [1, 2].pop(nil) }.should raise_error(TypeError)
143
+ end
144
+
145
+ it "raises an ArgumentError if more arguments are passed" do
146
+ lambda{ [1, 2].pop(1, 2) }.should raise_error(ArgumentError)
147
+ end
148
+
149
+ it "does not return subclass instances with Array subclass" do
150
+ ArraySpecs::MyArray[1, 2, 3].pop(2).should be_kind_of(Array)
151
+ end
152
+
153
+ it "returns an untainted array even if the array is tainted" do
154
+ ary = [1, 2].taint
155
+ ary.pop(2).tainted?.should be_false
156
+ ary.pop(0).tainted?.should be_false
157
+ end
158
+
159
+ it "keeps taint status" do
160
+ a = [1, 2].taint
161
+ a.pop(2)
162
+ a.tainted?.should be_true
163
+ a.pop(2)
164
+ a.tainted?.should be_true
165
+ end
166
+
167
+ ruby_version_is '' ... '1.9' do
168
+ it "raises a TypeError on a frozen array" do
169
+ lambda { ArraySpecs.frozen_array.pop(2) }.should raise_error(TypeError)
170
+ lambda { ArraySpecs.frozen_array.pop(0) }.should raise_error(TypeError)
171
+ end
172
+ end
70
173
  end
71
174
 
72
- it "raises an ArgumentError if n is negative" do
73
- lambda { [1, 2, 3].pop(-1) }.should raise_error(ArgumentError)
175
+ ruby_version_is '1.9' do
176
+ pending "returns a trusted array even if the array is untrusted" do
177
+ ary = [1, 2].untrust
178
+ ary.pop(2).untrusted?.should be_false
179
+ ary.pop(0).untrusted?.should be_false
180
+ end
181
+
182
+ it "raises a RuntimeError on a frozen array" do
183
+ lambda { ArraySpecs.frozen_array.pop(2) }.should raise_error(RuntimeError)
184
+ lambda { ArraySpecs.frozen_array.pop(0) }.should raise_error(RuntimeError)
185
+ end
186
+
187
+ pending "keeps untrusted status" do
188
+ a = [1, 2].untrust
189
+ a.pop(2)
190
+ a.untrusted?.should be_true
191
+ a.pop(2)
192
+ a.untrusted?.should be_true
193
+ end
74
194
  end
75
195
  end
76
- end
196
+ end
@@ -1,3 +1,6 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+
1
4
  describe "Array#push" do
2
5
  it "appends the arguments to the array" do
3
6
  a = [ "a", "b", "c" ]
@@ -13,4 +16,29 @@ describe "Array#push" do
13
16
  a.push("foo")
14
17
  a.should == ["b", "c", "foo"]
15
18
  end
16
- end
19
+
20
+ pending "properly handles recursive arrays" do
21
+ empty = ArraySpecs.empty_recursive_array
22
+ empty.push(:last).should == [empty, :last]
23
+
24
+ array = ArraySpecs.recursive_array
25
+ array.push(:last).should == [1, 'two', 3.0, array, array, array, array, array, :last]
26
+ end
27
+
28
+ ruby_version_is "" ... "1.9" do
29
+ it "raises a TypeError on a frozen array if modification takes place" do
30
+ lambda { ArraySpecs.frozen_array.push(1) }.should raise_error(TypeError)
31
+ end
32
+
33
+ it "does not raise on a frozen array if no modification is made" do
34
+ ArraySpecs.frozen_array.push.should == [1, 2, 3]
35
+ end
36
+ end
37
+
38
+ ruby_version_is "1.9" do
39
+ it "raises a RuntimeError on a frozen array" do
40
+ lambda { ArraySpecs.frozen_array.push(1) }.should raise_error(RuntimeError)
41
+ lambda { ArraySpecs.frozen_array.push }.should raise_error(RuntimeError)
42
+ end
43
+ end
44
+ end
@@ -1,9 +1,38 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+
1
4
  describe "Array#rassoc" do
2
- it "returns the first contained array whose second element it == object" do
5
+ it "returns the first contained array whose second element is == object" do
3
6
  ary = [[1, "a", 0.5], [2, "b"], [3, "b"], [4, "c"], [], [5], [6, "d"]]
4
7
  ary.rassoc("a").should == [1, "a", 0.5]
5
8
  ary.rassoc("b").should == [2, "b"]
6
9
  ary.rassoc("d").should == [6, "d"]
7
10
  ary.rassoc("z").should == nil
8
11
  end
9
- end
12
+
13
+ pending "properly handles recursive arrays" do
14
+ empty = ArraySpecs.empty_recursive_array
15
+ empty.rassoc([]).should be_nil
16
+ [[empty, empty]].rassoc(empty).should == [empty, empty]
17
+
18
+ array = ArraySpecs.recursive_array
19
+ array.rassoc(array).should be_nil
20
+ [[empty, array]].rassoc(array).should == [empty, array]
21
+ end
22
+
23
+ pending "calls elem == obj on the second element of each contained array" do
24
+ key = 'foobar'
25
+ o = mock('foobar')
26
+ def o.==(other); other == 'foobar'; end
27
+
28
+ [[1, :foobar], [2, o], [3, mock('foo')]].rassoc(key).should == [2, o]
29
+ end
30
+
31
+ pending "does not check the last element in each contained but speficically the second" do
32
+ key = 'foobar'
33
+ o = mock('foobar')
34
+ def o.==(other); other == 'foobar'; end
35
+
36
+ [[1, :foobar, o], [2, o, 1], [3, mock('foo')]].rassoc(key).should == [2, o, 1]
37
+ end
38
+ end
@@ -1,3 +1,7 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+ require File.expand_path('../shared/enumeratorize', __FILE__)
4
+
1
5
  describe "Array#reject" do
2
6
  it "returns a new array without elements for which block is true" do
3
7
  ary = [1, 2, 3, 4, 5]
@@ -6,6 +10,7 @@ describe "Array#reject" do
6
10
  ary.reject { false }.object_id.should_not == ary.object_id
7
11
  ary.reject { nil }.should == ary
8
12
  ary.reject { nil }.object_id.should_not == ary.object_id
13
+ ary.reject { 5 }.should == []
9
14
  ary.reject { |i| i < 3 }.should == [3, 4, 5]
10
15
  ary.reject { |i| i % 2 == 0 }.should == [1, 3, 5]
11
16
  end
@@ -15,6 +20,46 @@ describe "Array#reject" do
15
20
  array.shift
16
21
  array.reject { |x| true }.should == []
17
22
  end
23
+
24
+ pending "properly handles recursive arrays" do
25
+ empty = ArraySpecs.empty_recursive_array
26
+ empty.reject { false }.should == [empty]
27
+ empty.reject { true }.should == []
28
+
29
+ array = ArraySpecs.recursive_array
30
+ array.reject { false }.should == [1, 'two', 3.0, array, array, array, array, array]
31
+ array.reject { true }.should == []
32
+ end
33
+
34
+ ruby_version_is "" ... "1.9.3" do
35
+ not_compliant_on :ironruby do
36
+ it "returns subclass instance on Array subclasses" do
37
+ ArraySpecs::MyArray[1, 2, 3].reject { |x| x % 2 == 0 }.should be_kind_of(ArraySpecs::MyArray)
38
+ end
39
+ end if false
40
+
41
+ deviates_on :ironruby do
42
+ it "does not return subclass instance on Array subclasses" do
43
+ ArraySpecs::MyArray[1, 2, 3].reject { |x| x % 2 == 0 }.should be_kind_of(Array)
44
+ end
45
+ end if false
46
+ end
47
+
48
+ ruby_version_is "1.9.3" do
49
+ it "does not return subclass instance on Array subclasses" do
50
+ ArraySpecs::MyArray[1, 2, 3].reject { |x| x % 2 == 0 }.should be_kind_of(Array)
51
+ end
52
+
53
+ it "does not retain instance variables" do
54
+ array = []
55
+ array.instance_variable_set("@variable", "value")
56
+ array.reject { false }.instance_variable_get("@variable").should == nil
57
+ end
58
+ end
59
+
60
+ pending do
61
+ it_behaves_like :enumeratorize, :reject
62
+ end
18
63
  end
19
64
 
20
65
  describe "Array#reject!" do
@@ -34,7 +79,27 @@ describe "Array#reject!" do
34
79
  a.should == []
35
80
  end
36
81
 
37
- it "returns nil when called on an array emptied with #shift" do
82
+ pending "properly handles recursive arrays" do
83
+ empty = ArraySpecs.empty_recursive_array
84
+ empty_dup = empty.dup
85
+ empty.reject! { false }.should == nil
86
+ empty.should == empty_dup
87
+
88
+ empty = ArraySpecs.empty_recursive_array
89
+ empty.reject! { true }.should == []
90
+ empty.should == []
91
+
92
+ array = ArraySpecs.recursive_array
93
+ array_dup = array.dup
94
+ array.reject! { false }.should == nil
95
+ array.should == array_dup
96
+
97
+ array = ArraySpecs.recursive_array
98
+ array.reject! { true }.should == []
99
+ array.should == []
100
+ end
101
+
102
+ it "returns nil when called on an Array emptied with #shift" do
38
103
  array = [1]
39
104
  array.shift
40
105
  array.reject! { |x| true }.should == nil
@@ -48,4 +113,26 @@ describe "Array#reject!" do
48
113
  a.reject! { true }
49
114
  a.reject! { true }.should == nil
50
115
  end
51
- end
116
+
117
+ ruby_version_is "" ... "1.9" do
118
+ it "raises a TypeError on a frozen array" do
119
+ lambda { ArraySpecs.frozen_array.reject! {} }.should raise_error(TypeError)
120
+ end
121
+ it "raises a TypeError on an empty frozen array" do
122
+ lambda { ArraySpecs.empty_frozen_array.reject! {} }.should raise_error(TypeError)
123
+ end
124
+ end
125
+
126
+ ruby_version_is "1.9" do
127
+ it "raises a RuntimeError on a frozen array" do
128
+ lambda { ArraySpecs.frozen_array.reject! {} }.should raise_error(RuntimeError)
129
+ end
130
+ it "raises a RuntimeError on an empty frozen array" do
131
+ lambda { ArraySpecs.empty_frozen_array.reject! {} }.should raise_error(RuntimeError)
132
+ end
133
+ end
134
+
135
+ pending do
136
+ it_behaves_like :enumeratorize, :reject!
137
+ end
138
+ end