opal 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +3 -0
- data/.travis.yml +0 -4
- data/README.md +6 -0
- data/Rakefile +30 -6
- data/bin/opal +6 -82
- data/corelib/{opal/array.rb → array.rb} +40 -56
- data/corelib/{opal/basic_object.rb → basic_object.rb} +2 -2
- data/corelib/{opal/boolean.rb → boolean.rb} +0 -8
- data/corelib/class.rb +47 -0
- data/corelib/{opal/comparable.rb → comparable.rb} +0 -0
- data/corelib/{opal/enumerable.rb → enumerable.rb} +208 -141
- data/corelib/{opal/enumerator.rb → enumerator.rb} +3 -3
- data/corelib/{opal/error.rb → error.rb} +1 -0
- data/corelib/{opal/hash.rb → hash.rb} +67 -56
- data/corelib/io.rb +39 -0
- data/corelib/{opal/kernel.rb → kernel.rb} +35 -31
- data/corelib/{opal/class.rb → module.rb} +29 -57
- data/corelib/native.rb +148 -0
- data/corelib/{opal/nil_class.rb → nil_class.rb} +2 -10
- data/corelib/{opal/numeric.rb → numeric.rb} +39 -14
- data/corelib/opal.rb +42 -25
- data/corelib/{opal/proc.rb → proc.rb} +3 -3
- data/corelib/{opal/range.rb → range.rb} +5 -1
- data/corelib/{opal/regexp.rb → regexp.rb} +0 -0
- data/corelib/{opal/runtime.js → runtime.js} +96 -188
- data/corelib/{opal/string.rb → string.rb} +20 -15
- data/corelib/struct.rb +139 -0
- data/corelib/{opal/time.rb → time.rb} +0 -0
- data/lib/opal.rb +4 -0
- data/lib/opal/cli.rb +79 -32
- data/lib/opal/cli_options.rb +91 -0
- data/lib/opal/erb.rb +41 -8
- data/lib/opal/grammar.rb +24 -10
- data/lib/opal/grammar.y +15 -4
- data/lib/opal/grammar_helpers.rb +4 -0
- data/lib/opal/lexer.rb +214 -143
- data/lib/opal/parser.rb +596 -562
- data/lib/opal/require_parser.rb +1 -1
- data/lib/opal/source_map.rb +15 -30
- data/lib/opal/target_scope.rb +24 -5
- data/lib/opal/version.rb +1 -1
- data/mri_spec/cli_spec.rb +18 -0
- data/mri_spec/fixtures/opal_file.rb +2 -0
- data/mri_spec/spec_helper.rb +17 -0
- data/opal.gemspec +5 -2
- data/spec/{rubyspec/filters → filters}/bugs/alias.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/ancestors.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array.rb +0 -0
- data/spec/filters/bugs/array/combination.rb +11 -0
- data/spec/filters/bugs/array/count.rb +3 -0
- data/spec/filters/bugs/array/delete_if.rb +3 -0
- data/spec/filters/bugs/array/drop.rb +3 -0
- data/spec/filters/bugs/array/drop_while.rb +5 -0
- data/spec/filters/bugs/array/eql.rb +3 -0
- data/spec/filters/bugs/array/flatten.rb +9 -0
- data/spec/filters/bugs/array/minus.rb +5 -0
- data/spec/filters/bugs/array/multipliy.rb +9 -0
- data/spec/filters/bugs/array/new.rb +3 -0
- data/spec/filters/bugs/array/pop.rb +6 -0
- data/spec/filters/bugs/array/rassoc.rb +4 -0
- data/spec/filters/bugs/array/rindex.rb +6 -0
- data/spec/filters/bugs/array/select.rb +3 -0
- data/spec/filters/bugs/array/shift.rb +7 -0
- data/spec/filters/bugs/array/shuffle.rb +11 -0
- data/spec/filters/bugs/array/slice.rb +7 -0
- data/spec/filters/bugs/array/take.rb +3 -0
- data/spec/filters/bugs/array/to_a.rb +3 -0
- data/spec/filters/bugs/array/try_convert.rb +7 -0
- data/spec/filters/bugs/array/uniq.rb +10 -0
- data/spec/filters/bugs/array/zip.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_delete.rb +1 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_fetch.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_first.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_flatten.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_intersection.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_join.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/break.rb +0 -0
- data/spec/filters/bugs/case.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/coerce_integer.rb +0 -0
- data/spec/filters/bugs/enumerable_sort_by.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/kernel/instance_variables.rb +0 -0
- data/spec/filters/bugs/kernel/rand.rb +4 -0
- data/spec/filters/bugs/language/array.rb +3 -0
- data/spec/filters/bugs/language/block.rb +6 -0
- data/spec/filters/bugs/language/break.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class_variables.rb +0 -0
- data/spec/filters/bugs/language/def.rb +27 -0
- data/spec/filters/bugs/language/defined.rb +3 -0
- data/spec/filters/bugs/language/ensure.rb +4 -0
- data/spec/filters/bugs/language/execution.rb +4 -0
- data/spec/filters/bugs/language/for.rb +18 -0
- data/spec/filters/bugs/language/if.rb +13 -0
- data/spec/filters/bugs/language/loop.rb +4 -0
- data/spec/filters/bugs/language/metaclass.rb +14 -0
- data/spec/filters/bugs/language/module.rb +6 -0
- data/spec/filters/bugs/language/next.rb +3 -0
- data/spec/filters/bugs/language/or.rb +3 -0
- data/spec/filters/bugs/language/order.rb +4 -0
- data/spec/filters/bugs/language/precedence.rb +10 -0
- data/spec/filters/bugs/language/proc.rb +24 -0
- data/spec/filters/bugs/language/redo.rb +5 -0
- data/spec/filters/bugs/language/rescue.rb +9 -0
- data/spec/filters/bugs/language/retry.rb +5 -0
- data/spec/filters/bugs/language/send.rb +10 -0
- data/spec/filters/bugs/language/super.rb +9 -0
- data/spec/filters/bugs/language/until.rb +8 -0
- data/spec/filters/bugs/language/variables.rb +37 -0
- data/spec/filters/bugs/language/while.rb +6 -0
- data/spec/filters/bugs/language/yield.rb +5 -0
- data/spec/{rubyspec/filters → filters}/bugs/module/class_variables.rb +0 -0
- data/spec/filters/bugs/module/method_defined.rb +6 -0
- data/spec/filters/bugs/parser.rb +10 -0
- data/spec/{rubyspec/filters → filters}/bugs/public_methods.rb +1 -0
- data/spec/filters/bugs/return.rb +7 -0
- data/spec/filters/bugs/singleton/instance.rb +4 -0
- data/spec/filters/bugs/source_map.rb +3 -0
- data/spec/filters/bugs/string/center.rb +4 -0
- data/spec/filters/bugs/string/lines.rb +3 -0
- data/spec/{rubyspec/filters → filters}/mspec/mocks.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/ruby_exe.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/should_receive.rb +0 -0
- data/spec/{rubyspec/filters → filters}/parser/block_args.rb +0 -0
- data/spec/{rubyspec/filters → filters}/unsupported/array_subclasses.rb +1 -0
- data/spec/filters/unsupported/frozen.rb +32 -0
- data/spec/filters/unsupported/immutable_strings.rb +3 -0
- data/spec/filters/unsupported/tainted.rb +17 -0
- data/spec/filters/unsupported/trusted.rb +15 -0
- data/spec/opal/class/constants_spec.rb +7 -0
- data/spec/opal/erb/erb_spec.rb +7 -1
- data/spec/opal/erb/inline_block.opalerb +3 -0
- data/spec/opal/hash/allocate_spec.rb +16 -0
- data/spec/opal/hash/new_spec.rb +10 -0
- data/spec/opal/hash/to_s_spec.rb +9 -0
- data/spec/opal/kernel/instance_variable_defined_spec.rb +15 -0
- data/spec/opal/kernel/rand_spec.rb +5 -5
- data/spec/opal/kernel/respond_to_spec.rb +14 -1
- data/spec/opal/language/block_spec.rb +13 -0
- data/spec/opal/language/rescue_spec.rb +27 -0
- data/spec/opal/language/return_spec.rb +38 -0
- data/spec/opal/language/singleton_class_spec.rb +13 -0
- data/spec/opal/language/super_spec.rb +99 -0
- data/spec/opal/language/variables_spec.rb +20 -0
- data/spec/opal/module/attr_accessor_spec.rb +8 -0
- data/spec/opal/module/constants_spec.rb +2 -2
- data/spec/opal/native/alias_native_spec.rb +18 -0
- data/spec/opal/native/each_spec.rb +14 -0
- data/spec/opal/native/element_reference_spec.rb +14 -0
- data/spec/opal/native/method_missing_spec.rb +39 -0
- data/spec/opal/native/new_spec.rb +19 -0
- data/spec/opal/native/nil_spec.rb +14 -0
- data/spec/opal/runtime2/class_hierarchy_spec.rb +2 -2
- data/spec/opal/source_map_spec.rb +3 -7
- data/spec/ospec/main.rb.erb +2 -5
- data/spec/parser/alias_spec.rb +4 -4
- data/spec/parser/and_spec.rb +2 -2
- data/spec/parser/array_spec.rb +6 -6
- data/spec/parser/attrasgn_spec.rb +8 -8
- data/spec/parser/begin_spec.rb +11 -11
- data/spec/parser/block_spec.rb +3 -3
- data/spec/parser/break_spec.rb +4 -4
- data/spec/parser/call_spec.rb +50 -48
- data/spec/parser/class_spec.rb +2 -2
- data/spec/parser/const_spec.rb +1 -1
- data/spec/parser/cvar_spec.rb +1 -1
- data/spec/parser/def_spec.rb +5 -5
- data/spec/parser/gvar_spec.rb +2 -2
- data/spec/parser/hash_spec.rb +4 -4
- data/spec/parser/iasgn_spec.rb +3 -3
- data/spec/parser/if_spec.rb +6 -6
- data/spec/parser/iter_spec.rb +6 -6
- data/spec/parser/lambda_spec.rb +5 -5
- data/spec/parser/lasgn_spec.rb +2 -2
- data/spec/parser/line_spec.rb +2 -2
- data/spec/parser/lvar_spec.rb +5 -5
- data/spec/parser/masgn_spec.rb +1 -1
- data/spec/parser/module_spec.rb +2 -2
- data/spec/parser/not_spec.rb +4 -4
- data/spec/parser/op_asgn1_spec.rb +2 -2
- data/spec/parser/op_asgn2_spec.rb +2 -2
- data/spec/parser/or_spec.rb +2 -2
- data/spec/parser/parse_spec.rb +66 -0
- data/spec/parser/parser_spec.rb +32 -38
- data/spec/parser/regexp_spec.rb +4 -4
- data/spec/parser/return_spec.rb +4 -4
- data/spec/parser/sclass_spec.rb +4 -4
- data/spec/parser/str_spec.rb +3 -3
- data/spec/parser/super_spec.rb +6 -6
- data/spec/parser/undef_spec.rb +3 -3
- data/spec/parser/unless_spec.rb +4 -4
- data/spec/parser/while_spec.rb +3 -3
- data/spec/parser/xstr_spec.rb +3 -3
- data/spec/parser/yield_spec.rb +6 -6
- data/spec/rubyspec/core/array/drop_spec.rb +1 -1
- data/spec/rubyspec/core/array/keep_if_spec.rb +1 -3
- data/spec/rubyspec/core/array/length_spec.rb +1 -3
- data/spec/rubyspec/core/array/map_spec.rb +2 -6
- data/spec/rubyspec/core/array/minus_spec.rb +3 -3
- data/spec/rubyspec/core/array/multiply_spec.rb +14 -16
- data/spec/rubyspec/core/array/new_spec.rb +3 -5
- data/spec/rubyspec/core/array/plus_spec.rb +2 -2
- data/spec/rubyspec/core/array/pop_spec.rb +4 -4
- data/spec/rubyspec/core/array/rassoc_spec.rb +2 -2
- data/spec/rubyspec/core/array/reject_spec.rb +2 -6
- data/spec/rubyspec/core/array/replace_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_each_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_spec.rb +4 -4
- data/spec/rubyspec/core/array/rindex_spec.rb +1 -1
- data/spec/rubyspec/core/array/select_spec.rb +3 -7
- data/spec/rubyspec/core/array/shared/collect.rb +7 -0
- data/spec/rubyspec/core/array/shared/index.rb +1 -1
- data/spec/rubyspec/core/array/shared/keep_if.rb +3 -0
- data/spec/rubyspec/core/array/shared/length.rb +3 -0
- data/spec/rubyspec/core/array/shared/replace.rb +3 -0
- data/spec/rubyspec/core/array/shared/slice.rb +3 -0
- data/spec/rubyspec/core/array/shuffle_spec.rb +1 -1
- data/spec/rubyspec/core/array/size_spec.rb +1 -3
- data/spec/rubyspec/core/array/slice_spec.rb +4 -6
- data/spec/rubyspec/core/array/sort_spec.rb +2 -2
- data/spec/rubyspec/core/array/to_a_spec.rb +1 -1
- data/spec/rubyspec/core/array/try_convert_spec.rb +7 -7
- data/spec/rubyspec/core/array/uniq_spec.rb +7 -7
- data/spec/rubyspec/core/array/zip_spec.rb +1 -1
- data/spec/rubyspec/core/enumerable/collect_spec.rb +24 -0
- data/spec/rubyspec/core/enumerable/count_spec.rb +35 -19
- data/spec/rubyspec/core/enumerable/find_spec.rb +5 -0
- data/spec/rubyspec/core/hash/each_pair_spec.rb +7 -7
- data/spec/rubyspec/core/hash/each_spec.rb +13 -7
- data/spec/rubyspec/core/module/method_defined_spec.rb +4 -4
- data/spec/rubyspec/core/module/public_method_defined_spec.rb +19 -0
- data/spec/rubyspec/core/module/remove_const_spec.rb +23 -0
- data/spec/rubyspec/core/numeric/step_spec.rb +14 -0
- data/spec/rubyspec/core/string/center_spec.rb +43 -65
- data/spec/rubyspec/core/string/lines_spec.rb +1 -1
- data/spec/rubyspec/core/string/ljust_spec.rb +25 -9
- data/spec/rubyspec/core/string/rjust_spec.rb +26 -10
- data/spec/rubyspec/core/struct/fixtures/classes.rb +26 -0
- data/spec/rubyspec/core/struct/initialize_spec.rb +11 -0
- data/spec/rubyspec/core/struct/new_spec.rb +24 -0
- data/spec/rubyspec/fixtures/constants.rb +7 -0
- data/spec/rubyspec/language/break_spec.rb +1 -1
- data/spec/rubyspec/language/case_spec.rb +30 -30
- data/spec/rubyspec/language/def_spec.rb +34 -34
- data/spec/rubyspec/language/defined_spec.rb +2 -2
- data/spec/rubyspec/language/ensure_spec.rb +2 -2
- data/spec/rubyspec/language/execution_spec.rb +2 -2
- data/spec/rubyspec/language/for_spec.rb +17 -17
- data/spec/rubyspec/language/hash_spec.rb +3 -3
- data/spec/rubyspec/language/if_spec.rb +11 -11
- data/spec/rubyspec/language/loop_spec.rb +3 -3
- data/spec/rubyspec/language/metaclass_spec.rb +14 -14
- data/spec/rubyspec/language/module_spec.rb +6 -6
- data/spec/rubyspec/language/next_spec.rb +5 -5
- data/spec/rubyspec/language/not_spec.rb +1 -1
- data/spec/rubyspec/language/or_spec.rb +1 -1
- data/spec/rubyspec/language/order_spec.rb +3 -5
- data/spec/rubyspec/language/precedence_spec.rb +19 -19
- data/spec/rubyspec/language/proc_spec.rb +29 -29
- data/spec/rubyspec/language/redo_spec.rb +3 -5
- data/spec/rubyspec/language/rescue_spec.rb +7 -7
- data/spec/rubyspec/language/retry_spec.rb +2 -2
- data/spec/rubyspec/language/return_spec.rb +12 -12
- data/spec/rubyspec/language/send_spec.rb +9 -9
- data/spec/rubyspec/language/singleton_class_spec.rb +3 -4
- data/spec/rubyspec/language/super_spec.rb +7 -11
- data/spec/rubyspec/language/until_spec.rb +10 -10
- data/spec/rubyspec/language/variables_spec.rb +59 -67
- data/spec/rubyspec/language/versions/array_1.9.rb +1 -1
- data/spec/rubyspec/language/versions/block_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/break_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/literal_lambda_1.9.rb +12 -12
- data/spec/rubyspec/language/versions/send_1.9.rb +23 -23
- data/spec/rubyspec/language/versions/symbol_1.9.rb +2 -2
- data/spec/rubyspec/language/versions/variables_1.9.rb +1 -1
- data/spec/rubyspec/language/while_spec.rb +4 -4
- data/spec/rubyspec/language/yield_spec.rb +3 -3
- data/spec/rubyspec/library/erb/util/html_escape_spec.rb +10 -0
- data/spec/rubyspec/library/singleton/clone_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/dup_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/fixtures/classes.rb +18 -0
- data/spec/rubyspec/library/singleton/instance_spec.rb +30 -0
- data/spec/spec_helper.rb +214 -0
- data/stdlib/buffer.rb +40 -0
- data/stdlib/buffer/array.rb +66 -0
- data/stdlib/buffer/view.rb +70 -0
- data/stdlib/erb.rb +11 -20
- data/stdlib/forwardable.rb +71 -0
- data/stdlib/json.rb +78 -0
- data/stdlib/ostruct.rb +69 -0
- data/stdlib/rbconfig.rb +1 -0
- data/stdlib/singleton.rb +40 -0
- data/stdlib/stringio.rb +173 -0
- data/stdlib/template.rb +44 -0
- metadata +285 -79
- data/corelib/opal/native.rb +0 -31
- data/spec/opal/class/bridge_class_spec.rb +0 -39
- data/spec/opal/native_spec.rb +0 -209
- data/spec/ospec/runner.rb +0 -223
- data/spec/rubyspec/filters/bugs/block_args.rb +0 -3
- data/spec/rubyspec/filters/bugs/case.rb +0 -8
- data/spec/rubyspec/filters/bugs/language/module.rb +0 -3
- data/spec/rubyspec/filters/unsupported/frozen.rb +0 -4
- data/spec/rubyspec/filters/unsupported/tainted.rb +0 -7
@@ -46,7 +46,7 @@ describe "Array#+" do
|
|
46
46
|
([5, 6] + ArraySpecs::ToAryArray[1, 2]).should == [5, 6, 1, 2]
|
47
47
|
end
|
48
48
|
|
49
|
-
|
49
|
+
it "does not get infected even if an original array is tainted" do
|
50
50
|
([1, 2] + [3, 4]).tainted?.should be_false
|
51
51
|
([1, 2].taint + [3, 4]).tainted?.should be_false
|
52
52
|
([1, 2] + [3, 4].taint).tainted?.should be_false
|
@@ -54,7 +54,7 @@ describe "Array#+" do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
ruby_version_is '1.9' do
|
57
|
-
|
57
|
+
it "does not infected even if an original array is untrusted" do
|
58
58
|
([1, 2] + [3, 4]).untrusted?.should be_false
|
59
59
|
([1, 2].untrust + [3, 4]).untrusted?.should be_false
|
60
60
|
([1, 2] + [3, 4].untrust).untrusted?.should be_false
|
@@ -30,7 +30,7 @@ describe "Array#pop" do
|
|
30
30
|
array.pop.should == [1, 'two', 3.0, array, array, array, array]
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
it "keeps taint status" do
|
34
34
|
a = [1, 2].taint
|
35
35
|
a.pop
|
36
36
|
a.tainted?.should be_true
|
@@ -56,7 +56,7 @@ describe "Array#pop" do
|
|
56
56
|
lambda { ArraySpecs.empty_frozen_array.pop }.should raise_error(RuntimeError)
|
57
57
|
end
|
58
58
|
|
59
|
-
|
59
|
+
it "keeps untrusted status" do
|
60
60
|
a = [1, 2].untrust
|
61
61
|
a.pop
|
62
62
|
a.untrusted?.should be_true
|
@@ -173,7 +173,7 @@ describe "Array#pop" do
|
|
173
173
|
end
|
174
174
|
|
175
175
|
ruby_version_is '1.9' do
|
176
|
-
|
176
|
+
it "returns a trusted array even if the array is untrusted" do
|
177
177
|
ary = [1, 2].untrust
|
178
178
|
ary.pop(2).untrusted?.should be_false
|
179
179
|
ary.pop(0).untrusted?.should be_false
|
@@ -184,7 +184,7 @@ describe "Array#pop" do
|
|
184
184
|
lambda { ArraySpecs.frozen_array.pop(0) }.should raise_error(RuntimeError)
|
185
185
|
end
|
186
186
|
|
187
|
-
|
187
|
+
it "keeps untrusted status" do
|
188
188
|
a = [1, 2].untrust
|
189
189
|
a.pop(2)
|
190
190
|
a.untrusted?.should be_true
|
@@ -20,7 +20,7 @@ describe "Array#rassoc" do
|
|
20
20
|
[[empty, array]].rassoc(array).should == [empty, array]
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
it "calls elem == obj on the second element of each contained array" do
|
24
24
|
key = 'foobar'
|
25
25
|
o = mock('foobar')
|
26
26
|
def o.==(other); other == 'foobar'; end
|
@@ -28,7 +28,7 @@ describe "Array#rassoc" do
|
|
28
28
|
[[1, :foobar], [2, o], [3, mock('foo')]].rassoc(key).should == [2, o]
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
it "does not check the last element in each contained but speficically the second" do
|
32
32
|
key = 'foobar'
|
33
33
|
o = mock('foobar')
|
34
34
|
def o.==(other); other == 'foobar'; end
|
@@ -57,9 +57,7 @@ describe "Array#reject" do
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
|
61
|
-
it_behaves_like :enumeratorize, :reject
|
62
|
-
end
|
60
|
+
it_behaves_like :enumeratorize, :reject
|
63
61
|
end
|
64
62
|
|
65
63
|
describe "Array#reject!" do
|
@@ -132,7 +130,5 @@ describe "Array#reject!" do
|
|
132
130
|
end
|
133
131
|
end
|
134
132
|
|
135
|
-
|
136
|
-
it_behaves_like :enumeratorize, :reject!
|
137
|
-
end
|
133
|
+
it_behaves_like :enumeratorize, :reject!
|
138
134
|
end
|
@@ -7,7 +7,7 @@ describe "Array#reverse" do
|
|
7
7
|
[1, 3, 5, 2].reverse.should == [2, 5, 3, 1]
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
it "properly handles recursive arrays" do
|
11
11
|
empty = ArraySpecs.empty_recursive_array
|
12
12
|
empty.reverse.should == empty
|
13
13
|
|
@@ -16,7 +16,7 @@ describe "Array#reverse" do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
ruby_version_is "" ... "1.9.3" do
|
19
|
-
|
19
|
+
it "returns subclass instance on Array subclasses" do
|
20
20
|
ArraySpecs::MyArray[1, 2, 3].reverse.should be_kind_of(ArraySpecs::MyArray)
|
21
21
|
end
|
22
22
|
end
|
@@ -29,14 +29,14 @@ describe "Array#reverse" do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
describe "Array#reverse!" do
|
32
|
-
|
32
|
+
it "reverses the elements in place" do
|
33
33
|
a = [6, 3, 4, 2, 1]
|
34
34
|
a.reverse!.should equal(a)
|
35
35
|
a.should == [1, 2, 4, 3, 6]
|
36
36
|
[].reverse!.should == []
|
37
37
|
end
|
38
38
|
|
39
|
-
|
39
|
+
it "properly handles recursive arrays" do
|
40
40
|
empty = ArraySpecs.empty_recursive_array
|
41
41
|
empty.reverse!.should == [empty]
|
42
42
|
|
@@ -6,7 +6,7 @@ require File.expand_path('../fixtures/classes', __FILE__)
|
|
6
6
|
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/23633
|
7
7
|
|
8
8
|
describe "Array#rindex" do
|
9
|
-
|
9
|
+
it "returns the first index backwards from the end where element == to object" do
|
10
10
|
key = 3
|
11
11
|
uno = mock('one')
|
12
12
|
dos = mock('two')
|
@@ -4,11 +4,9 @@ require File.expand_path('../shared/enumeratorize', __FILE__)
|
|
4
4
|
require File.expand_path('../shared/keep_if', __FILE__)
|
5
5
|
|
6
6
|
describe "Array#select" do
|
7
|
-
|
8
|
-
it_behaves_like :enumeratorize, :select
|
9
|
-
end
|
7
|
+
it_behaves_like :enumeratorize, :select
|
10
8
|
|
11
|
-
|
9
|
+
it "returns a new array of elements for which block is true" do
|
12
10
|
[1, 3, 4, 5, 6, 9].select { |i| i % ((i + 1) / 2) == 0}.should == [1, 4, 6]
|
13
11
|
end
|
14
12
|
|
@@ -33,8 +31,6 @@ ruby_version_is "1.9" do
|
|
33
31
|
[1, 2, 3].select! { true }.should be_nil
|
34
32
|
end
|
35
33
|
|
36
|
-
|
37
|
-
it_behaves_like :keep_if, :select!
|
38
|
-
end
|
34
|
+
it_behaves_like :keep_if, :select!
|
39
35
|
end
|
40
36
|
end
|
@@ -24,7 +24,7 @@ describe "Array#shuffle" do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
ruby_version_is "1.8.7" ... "1.9.3" do
|
27
|
-
|
27
|
+
it "returns subclass instances with Array subclass" do
|
28
28
|
ArraySpecs::MyArray[1, 2, 3].shuffle.should be_an_instance_of(ArraySpecs::MyArray)
|
29
29
|
end
|
30
30
|
end
|
@@ -48,7 +48,7 @@ describe "Array#slice!" do
|
|
48
48
|
array.slice(0..3).should == [1, 'two', 3.0, array]
|
49
49
|
end
|
50
50
|
|
51
|
-
|
51
|
+
it "calls to_int on start and length arguments" do
|
52
52
|
obj = mock('2')
|
53
53
|
def obj.to_int() 2 end
|
54
54
|
|
@@ -61,7 +61,7 @@ describe "Array#slice!" do
|
|
61
61
|
a.should == []
|
62
62
|
end
|
63
63
|
|
64
|
-
|
64
|
+
it "removes and return elements in range" do
|
65
65
|
a = [1, 2, 3, 4, 5, 6, 7, 8]
|
66
66
|
a.slice!(1..4).should == [2, 3, 4, 5]
|
67
67
|
a.should == [1, 6, 7, 8]
|
@@ -79,7 +79,7 @@ describe "Array#slice!" do
|
|
79
79
|
a.should == []
|
80
80
|
end
|
81
81
|
|
82
|
-
|
82
|
+
it "calls to_int on range arguments" do
|
83
83
|
from = mock('from')
|
84
84
|
to = mock('to')
|
85
85
|
|
@@ -162,7 +162,5 @@ describe "Array#slice!" do
|
|
162
162
|
end
|
163
163
|
|
164
164
|
describe "Array#slice" do
|
165
|
-
|
166
|
-
it_behaves_like(:array_slice, :slice)
|
167
|
-
end
|
165
|
+
it_behaves_like(:array_slice, :slice)
|
168
166
|
end
|
@@ -96,7 +96,7 @@ describe "Array#sort" do
|
|
96
96
|
a.sort { -1 }.should be_kind_of(Array)
|
97
97
|
end
|
98
98
|
|
99
|
-
|
99
|
+
it "does not freezes self during being sorted" do
|
100
100
|
a = [1, 2, 3]
|
101
101
|
a.sort { |x,y| a.frozen?.should == false; x <=> y }
|
102
102
|
end
|
@@ -159,7 +159,7 @@ describe "Array#sort" do
|
|
159
159
|
end
|
160
160
|
|
161
161
|
ruby_version_is "" ... "1.9.3" do
|
162
|
-
|
162
|
+
it "returns subclass instance on Array subclasses" do
|
163
163
|
ary = ArraySpecs::MyArray[1, 2, 3]
|
164
164
|
ary.sort.should be_kind_of(ArraySpecs::MyArray)
|
165
165
|
end
|
@@ -8,7 +8,7 @@ describe "Array#to_a" do
|
|
8
8
|
a.should equal(a.to_a)
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
it "does not return subclass instance on Array subclasses" do
|
12
12
|
e = ArraySpecs::MyArray.new(1, 2)
|
13
13
|
e.to_a.should be_an_instance_of(Array)
|
14
14
|
e.to_a.should == [1, 2]
|
@@ -8,42 +8,42 @@ ruby_version_is "1.9" do
|
|
8
8
|
Array.try_convert(x).should equal(x)
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
it "returns the argument if it's a kind of Array" do
|
12
12
|
x = ArraySpecs::MyArray[]
|
13
13
|
Array.try_convert(x).should equal(x)
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
it "returns nil when the argument does not respond to #to_ary" do
|
17
17
|
Array.try_convert(Object.new).should be_nil
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
it "sends #to_ary to the argument and returns the result if it's nil" do
|
21
21
|
obj = mock("to_ary")
|
22
22
|
obj.should_receive(:to_ary).and_return(nil)
|
23
23
|
Array.try_convert(obj).should be_nil
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
it "sends #to_ary to the argument and returns the result if it's an Array" do
|
27
27
|
x = Array.new
|
28
28
|
obj = mock("to_ary")
|
29
29
|
obj.should_receive(:to_ary).and_return(x)
|
30
30
|
Array.try_convert(obj).should equal(x)
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
it "sends #to_ary to the argument and returns the result if it's a kind of Array" do
|
34
34
|
x = ArraySpecs::MyArray[]
|
35
35
|
obj = mock("to_ary")
|
36
36
|
obj.should_receive(:to_ary).and_return(x)
|
37
37
|
Array.try_convert(obj).should equal(x)
|
38
38
|
end
|
39
39
|
|
40
|
-
|
40
|
+
it "sends #to_ary to the argument and raises TypeError if it's not a kind of Array" do
|
41
41
|
obj = mock("to_ary")
|
42
42
|
obj.should_receive(:to_ary).and_return(Object.new)
|
43
43
|
lambda { Array.try_convert obj }.should raise_error(TypeError)
|
44
44
|
end
|
45
45
|
|
46
|
-
|
46
|
+
it "does not rescue exceptions raised by #to_ary" do
|
47
47
|
obj = mock("to_ary")
|
48
48
|
obj.should_receive(:to_ary).and_raise(RuntimeError)
|
49
49
|
lambda { Array.try_convert obj }.should raise_error(RuntimeError)
|
@@ -16,7 +16,7 @@ describe "Array#uniq" do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
it "uses eql? semantics" do
|
20
20
|
[1.0, 1].uniq.should == [1.0, 1]
|
21
21
|
end
|
22
22
|
|
@@ -43,7 +43,7 @@ describe "Array#uniq" do
|
|
43
43
|
[x, y].uniq.should == [x, y]
|
44
44
|
end
|
45
45
|
|
46
|
-
|
46
|
+
it "compares elements with matching hash codes with #eql?" do
|
47
47
|
# Can't use should_receive because it uses hash and eql? internally
|
48
48
|
a = Array.new(2) do
|
49
49
|
obj = mock('0')
|
@@ -81,14 +81,14 @@ describe "Array#uniq" do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
ruby_version_is "1.9" do
|
84
|
-
|
84
|
+
it "compares elements based on the value returned from the block" do
|
85
85
|
a = [1, 2, 3, 4]
|
86
86
|
a.uniq { |x| x >= 2 ? 1 : 0 }.should == [1, 2]
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
ruby_version_is "" ... "1.9.3" do
|
91
|
-
|
91
|
+
it "returns subclass instance on Array subclasses" do
|
92
92
|
ArraySpecs::MyArray[1, 2, 3].uniq.should be_kind_of(ArraySpecs::MyArray)
|
93
93
|
end
|
94
94
|
end
|
@@ -113,7 +113,7 @@ describe "Array#uniq!" do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
ruby_bug "#", "1.8.6.277" do
|
116
|
-
|
116
|
+
it "properly handles recursive arrays" do
|
117
117
|
empty = ArraySpecs.empty_recursive_array
|
118
118
|
empty_dup = empty.dup
|
119
119
|
empty.uniq!
|
@@ -143,7 +143,7 @@ describe "Array#uniq!" do
|
|
143
143
|
end
|
144
144
|
|
145
145
|
ruby_version_is "1.9" do
|
146
|
-
|
146
|
+
it "raises a RuntimeError on a frozen array when the array is modified" do
|
147
147
|
dup_ary = [1, 1, 2]
|
148
148
|
dup_ary.freeze
|
149
149
|
lambda { dup_ary.uniq! }.should raise_error(RuntimeError)
|
@@ -159,7 +159,7 @@ describe "Array#uniq!" do
|
|
159
159
|
lambda { ArraySpecs.frozen_array.uniq!{ raise RangeError, "shouldn't yield"}}.should raise_error(RuntimeError)
|
160
160
|
end
|
161
161
|
|
162
|
-
|
162
|
+
it "compares elements based on the value returned from the block" do
|
163
163
|
a = [1, 2, 3, 4]
|
164
164
|
a.uniq! { |x| x >= 2 ? 1 : 0 }.should == [1, 2]
|
165
165
|
end
|
@@ -22,7 +22,7 @@ describe "Array#zip" do
|
|
22
22
|
b.zip(b).should == [ [b[0], b[0]], [b[1], b[1]] ]
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
it "calls #to_ary to convert the argument to an Array" do
|
26
26
|
obj = mock('[3,4]')
|
27
27
|
obj.should_receive(:to_ary).and_return([3, 4])
|
28
28
|
[1, 2].zip(obj).should == [[1, 3], [2, 4]]
|
@@ -12,4 +12,28 @@ describe "Enumerable#collect" do
|
|
12
12
|
numerous.collect { |i| i % 2 }.should == [0, 1, 1, 0, 1, 0]
|
13
13
|
numerous.collect { |i| i }.should == entries
|
14
14
|
end
|
15
|
+
|
16
|
+
ruby_version_is ""..."1.9" do
|
17
|
+
it "gathers whole arrays as elements when each yields multiple" do
|
18
|
+
multi = EnumerableSpecs::YieldsMulti.new
|
19
|
+
multi.send(@method) {|e| e}.should == [[1,2],[3,4,5],[6,7,8,9]]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns to_a when no block given" do
|
23
|
+
EnumerableSpecs::Numerous.new.send(@method).should == [2, 5, 3, 6, 1, 4]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
ruby_version_is "1.9" do
|
28
|
+
it "gathers initial args as elements when each yields multiple" do
|
29
|
+
multi = EnumerableSpecs::YieldsMulti.new
|
30
|
+
multi.collect {|e| e}.should == [1, 3, 6]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns an enumerator when no block given" do
|
34
|
+
enum = EnumerableSpecs::Numerous.new.collect
|
35
|
+
enum.should be_an_instance_of(enumerator_class)
|
36
|
+
enum.each { |i| -i }.should == [-2, -5, -3, -6, -1, -4]
|
37
|
+
end
|
38
|
+
end
|
15
39
|
end
|