opal 0.3.41 → 0.3.42
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +14 -1
- data/Gemfile +2 -5
- data/Rakefile +41 -3
- data/bin/opal +33 -0
- data/lib/opal.rb +2 -12
- data/lib/opal/core_ext.rb +5 -0
- data/lib/opal/grammar.rb +2207 -2138
- data/lib/opal/grammar.y +21 -0
- data/lib/opal/grammar_helpers.rb +360 -0
- data/lib/opal/lexer.rb +55 -401
- data/lib/opal/lexer_scope.rb +28 -0
- data/lib/opal/parser.rb +155 -171
- data/lib/opal/target_scope.rb +257 -0
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +6 -2
- data/opal/opal-parser.js.erb +3 -2
- data/opal/opal.rb +20 -18
- data/opal/opal/array.rb +21 -12
- data/opal/opal/basic_object.rb +2 -1
- data/opal/opal/boolean.rb +3 -0
- data/opal/opal/browser_loader.js +57 -0
- data/opal/opal/class.rb +51 -13
- data/opal/opal/date.rb +1 -20
- data/opal/opal/enumerable.rb +66 -33
- data/opal/opal/error.rb +2 -0
- data/opal/opal/hash.rb +1 -1
- data/opal/opal/kernel.rb +14 -3
- data/opal/opal/nil_class.rb +4 -0
- data/opal/opal/proc.rb +9 -1
- data/opal/opal/racc.rb +2 -2
- data/opal/opal/regexp.rb +1 -1
- data/opal/opal/runtime.js +14 -4
- data/opal/opal/string.rb +21 -4
- data/opal/opal/time.rb +27 -0
- data/spec/core/array/allocate_spec.rb +7 -1
- data/spec/core/array/append_spec.rb +18 -3
- data/spec/core/array/array_spec.rb +7 -0
- data/spec/core/array/assoc_spec.rb +23 -8
- data/spec/core/array/at_spec.rb +23 -3
- data/spec/core/array/choice_spec.rb +20 -0
- data/spec/core/array/clear_spec.rb +45 -4
- data/spec/core/array/combination_spec.rb +55 -0
- data/spec/core/array/compact_spec.rb +72 -1
- data/spec/core/array/constructor_spec.rb +13 -2
- data/spec/core/array/count_spec.rb +15 -7
- data/spec/core/array/delete_at_spec.rb +44 -1
- data/spec/core/array/delete_if_spec.rb +52 -2
- data/spec/core/array/delete_spec.rb +83 -2
- data/spec/core/array/drop_spec.rb +24 -16
- data/spec/core/array/drop_while_spec.rb +17 -0
- data/spec/core/array/each_index_spec.rb +11 -1
- data/spec/core/array/each_spec.rb +20 -2
- data/spec/core/array/empty_spec.rb +4 -1
- data/spec/core/array/eql_spec.rb +14 -0
- data/spec/core/array/fetch_spec.rb +31 -2
- data/spec/core/array/find_index_spec.rb +8 -0
- data/spec/core/array/first_spec.rb +45 -8
- data/spec/core/array/fixtures/classes.rb +538 -0
- data/spec/core/array/flatten_spec.rb +200 -7
- data/spec/core/array/frozen_spec.rb +32 -0
- data/spec/core/array/include_spec.rb +16 -1
- data/spec/core/array/index_spec.rb +5 -25
- data/spec/core/array/insert_spec.rb +37 -3
- data/spec/core/array/inspect_spec.rb +6 -12
- data/spec/core/array/intersection_spec.rb +55 -4
- data/spec/core/array/join_spec.rb +29 -4
- data/spec/core/array/keep_if_spec.rb +13 -6
- data/spec/core/array/last_spec.rb +35 -1
- data/spec/core/array/length_spec.rb +7 -4
- data/spec/core/array/map_spec.rb +9 -47
- data/spec/core/array/minus_spec.rb +68 -4
- data/spec/core/array/multiply_spec.rb +138 -6
- data/spec/core/array/new_spec.rb +92 -3
- data/spec/core/array/ntimes_spec.rb +26 -0
- data/spec/core/array/plus_spec.rb +48 -2
- data/spec/core/array/pop_spec.rb +159 -39
- data/spec/core/array/push_spec.rb +29 -1
- data/spec/core/array/rassoc_spec.rb +31 -2
- data/spec/core/array/reject_spec.rb +89 -2
- data/spec/core/array/replace_spec.rb +7 -29
- data/spec/core/array/reverse_each_spec.rb +25 -1
- data/spec/core/array/reverse_spec.rb +53 -1
- data/spec/core/array/rindex_spec.rb +55 -5
- data/spec/core/array/select_spec.rb +35 -8
- data/spec/core/array/shared/collect.rb +0 -0
- data/spec/core/array/shared/enumeratorize.rb +12 -0
- data/spec/core/array/shared/eql.rb +95 -0
- data/spec/core/array/shared/index.rb +37 -0
- data/spec/core/array/shared/inspect.rb +3 -0
- data/spec/core/array/shared/join.rb +7 -0
- data/spec/core/array/shared/keep_if.rb +0 -0
- data/spec/core/array/shared/length.rb +0 -0
- data/spec/core/array/shared/replace.rb +0 -0
- data/spec/core/array/shared/slice.rb +0 -0
- data/spec/core/array/shift_spec.rb +132 -23
- data/spec/core/array/shuffle_spec.rb +82 -6
- data/spec/core/array/size_spec.rb +7 -4
- data/spec/core/array/slice_spec.rb +132 -1
- data/spec/core/array/sort_spec.rb +263 -14
- data/spec/core/array/take_spec.rb +24 -16
- data/spec/core/array/take_while_spec.rb +14 -10
- data/spec/core/array/to_a_spec.rb +18 -1
- data/spec/core/array/to_ary_spec.rb +15 -1
- data/spec/core/array/try_convert_spec.rb +39 -2
- data/spec/core/array/uniq_spec.rb +148 -3
- data/spec/core/array/unshift_spec.rb +36 -1
- data/spec/core/array/zip_spec.rb +36 -1
- data/spec/core/class/new_spec.rb +8 -6
- data/spec/core/enumerable/all_spec.rb +37 -9
- data/spec/core/enumerable/any_spec.rb +45 -7
- data/spec/core/enumerable/collect_spec.rb +4 -1
- data/spec/core/enumerable/count_spec.rb +4 -1
- data/spec/core/enumerable/detect_spec.rb +2 -2
- data/spec/core/enumerable/drop_spec.rb +4 -1
- data/spec/core/enumerable/drop_while_spec.rb +4 -1
- data/spec/core/enumerable/each_slice_spec.rb +2 -1
- data/spec/core/enumerable/each_with_index_spec.rb +4 -1
- data/spec/core/enumerable/each_with_object_spec.rb +4 -1
- data/spec/core/enumerable/entries_spec.rb +4 -1
- data/spec/core/enumerable/find_all_spec.rb +4 -1
- data/spec/core/enumerable/find_index_spec.rb +4 -1
- data/spec/core/enumerable/find_spec.rb +5 -2
- data/spec/core/enumerable/first_spec.rb +4 -1
- data/spec/core/enumerable/fixtures/classes.rb +198 -2
- data/spec/core/enumerable/grep_spec.rb +4 -1
- data/spec/core/enumerable/take_spec.rb +4 -1
- data/spec/core/enumerable/to_a_spec.rb +4 -1
- data/spec/core/false/and_spec.rb +11 -0
- data/spec/core/false/inspect_spec.rb +7 -0
- data/spec/core/false/or_spec.rb +11 -0
- data/spec/core/false/to_s_spec.rb +7 -0
- data/spec/core/false/xor_spec.rb +11 -0
- data/spec/core/kernel/rand_spec.rb +5 -5
- data/spec/core/module/const_get_spec.rb +4 -4
- data/spec/core/module/fixtures/classes.rb +434 -0
- data/spec/core/module/method_defined_spec.rb +49 -0
- data/spec/core/module/module_function_spec.rb +28 -0
- data/spec/core/nil/and_spec.rb +3 -1
- data/spec/core/nil/dup_spec.rb +7 -0
- data/spec/core/nil/inspect_spec.rb +3 -1
- data/spec/core/nil/nil_spec.rb +3 -1
- data/spec/core/nil/or_spec.rb +4 -2
- data/spec/core/nil/to_a_spec.rb +3 -1
- data/spec/core/nil/to_f_spec.rb +3 -1
- data/spec/core/nil/to_i_spec.rb +3 -1
- data/spec/core/nil/to_s_spec.rb +3 -1
- data/spec/core/nil/xor_spec.rb +4 -2
- data/spec/core/string/element_reference_spec.rb +14 -1
- data/spec/core/string/fixtures/classes.rb +0 -0
- data/spec/core/true/and_spec.rb +11 -0
- data/spec/core/true/inspect_spec.rb +7 -0
- data/spec/core/true/or_spec.rb +11 -0
- data/spec/core/true/to_s_spec.rb +7 -0
- data/spec/core/true/xor_spec.rb +11 -0
- data/spec/{core → core_ext}/array/element_reference_spec.rb +0 -0
- data/spec/{core → core_ext}/array/equal_value_spec.rb +0 -0
- data/spec/{core → core_ext}/array/fill_spec.rb +0 -0
- data/spec/{core → core_ext}/array/reduce_spec.rb +0 -0
- data/spec/core_ext/basic_object/send_spec.rb +3 -3
- data/spec/{core → core_ext}/boolean/singleton_class_spec.rb +0 -0
- data/spec/{core → core_ext}/boolean/to_json_spec.rb +0 -0
- data/spec/core_ext/class/_inherited_spec.rb +3 -3
- data/spec/core_ext/class/proc_methods_spec.rb +2 -2
- data/spec/core_ext/class/singleton_methods_spec.rb +8 -8
- data/spec/core_ext/method_missing_spec.rb +3 -3
- data/spec/core_ext/native/method_missing_spec.rb +3 -2
- data/spec/core_ext/native/to_native_spec.rb +3 -2
- data/spec/{core → core_ext}/nil/to_json_spec.rb +0 -0
- data/spec/date.rb +0 -0
- data/spec/fileutils.rb +0 -0
- data/spec/filters/ancestors.rb +4 -0
- data/spec/filters/array_delete.rb +3 -0
- data/spec/filters/array_fetch.rb +3 -0
- data/spec/filters/array_first.rb +3 -0
- data/spec/filters/array_flatten.rb +14 -0
- data/spec/filters/array_intersection.rb +5 -0
- data/spec/filters/array_join.rb +6 -0
- data/spec/filters/array_subclasses.rb +4 -0
- data/spec/filters/block_args.rb +3 -0
- data/spec/filters/coerce_integer.rb +9 -0
- data/spec/filters/frozen.rb +4 -0
- data/spec/filters/mocks.rb +3 -0
- data/spec/filters/should_receive.rb +4 -0
- data/spec/filters/tainted.rb +7 -0
- data/spec/fixtures/class.rb +124 -0
- data/spec/fixtures/class_variables.rb +0 -0
- data/spec/fixtures/constants.rb +0 -0
- data/spec/grammar/alias_spec.rb +1 -1
- data/spec/grammar/def_spec.rb +1 -0
- data/spec/grammar/lvar_spec.rb +1 -2
- data/spec/grammar/nth_ref_spec.rb +13 -0
- data/spec/grammar/sclass_spec.rb +6 -7
- data/spec/grammar/str_spec.rb +4 -4
- data/spec/grammar/string_spec.rb +8 -0
- data/spec/grammar/xstr_spec.rb +4 -4
- data/spec/iconv.rb +0 -0
- data/spec/language/alias_spec.rb +140 -3
- data/spec/language/and_spec.rb +14 -7
- data/spec/language/array_spec.rb +57 -5
- data/spec/language/block_spec.rb +466 -49
- data/spec/language/break_spec.rb +294 -44
- data/spec/language/case_spec.rb +151 -3
- data/spec/language/class_spec.rb +196 -0
- data/spec/language/class_variable_spec.rb +56 -0
- data/spec/language/def_spec.rb +507 -4
- data/spec/language/defined_spec.rb +19 -7
- data/spec/language/ensure_spec.rb +26 -39
- data/spec/language/execution_spec.rb +15 -0
- data/spec/language/fixtures/array.rb +11 -0
- data/spec/language/fixtures/block.rb +57 -0
- data/spec/language/fixtures/break.rb +240 -0
- data/spec/language/fixtures/ensure.rb +72 -0
- data/spec/language/fixtures/literal_lambda.rb +7 -0
- data/spec/language/fixtures/metaclass.rb +33 -0
- data/spec/language/fixtures/module.rb +24 -0
- data/spec/language/fixtures/next.rb +78 -12
- data/spec/language/fixtures/return.rb +118 -0
- data/spec/language/fixtures/send.rb +110 -0
- data/spec/language/fixtures/send_1.9.rb +22 -0
- data/spec/language/fixtures/super.rb +308 -0
- data/spec/language/fixtures/variables.rb +58 -0
- data/spec/language/fixtures/yield.rb +5 -0
- data/spec/language/for_spec.rb +192 -0
- data/spec/language/hash_spec.rb +29 -5
- data/spec/language/if_spec.rb +90 -9
- data/spec/language/literal_lambda_spec.rb +1 -47
- data/spec/language/loop_spec.rb +39 -2
- data/spec/language/metaclass_spec.rb +151 -5
- data/spec/language/module_spec.rb +56 -0
- data/spec/language/next_spec.rb +370 -12
- data/spec/language/not_spec.rb +55 -0
- data/spec/language/numbers_spec.rb +56 -0
- data/spec/language/or_spec.rb +31 -3
- data/spec/language/order_spec.rb +79 -0
- data/spec/language/precedence_spec.rb +483 -0
- data/spec/language/proc_spec.rb +249 -21
- data/spec/language/redo_spec.rb +67 -0
- data/spec/language/rescue_spec.rb +121 -0
- data/spec/language/retry_spec.rb +56 -0
- data/spec/language/return_spec.rb +281 -0
- data/spec/language/send_spec.rb +141 -48
- data/spec/language/singleton_class_spec.rb +1 -1
- data/spec/language/string_spec.rb +11 -0
- data/spec/language/super_spec.rb +213 -133
- data/spec/language/symbol_spec.rb +2 -1
- data/spec/language/undef_spec.rb +3 -1
- data/spec/language/unless_spec.rb +6 -2
- data/spec/language/until_spec.rb +102 -3
- data/spec/language/variables_spec.rb +1212 -16
- data/spec/language/versions/array_1.9.rb +39 -0
- data/spec/language/versions/case_1.9.rb +20 -0
- data/spec/language/versions/hash_1.9.rb +18 -0
- data/spec/language/versions/literal_lambda_1.9.rb +143 -0
- data/spec/language/versions/not_1.9.rb +22 -0
- data/spec/language/versions/send_1.9.rb +241 -0
- data/spec/language/versions/symbol_1.9.rb +15 -0
- data/spec/language/versions/variables_1.9.rb +8 -0
- data/spec/language/while_spec.rb +70 -5
- data/spec/language/yield_spec.rb +32 -6
- data/spec/mspec/guards/block_device.rb +0 -0
- data/spec/mspec/guards/endian.rb +0 -0
- data/spec/mspec/helpers/environment.rb +0 -0
- data/spec/mspec/helpers/language_version.rb +0 -0
- data/spec/mspec/helpers/tmp.rb +0 -0
- data/spec/ospec/filter.rb +32 -0
- data/spec/ospec/main.rb.erb +18 -0
- data/spec/ospec/phantom.rb +97 -0
- data/spec/ospec/runner.rb +95 -0
- data/spec/ospec/sprockets.js +40 -0
- data/spec/pp.rb +3 -0
- data/spec/rbconfig.rb +5 -0
- data/spec/spec_helper.rb +53 -26
- data/spec/yaml.rb +0 -0
- metadata +275 -31
- data/config.ru +0 -8
- data/lib/opal/processor.rb +0 -47
- data/lib/opal/scope.rb +0 -236
- data/lib/opal/server.rb +0 -94
- data/spec/core/boolean/and_spec.rb +0 -17
- data/spec/core/boolean/inspect_spec.rb +0 -9
- data/spec/core/boolean/or_spec.rb +0 -17
- data/spec/core/boolean/to_s_spec.rb +0 -9
- data/spec/core/boolean/xor_spec.rb +0 -17
@@ -1,31 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
b = ['a', 'b', 'c']
|
5
|
-
a.replace(b).should equal(a)
|
6
|
-
a.should == b
|
7
|
-
a.should_not equal(b)
|
8
|
-
|
9
|
-
a.replace([4] * 10)
|
10
|
-
a.should == [4] * 10
|
11
|
-
|
12
|
-
a.replace([])
|
13
|
-
a.should == []
|
14
|
-
end
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
require File.expand_path('../shared/replace', __FILE__)
|
15
4
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
ary.replace(other).should equal(ary)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "does not make self dependent to the original array" do
|
23
|
-
ary = [1, 2, 3]
|
24
|
-
other = [:a, :b, :c]
|
25
|
-
ary.replace(other)
|
26
|
-
ary.should == [:a, :b, :c]
|
27
|
-
ary << :d
|
28
|
-
ary.should == [:a, :b, :c, :d]
|
29
|
-
other.should == [:a, :b, :c]
|
5
|
+
describe "Array#replace" do
|
6
|
+
pending do
|
7
|
+
it_behaves_like(:array_replace, :replace)
|
30
8
|
end
|
31
|
-
end
|
9
|
+
end
|
@@ -1,3 +1,11 @@
|
|
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
|
+
|
5
|
+
# Modifying a collection while the contents are being iterated
|
6
|
+
# gives undefined behavior. See
|
7
|
+
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/23633
|
8
|
+
|
1
9
|
describe "Array#reverse_each" do
|
2
10
|
before :each do
|
3
11
|
ScratchPad.record []
|
@@ -12,4 +20,20 @@ describe "Array#reverse_each" do
|
|
12
20
|
a = [:a, :b, :c]
|
13
21
|
a.reverse_each { |x| }.should equal(a)
|
14
22
|
end
|
15
|
-
|
23
|
+
|
24
|
+
pending "yields only the top level element of an empty recursive arrays" do
|
25
|
+
empty = ArraySpecs.empty_recursive_array
|
26
|
+
empty.reverse_each { |i| ScratchPad << i }
|
27
|
+
ScratchPad.recorded.should == [empty]
|
28
|
+
end
|
29
|
+
|
30
|
+
pending "yields only the top level element of a recursive array" do
|
31
|
+
array = ArraySpecs.recursive_array
|
32
|
+
array.reverse_each { |i| ScratchPad << i }
|
33
|
+
ScratchPad.recorded.should == [array, array, array, array, array, 3.0, 'two', 1]
|
34
|
+
end
|
35
|
+
|
36
|
+
pending do
|
37
|
+
it_behaves_like :enumeratorize, :reverse_each
|
38
|
+
end
|
39
|
+
end
|
@@ -1,6 +1,58 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
|
1
4
|
describe "Array#reverse" do
|
2
5
|
it "returns a new array with the elements in reverse order" do
|
3
6
|
[].reverse.should == []
|
4
7
|
[1, 3, 5, 2].reverse.should == [2, 5, 3, 1]
|
5
8
|
end
|
6
|
-
|
9
|
+
|
10
|
+
pending "properly handles recursive arrays" do
|
11
|
+
empty = ArraySpecs.empty_recursive_array
|
12
|
+
empty.reverse.should == empty
|
13
|
+
|
14
|
+
array = ArraySpecs.recursive_array
|
15
|
+
array.reverse.should == [array, array, array, array, array, 3.0, 'two', 1]
|
16
|
+
end
|
17
|
+
|
18
|
+
ruby_version_is "" ... "1.9.3" do
|
19
|
+
pending "returns subclass instance on Array subclasses" do
|
20
|
+
ArraySpecs::MyArray[1, 2, 3].reverse.should be_kind_of(ArraySpecs::MyArray)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
ruby_version_is "1.9.3" do
|
25
|
+
it "does not return subclass instance on Array subclasses" do
|
26
|
+
ArraySpecs::MyArray[1, 2, 3].reverse.should be_kind_of(Array)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "Array#reverse!" do
|
32
|
+
pending "reverses the elements in place" do
|
33
|
+
a = [6, 3, 4, 2, 1]
|
34
|
+
a.reverse!.should equal(a)
|
35
|
+
a.should == [1, 2, 4, 3, 6]
|
36
|
+
[].reverse!.should == []
|
37
|
+
end
|
38
|
+
|
39
|
+
pending "properly handles recursive arrays" do
|
40
|
+
empty = ArraySpecs.empty_recursive_array
|
41
|
+
empty.reverse!.should == [empty]
|
42
|
+
|
43
|
+
array = ArraySpecs.recursive_array
|
44
|
+
array.reverse!.should == [array, array, array, array, array, 3.0, 'two', 1]
|
45
|
+
end
|
46
|
+
|
47
|
+
ruby_version_is "" ... "1.9" do
|
48
|
+
it "raises a TypeError on a frozen array" do
|
49
|
+
lambda { ArraySpecs.frozen_array.reverse! }.should raise_error(TypeError)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
ruby_version_is "1.9" do
|
54
|
+
it "raises a RuntimeError on a frozen array" do
|
55
|
+
lambda { ArraySpecs.frozen_array.reverse! }.should raise_error(RuntimeError)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -1,6 +1,22 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
|
4
|
+
# Modifying a collection while the contents are being iterated
|
5
|
+
# gives undefined behavior. See
|
6
|
+
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/23633
|
7
|
+
|
1
8
|
describe "Array#rindex" do
|
2
|
-
|
3
|
-
|
9
|
+
pending "returns the first index backwards from the end where element == to object" do
|
10
|
+
key = 3
|
11
|
+
uno = mock('one')
|
12
|
+
dos = mock('two')
|
13
|
+
tres = mock('three')
|
14
|
+
tres.should_receive(:==).any_number_of_times.and_return(false)
|
15
|
+
dos.should_receive(:==).any_number_of_times.and_return(true)
|
16
|
+
uno.should_not_receive(:==)
|
17
|
+
ary = [uno, dos, tres]
|
18
|
+
|
19
|
+
ary.rindex(key).should == 1
|
4
20
|
end
|
5
21
|
|
6
22
|
it "returns size-1 if last element == to object" do
|
@@ -15,7 +31,41 @@ describe "Array#rindex" do
|
|
15
31
|
[1, 1, 3, 2, 1, 3].rindex(4).should == nil
|
16
32
|
end
|
17
33
|
|
18
|
-
|
19
|
-
|
34
|
+
pending "properly handles empty recursive arrays" do
|
35
|
+
empty = ArraySpecs.empty_recursive_array
|
36
|
+
empty.rindex(empty).should == 0
|
37
|
+
empty.rindex(1).should be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
pending "properly handles recursive arrays" do
|
41
|
+
array = ArraySpecs.recursive_array
|
42
|
+
array.rindex(1).should == 0
|
43
|
+
array.rindex(array).should == 7
|
44
|
+
end
|
45
|
+
|
46
|
+
ruby_version_is "1.8.7" do
|
47
|
+
it "accepts a block instead of an argument" do
|
48
|
+
[4, 2, 1, 5, 1, 3].rindex { |x| x < 2 }.should == 4
|
49
|
+
end
|
50
|
+
|
51
|
+
it "ignore the block if there is an argument" do
|
52
|
+
[4, 2, 1, 5, 1, 3].rindex(5) { |x| x < 2 }.should == 3
|
53
|
+
end
|
54
|
+
|
55
|
+
it "rechecks the array size during iteration" do
|
56
|
+
ary = [4, 2, 1, 5, 1, 3]
|
57
|
+
seen = []
|
58
|
+
ary.rindex { |x| seen << x; ary.clear; false }
|
59
|
+
|
60
|
+
seen.should == [3]
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "given no argument and no block" do
|
64
|
+
it "produces an Enumerator" do
|
65
|
+
enum = [4, 2, 1, 5, 1, 3].rindex
|
66
|
+
enum.should be_kind_of(enumerator_class)
|
67
|
+
enum.each { |x| x < 2 }.should == 4
|
68
|
+
end
|
69
|
+
end
|
20
70
|
end
|
21
|
-
end
|
71
|
+
end
|
@@ -1,13 +1,40 @@
|
|
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
|
+
require File.expand_path('../shared/keep_if', __FILE__)
|
5
|
+
|
1
6
|
describe "Array#select" do
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
7
|
+
pending do
|
8
|
+
it_behaves_like :enumeratorize, :select
|
9
|
+
end
|
10
|
+
|
11
|
+
pending "returns a new array of elements for which block is true" do
|
12
|
+
[1, 3, 4, 5, 6, 9].select { |i| i % ((i + 1) / 2) == 0}.should == [1, 4, 6]
|
13
|
+
end
|
14
|
+
|
15
|
+
it "does not return subclass instance on Array subclasses" do
|
16
|
+
ArraySpecs::MyArray[1, 2, 3].select { true }.should be_kind_of(Array)
|
17
|
+
end
|
18
|
+
|
19
|
+
pending "properly handles recursive arrays" do
|
20
|
+
empty = ArraySpecs.empty_recursive_array
|
21
|
+
empty.select { true }.should == empty
|
22
|
+
empty.select { false }.should == []
|
23
|
+
|
24
|
+
array = ArraySpecs.recursive_array
|
25
|
+
array.select { true }.should == [1, 'two', 3.0, array, array, array, array, array]
|
26
|
+
array.select { false }.should == []
|
6
27
|
end
|
7
28
|
end
|
8
29
|
|
9
|
-
|
10
|
-
|
11
|
-
|
30
|
+
ruby_version_is "1.9" do
|
31
|
+
describe "Array#select!" do
|
32
|
+
it "returns nil if no changes were made in the array" do
|
33
|
+
[1, 2, 3].select! { true }.should be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
pending do
|
37
|
+
it_behaves_like :keep_if, :select!
|
38
|
+
end
|
12
39
|
end
|
13
|
-
end
|
40
|
+
end
|
File without changes
|
@@ -0,0 +1,12 @@
|
|
1
|
+
describe :enumeratorize, :shared => true do
|
2
|
+
ruby_version_is '' ... '1.8.7' do
|
3
|
+
it "raises a LocalJumpError if no block given" do
|
4
|
+
lambda{ [1,2].send(@method) }.should raise_error(LocalJumpError)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
ruby_version_is '1.8.7' do
|
8
|
+
it "returns an Enumerator if no block given" do
|
9
|
+
[1,2].send(@method).should be_an_instance_of(enumerator_class)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
describe :array_eql, :shared => true do
|
2
|
+
it "returns true if other is the same array" do
|
3
|
+
a = [1]
|
4
|
+
a.send(@method, a).should be_true
|
5
|
+
end
|
6
|
+
|
7
|
+
it "returns true if corresponding elements are #eql?" do
|
8
|
+
[].send(@method, []).should be_true
|
9
|
+
[1, 2, 3, 4].send(@method, [1, 2, 3, 4]).should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns false if other is shorter than self" do
|
13
|
+
[1, 2, 3, 4].send(@method, [1, 2, 3]).should be_false
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns false if other is longer than self" do
|
17
|
+
[1, 2, 3, 4].send(@method, [1, 2, 3, 4, 5]).should be_false
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns false immediately when sizes of the arrays differ" do
|
21
|
+
obj = mock('1')
|
22
|
+
obj.should_not_receive(@method)
|
23
|
+
|
24
|
+
[] .send(@method, [obj] ).should be_false
|
25
|
+
[obj] .send(@method, [] ).should be_false
|
26
|
+
end
|
27
|
+
|
28
|
+
ruby_bug "ruby-core #1448", "1.9.1" do
|
29
|
+
it "handles well recursive arrays" do
|
30
|
+
a = ArraySpecs.empty_recursive_array
|
31
|
+
a .send(@method, [a] ).should be_true
|
32
|
+
a .send(@method, [[a]] ).should be_true
|
33
|
+
[a] .send(@method, a ).should be_true
|
34
|
+
[[a]] .send(@method, a ).should be_true
|
35
|
+
# These may be surprising, but no difference can be
|
36
|
+
# found between these arrays, so they are ==.
|
37
|
+
# There is no "path" that will lead to a difference
|
38
|
+
# (contrary to other examples below)
|
39
|
+
|
40
|
+
a2 = ArraySpecs.empty_recursive_array
|
41
|
+
a .send(@method, a2 ).should be_true
|
42
|
+
a .send(@method, [a2] ).should be_true
|
43
|
+
a .send(@method, [[a2]] ).should be_true
|
44
|
+
[a] .send(@method, a2 ).should be_true
|
45
|
+
[[a]] .send(@method, a2 ).should be_true
|
46
|
+
|
47
|
+
back = []
|
48
|
+
forth = [back]; back << forth;
|
49
|
+
back .send(@method, a ).should be_true
|
50
|
+
|
51
|
+
x = []; x << x << x
|
52
|
+
x .send(@method, a ).should be_false # since x.size != a.size
|
53
|
+
x .send(@method, [a, a] ).should be_false # since x[0].size != [a, a][0].size
|
54
|
+
x .send(@method, [x, a] ).should be_false # since x[1].size != [x, a][1].size
|
55
|
+
[x, a] .send(@method, [a, x] ).should be_false # etc...
|
56
|
+
x .send(@method, [x, x] ).should be_true
|
57
|
+
x .send(@method, [[x, x], [x, x]] ).should be_true
|
58
|
+
|
59
|
+
tree = [];
|
60
|
+
branch = []; branch << tree << tree; tree << branch
|
61
|
+
tree2 = [];
|
62
|
+
branch2 = []; branch2 << tree2 << tree2; tree2 << branch2
|
63
|
+
forest = [tree, branch, :bird, a]; forest << forest
|
64
|
+
forest2 = [tree2, branch2, :bird, a2]; forest2 << forest2
|
65
|
+
|
66
|
+
forest .send(@method, forest2 ).should be_true
|
67
|
+
forest .send(@method, [tree2, branch, :bird, a, forest2]).should be_true
|
68
|
+
|
69
|
+
diffforest = [branch2, tree2, :bird, a2]; diffforest << forest2
|
70
|
+
forest .send(@method, diffforest ).should be_false # since forest[0].size == 1 != 3 == diffforest[0]
|
71
|
+
forest .send(@method, [nil] ).should be_false
|
72
|
+
forest .send(@method, [forest] ).should be_false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "does not call #to_ary on its argument" do
|
77
|
+
obj = mock('to_ary')
|
78
|
+
obj.should_not_receive(:to_ary)
|
79
|
+
|
80
|
+
[1, 2, 3].send(@method, obj).should be_false
|
81
|
+
end
|
82
|
+
|
83
|
+
it "does not call #to_ary on Array subclasses" do
|
84
|
+
ary = ArraySpecs::ToAryArray[5, 6, 7]
|
85
|
+
ary.should_not_receive(:to_ary)
|
86
|
+
[5, 6, 7].send(@method, ary).should be_true
|
87
|
+
end
|
88
|
+
|
89
|
+
it "ignores array class differences" do
|
90
|
+
ArraySpecs::MyArray[1, 2, 3].send(@method, [1, 2, 3]).should be_true
|
91
|
+
ArraySpecs::MyArray[1, 2, 3].send(@method, ArraySpecs::MyArray[1, 2, 3]).should be_true
|
92
|
+
[1, 2, 3].send(@method, ArraySpecs::MyArray[1, 2, 3]).should be_true
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
describe :array_index, :shared => true do
|
2
|
+
it "returns the index of the first element == to object" do
|
3
|
+
x = mock('3')
|
4
|
+
def x.==(obj) 3 == obj; end
|
5
|
+
|
6
|
+
[2, x, 3, 1, 3, 1].send(@method, 3).should == 1
|
7
|
+
[2, 3.0, 3, x, 1, 3, 1].send(@method, x).should == 1
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns 0 if first element == to object" do
|
11
|
+
[2, 1, 3, 2, 5].send(@method, 2).should == 0
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns size-1 if only last element == to object" do
|
15
|
+
[2, 1, 3, 1, 5].send(@method, 5).should == 4
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns nil if no element == to object" do
|
19
|
+
[2, 1, 1, 1, 1].send(@method, 3).should == nil
|
20
|
+
end
|
21
|
+
|
22
|
+
ruby_version_is "1.8.7" do
|
23
|
+
it "accepts a block instead of an argument" do
|
24
|
+
[4, 2, 1, 5, 1, 3].send(@method) {|x| x < 2}.should == 2
|
25
|
+
end
|
26
|
+
|
27
|
+
it "ignore the block if there is an argument" do
|
28
|
+
[4, 2, 1, 5, 1, 3].send(@method, 5) {|x| x < 2}.should == 3
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "given no argument and no block" do
|
32
|
+
it "produces an Enumerator" do
|
33
|
+
[].send(@method).should be_kind_of(enumerator_class)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -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#shift" do
|
2
5
|
it "removes and returns the first element" do
|
3
6
|
a = [5, 1, 1, 5, 4]
|
@@ -13,39 +16,145 @@ describe "Array#shift" do
|
|
13
16
|
a.should == []
|
14
17
|
end
|
15
18
|
|
16
|
-
it "returns nil
|
19
|
+
it "returns nil when the array is empty" do
|
17
20
|
[].shift.should == nil
|
18
21
|
end
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
+
pending "properly handles recursive arrays" do
|
24
|
+
empty = ArraySpecs.empty_recursive_array
|
25
|
+
empty.shift.should == []
|
26
|
+
empty.should == []
|
23
27
|
|
24
|
-
|
25
|
-
|
28
|
+
array = ArraySpecs.recursive_array
|
29
|
+
array.shift.should == 1
|
30
|
+
array[0..2].should == ['two', 3.0, array]
|
31
|
+
end
|
26
32
|
|
27
|
-
|
28
|
-
|
33
|
+
ruby_version_is "" ... "1.9" do
|
34
|
+
it "raises a TypeError on a frozen array" do
|
35
|
+
lambda { ArraySpecs.frozen_array.shift }.should raise_error(TypeError)
|
36
|
+
end
|
37
|
+
it "raises a TypeError on an empty frozen array" do
|
38
|
+
lambda { ArraySpecs.empty_frozen_array.shift }.should raise_error(TypeError)
|
39
|
+
end
|
40
|
+
end
|
29
41
|
|
30
|
-
|
31
|
-
|
42
|
+
ruby_version_is "1.9" do
|
43
|
+
it "raises a RuntimeError on a frozen array" do
|
44
|
+
lambda { ArraySpecs.frozen_array.shift }.should raise_error(RuntimeError)
|
45
|
+
end
|
46
|
+
it "raises a RuntimeError on an empty frozen array" do
|
47
|
+
lambda { ArraySpecs.empty_frozen_array.shift }.should raise_error(RuntimeError)
|
48
|
+
end
|
49
|
+
end
|
32
50
|
|
33
|
-
|
34
|
-
|
51
|
+
ruby_version_is '' ... '1.8.7' do
|
52
|
+
it "raises an ArgumentError if passed an argument" do
|
53
|
+
lambda{ [1, 2].shift(1) }.should raise_error(ArgumentError)
|
35
54
|
end
|
55
|
+
end
|
36
56
|
|
37
|
-
|
38
|
-
|
57
|
+
describe "passed a number n as an argument" do
|
58
|
+
ruby_version_is '1.8.7' do
|
59
|
+
it "removes and returns an array with the first n element of the array" do
|
60
|
+
a = [1, 2, 3, 4, 5, 6]
|
39
61
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
62
|
+
a.shift(0).should == []
|
63
|
+
a.should == [1, 2, 3, 4, 5, 6]
|
64
|
+
|
65
|
+
a.shift(1).should == [1]
|
66
|
+
a.should == [2, 3, 4, 5, 6]
|
67
|
+
|
68
|
+
a.shift(2).should == [2, 3]
|
69
|
+
a.should == [4, 5, 6]
|
70
|
+
|
71
|
+
a.shift(3).should == [4, 5, 6]
|
72
|
+
a.should == []
|
73
|
+
end
|
74
|
+
|
75
|
+
it "does not corrupt the array when shift without arguments is followed by shift with an argument" do
|
76
|
+
a = [1, 2, 3, 4, 5]
|
77
|
+
|
78
|
+
a.shift.should == 1
|
79
|
+
a.shift(3).should == [2, 3, 4]
|
80
|
+
a.should == [5]
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns a new empty array if there are no more elements" do
|
84
|
+
a = []
|
85
|
+
popped1 = a.shift(1)
|
86
|
+
popped1.should == []
|
87
|
+
a.should == []
|
88
|
+
|
89
|
+
popped2 = a.shift(2)
|
90
|
+
popped2.should == []
|
91
|
+
a.should == []
|
92
|
+
|
93
|
+
popped1.should_not equal(popped2)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "returns whole elements if n exceeds size of the array" do
|
97
|
+
a = [1, 2, 3, 4, 5]
|
98
|
+
a.shift(6).should == [1, 2, 3, 4, 5]
|
99
|
+
a.should == []
|
100
|
+
end
|
101
|
+
|
102
|
+
it "does not return self even when it returns whole elements" do
|
103
|
+
a = [1, 2, 3, 4, 5]
|
104
|
+
a.shift(5).should_not equal(a)
|
105
|
+
|
106
|
+
a = [1, 2, 3, 4, 5]
|
107
|
+
a.shift(6).should_not equal(a)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "raises an ArgumentError if n is negative" do
|
111
|
+
lambda{ [1, 2, 3].shift(-1) }.should raise_error(ArgumentError)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "tries to convert n to an Integer using #to_int" do
|
115
|
+
a = [1, 2, 3, 4]
|
116
|
+
a.shift(2.3).should == [1, 2]
|
117
|
+
|
118
|
+
obj = mock('to_int')
|
119
|
+
obj.should_receive(:to_int).and_return(2)
|
120
|
+
a.should == [3, 4]
|
121
|
+
a.shift(obj).should == [3, 4]
|
122
|
+
a.should == []
|
123
|
+
end
|
124
|
+
|
125
|
+
it "raises a TypeError when the passed n can be coerced to Integer" do
|
126
|
+
lambda{ [1, 2].shift("cat") }.should raise_error(TypeError)
|
127
|
+
lambda{ [1, 2].shift(nil) }.should raise_error(TypeError)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "raises an ArgumentError if more arguments are passed" do
|
131
|
+
lambda{ [1, 2].shift(1, 2) }.should raise_error(ArgumentError)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "does not return subclass instances with Array subclass" do
|
135
|
+
ArraySpecs::MyArray[1, 2, 3].shift(2).should be_kind_of(Array)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "returns an untainted array even if the array is tainted" do
|
139
|
+
ary = [1, 2].taint
|
140
|
+
ary.shift(2).tainted?.should be_false
|
141
|
+
ary.shift(0).tainted?.should be_false
|
142
|
+
end
|
143
|
+
|
144
|
+
it "keeps taint status" do
|
145
|
+
a = [1, 2].taint
|
146
|
+
a.shift(2)
|
147
|
+
a.tainted?.should be_true
|
148
|
+
a.shift(2)
|
149
|
+
a.tainted?.should be_true
|
150
|
+
end
|
44
151
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
152
|
+
ruby_version_is '' ... '1.9' do
|
153
|
+
it "raises a TypeError on a frozen array" do
|
154
|
+
lambda { ArraySpecs.frozen_array.shift(2) }.should raise_error(TypeError)
|
155
|
+
lambda { ArraySpecs.frozen_array.shift(0) }.should raise_error(TypeError)
|
156
|
+
end
|
157
|
+
end
|
49
158
|
end
|
50
159
|
end
|
51
|
-
end
|
160
|
+
end
|