opal 0.3.41 → 0.3.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,21 +1,29 @@
|
|
1
|
-
|
2
|
-
it "returns the first specified number of elements" do
|
3
|
-
[1, 2, 3].take(2).should == [1, 2]
|
4
|
-
end
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
ruby_version_is "1.8.7" do
|
4
|
+
describe "Array#take" do
|
5
|
+
it "returns the first specified number of elements" do
|
6
|
+
[1, 2, 3].take(2).should == [1, 2]
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
it "returns all elements when the argument is greater than the Array size" do
|
10
|
+
[1, 2].take(99).should == [1, 2]
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
it "returns all elements when the argument is less than the Array size" do
|
14
|
+
[1, 2].take(4).should == [1, 2]
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns an empty Array when passed zero" do
|
18
|
+
[1].take(0).should == []
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns an empty Array when called on an empty Array" do
|
22
|
+
[].take(3).should == []
|
23
|
+
end
|
17
24
|
|
18
|
-
|
19
|
-
|
25
|
+
it "raises an ArgumentError when the argument is negative" do
|
26
|
+
lambda{ [1].take(-3) }.should raise_error(ArgumentError)
|
27
|
+
end
|
20
28
|
end
|
21
|
-
end
|
29
|
+
end
|
@@ -1,13 +1,17 @@
|
|
1
|
-
|
2
|
-
it "returns all elements until the block returns false" do
|
3
|
-
[1, 2, 3].take_while{ |element| element < 3 }.should == [1, 2]
|
4
|
-
end
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
ruby_version_is "1.8.7" do
|
4
|
+
describe "Array#take_while" do
|
5
|
+
it "returns all elements until the block returns false" do
|
6
|
+
[1, 2, 3].take_while{ |element| element < 3 }.should == [1, 2]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns all elements until the block returns nil" do
|
10
|
+
[1, 2, nil, 4].take_while{ |element| element }.should == [1, 2]
|
11
|
+
end
|
9
12
|
|
10
|
-
|
11
|
-
|
13
|
+
it "returns all elements until the block returns false" do
|
14
|
+
[1, 2, false, 4].take_while{ |element| element }.should == [1, 2]
|
15
|
+
end
|
12
16
|
end
|
13
|
-
end
|
17
|
+
end
|
@@ -1,7 +1,24 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
|
1
4
|
describe "Array#to_a" do
|
2
5
|
it "returns self" do
|
3
6
|
a = [1, 2, 3]
|
4
7
|
a.to_a.should == [1, 2, 3]
|
5
8
|
a.should equal(a.to_a)
|
6
9
|
end
|
7
|
-
|
10
|
+
|
11
|
+
pending "does not return subclass instance on Array subclasses" do
|
12
|
+
e = ArraySpecs::MyArray.new(1, 2)
|
13
|
+
e.to_a.should be_an_instance_of(Array)
|
14
|
+
e.to_a.should == [1, 2]
|
15
|
+
end
|
16
|
+
|
17
|
+
pending "properly handles recursive arrays" do
|
18
|
+
empty = ArraySpecs.empty_recursive_array
|
19
|
+
empty.to_a.should == empty
|
20
|
+
|
21
|
+
array = ArraySpecs.recursive_array
|
22
|
+
array.to_a.should == array
|
23
|
+
end
|
24
|
+
end
|
@@ -1,6 +1,20 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
|
1
4
|
describe "Array#to_ary" do
|
2
5
|
it "returns self" do
|
3
6
|
a = [1, 2, 3]
|
4
7
|
a.should equal(a.to_ary)
|
8
|
+
a = ArraySpecs::MyArray[1, 2, 3]
|
9
|
+
a.should equal(a.to_ary)
|
10
|
+
end
|
11
|
+
|
12
|
+
pending "properly handles recursive arrays" do
|
13
|
+
empty = ArraySpecs.empty_recursive_array
|
14
|
+
empty.to_ary.should == empty
|
15
|
+
|
16
|
+
array = ArraySpecs.recursive_array
|
17
|
+
array.to_ary.should == array
|
5
18
|
end
|
6
|
-
|
19
|
+
|
20
|
+
end
|
@@ -3,13 +3,50 @@ require File.expand_path('../fixtures/classes', __FILE__)
|
|
3
3
|
|
4
4
|
ruby_version_is "1.9" do
|
5
5
|
describe "Array.try_convert" do
|
6
|
-
it "returns the argument if it's
|
6
|
+
it "returns the argument if it's an Array" do
|
7
7
|
x = Array.new
|
8
8
|
Array.try_convert(x).should equal(x)
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
pending "returns the argument if it's a kind of Array" do
|
12
|
+
x = ArraySpecs::MyArray[]
|
13
|
+
Array.try_convert(x).should equal(x)
|
14
|
+
end
|
15
|
+
|
16
|
+
pending "returns nil when the argument does not respond to #to_ary" do
|
12
17
|
Array.try_convert(Object.new).should be_nil
|
13
18
|
end
|
19
|
+
|
20
|
+
pending "sends #to_ary to the argument and returns the result if it's nil" do
|
21
|
+
obj = mock("to_ary")
|
22
|
+
obj.should_receive(:to_ary).and_return(nil)
|
23
|
+
Array.try_convert(obj).should be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
pending "sends #to_ary to the argument and returns the result if it's an Array" do
|
27
|
+
x = Array.new
|
28
|
+
obj = mock("to_ary")
|
29
|
+
obj.should_receive(:to_ary).and_return(x)
|
30
|
+
Array.try_convert(obj).should equal(x)
|
31
|
+
end
|
32
|
+
|
33
|
+
pending "sends #to_ary to the argument and returns the result if it's a kind of Array" do
|
34
|
+
x = ArraySpecs::MyArray[]
|
35
|
+
obj = mock("to_ary")
|
36
|
+
obj.should_receive(:to_ary).and_return(x)
|
37
|
+
Array.try_convert(obj).should equal(x)
|
38
|
+
end
|
39
|
+
|
40
|
+
pending "sends #to_ary to the argument and raises TypeError if it's not a kind of Array" do
|
41
|
+
obj = mock("to_ary")
|
42
|
+
obj.should_receive(:to_ary).and_return(Object.new)
|
43
|
+
lambda { Array.try_convert obj }.should raise_error(TypeError)
|
44
|
+
end
|
45
|
+
|
46
|
+
pending "does not rescue exceptions raised by #to_ary" do
|
47
|
+
obj = mock("to_ary")
|
48
|
+
obj.should_receive(:to_ary).and_raise(RuntimeError)
|
49
|
+
lambda { Array.try_convert obj }.should raise_error(RuntimeError)
|
50
|
+
end
|
14
51
|
end
|
15
52
|
end
|
@@ -1,10 +1,102 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
|
1
4
|
describe "Array#uniq" do
|
2
5
|
it "returns an array with no duplicates" do
|
3
6
|
["a", "a", "b", "b", "c"].uniq.should == ["a", "b", "c"]
|
4
7
|
end
|
5
8
|
|
6
|
-
|
7
|
-
|
9
|
+
ruby_bug "#", "1.8.6.277" do
|
10
|
+
pending "properly handles recursive arrays" do
|
11
|
+
empty = ArraySpecs.empty_recursive_array
|
12
|
+
empty.uniq.should == [empty]
|
13
|
+
|
14
|
+
array = ArraySpecs.recursive_array
|
15
|
+
array.uniq.should == [1, 'two', 3.0, array]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
pending "uses eql? semantics" do
|
20
|
+
[1.0, 1].uniq.should == [1.0, 1]
|
21
|
+
end
|
22
|
+
|
23
|
+
it "compares elements first with hash" do
|
24
|
+
# Can't use should_receive because it uses hash internally
|
25
|
+
x = mock('0')
|
26
|
+
def x.hash() 0 end
|
27
|
+
y = mock('0')
|
28
|
+
def y.hash() 0 end
|
29
|
+
|
30
|
+
[x, y].uniq.should == [x, y]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "does not compare elements with different hash codes via eql?" do
|
34
|
+
# Can't use should_receive because it uses hash and eql? internally
|
35
|
+
x = mock('0')
|
36
|
+
def x.eql?(o) raise("Shouldn't receive eql?") end
|
37
|
+
y = mock('1')
|
38
|
+
def y.eql?(o) raise("Shouldn't receive eql?") end
|
39
|
+
|
40
|
+
def x.hash() 0 end
|
41
|
+
def y.hash() 1 end
|
42
|
+
|
43
|
+
[x, y].uniq.should == [x, y]
|
44
|
+
end
|
45
|
+
|
46
|
+
pending "compares elements with matching hash codes with #eql?" do
|
47
|
+
# Can't use should_receive because it uses hash and eql? internally
|
48
|
+
a = Array.new(2) do
|
49
|
+
obj = mock('0')
|
50
|
+
|
51
|
+
def obj.hash()
|
52
|
+
# It's undefined whether the impl does a[0].eql?(a[1]) or
|
53
|
+
# a[1].eql?(a[0]) so we taint both.
|
54
|
+
def self.eql?(o) taint; o.taint; false; end
|
55
|
+
return 0
|
56
|
+
end
|
57
|
+
|
58
|
+
obj
|
59
|
+
end
|
60
|
+
|
61
|
+
a.uniq.should == a
|
62
|
+
a[0].tainted?.should == true
|
63
|
+
a[1].tainted?.should == true
|
64
|
+
|
65
|
+
a = Array.new(2) do
|
66
|
+
obj = mock('0')
|
67
|
+
|
68
|
+
def obj.hash()
|
69
|
+
# It's undefined whether the impl does a[0].eql?(a[1]) or
|
70
|
+
# a[1].eql?(a[0]) so we taint both.
|
71
|
+
def self.eql?(o) taint; o.taint; true; end
|
72
|
+
return 0
|
73
|
+
end
|
74
|
+
|
75
|
+
obj
|
76
|
+
end
|
77
|
+
|
78
|
+
a.uniq.size.should == 1
|
79
|
+
a[0].tainted?.should == true
|
80
|
+
a[1].tainted?.should == true
|
81
|
+
end
|
82
|
+
|
83
|
+
ruby_version_is "1.9" do
|
84
|
+
pending "compares elements based on the value returned from the block" do
|
85
|
+
a = [1, 2, 3, 4]
|
86
|
+
a.uniq { |x| x >= 2 ? 1 : 0 }.should == [1, 2]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
ruby_version_is "" ... "1.9.3" do
|
91
|
+
pending "returns subclass instance on Array subclasses" do
|
92
|
+
ArraySpecs::MyArray[1, 2, 3].uniq.should be_kind_of(ArraySpecs::MyArray)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
ruby_version_is "1.9.3" do
|
97
|
+
it "does not return subclass instance on Array subclasses" do
|
98
|
+
ArraySpecs::MyArray[1, 2, 3].uniq.should be_kind_of(Array)
|
99
|
+
end
|
8
100
|
end
|
9
101
|
end
|
10
102
|
|
@@ -19,4 +111,57 @@ describe "Array#uniq!" do
|
|
19
111
|
a = [ "a", "a", "b", "b", "c" ]
|
20
112
|
a.should equal(a.uniq!)
|
21
113
|
end
|
22
|
-
|
114
|
+
|
115
|
+
ruby_bug "#", "1.8.6.277" do
|
116
|
+
pending "properly handles recursive arrays" do
|
117
|
+
empty = ArraySpecs.empty_recursive_array
|
118
|
+
empty_dup = empty.dup
|
119
|
+
empty.uniq!
|
120
|
+
empty.should == empty_dup
|
121
|
+
|
122
|
+
array = ArraySpecs.recursive_array
|
123
|
+
expected = array[0..3]
|
124
|
+
array.uniq!
|
125
|
+
array.should == expected
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
it "returns nil if no changes are made to the array" do
|
130
|
+
[ "a", "b", "c" ].uniq!.should == nil
|
131
|
+
end
|
132
|
+
|
133
|
+
ruby_version_is ""..."1.9" do
|
134
|
+
it "raises a TypeError on a frozen array when the array is modified" do
|
135
|
+
dup_ary = [1, 1, 2]
|
136
|
+
dup_ary.freeze
|
137
|
+
lambda { dup_ary.uniq! }.should raise_error(TypeError)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "does not raise an exception on a frozen array when the array would not be modified" do
|
141
|
+
ArraySpecs.frozen_array.uniq!.should be_nil
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
ruby_version_is "1.9" do
|
146
|
+
pending "raises a RuntimeError on a frozen array when the array is modified" do
|
147
|
+
dup_ary = [1, 1, 2]
|
148
|
+
dup_ary.freeze
|
149
|
+
lambda { dup_ary.uniq! }.should raise_error(RuntimeError)
|
150
|
+
end
|
151
|
+
|
152
|
+
# see [ruby-core:23666]
|
153
|
+
it "raises a RuntimeError on a frozen array when the array would not be modified" do
|
154
|
+
lambda { ArraySpecs.frozen_array.uniq!}.should raise_error(RuntimeError)
|
155
|
+
lambda { ArraySpecs.empty_frozen_array.uniq!}.should raise_error(RuntimeError)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "doesn't yield to the block on a frozen array" do
|
159
|
+
lambda { ArraySpecs.frozen_array.uniq!{ raise RangeError, "shouldn't yield"}}.should raise_error(RuntimeError)
|
160
|
+
end
|
161
|
+
|
162
|
+
pending "compares elements based on the value returned from the block" do
|
163
|
+
a = [1, 2, 3, 4]
|
164
|
+
a.uniq! { |x| x >= 2 ? 1 : 0 }.should == [1, 2]
|
165
|
+
end
|
166
|
+
end
|
167
|
+
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#unshift" do
|
2
5
|
it "prepends object to the original array" do
|
3
6
|
a = [1, 2, 3]
|
@@ -26,4 +29,36 @@ describe "Array#unshift" do
|
|
26
29
|
[].unshift().should == []
|
27
30
|
[].unshift(*[]).should == []
|
28
31
|
end
|
29
|
-
|
32
|
+
|
33
|
+
pending "properly handles recursive arrays" do
|
34
|
+
empty = ArraySpecs.empty_recursive_array
|
35
|
+
empty.unshift(:new).should == [:new, empty]
|
36
|
+
|
37
|
+
array = ArraySpecs.recursive_array
|
38
|
+
array.unshift(:new)
|
39
|
+
array[0..5].should == [:new, 1, 'two', 3.0, array, array]
|
40
|
+
end
|
41
|
+
|
42
|
+
ruby_version_is "" ... "1.9" do
|
43
|
+
it "raises a TypeError on a frozen array" do
|
44
|
+
lambda { ArraySpecs.frozen_array.unshift(1) }.should raise_error(TypeError)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
ruby_version_is "1.9" do
|
49
|
+
it "raises a RuntimeError on a frozen array when the array is modified" do
|
50
|
+
lambda { ArraySpecs.frozen_array.unshift(1) }.should raise_error(RuntimeError)
|
51
|
+
end
|
52
|
+
|
53
|
+
# see [ruby-core:23666]
|
54
|
+
it "raises a RuntimeError on a frozen array when the array would not be modified" do
|
55
|
+
lambda { ArraySpecs.frozen_array.unshift }.should raise_error(RuntimeError)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
ruby_version_is ""..."1.9" do
|
60
|
+
it "does not raise an exception on a frozen array if no modification takes place" do
|
61
|
+
ArraySpecs.frozen_array.unshift.should == [1, 2, 3]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/core/array/zip_spec.rb
CHANGED
@@ -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#zip" do
|
2
5
|
it "returns an array of arrays containing corresponding elements of each array" do
|
3
6
|
[1, 2, 3, 4].zip(["a", "b", "c", "d", "e"]).should ==
|
@@ -9,6 +12,34 @@ describe "Array#zip" do
|
|
9
12
|
[[1, "a"], [2, "b"], [3, "c"], [4, "d"], [5, nil]]
|
10
13
|
end
|
11
14
|
|
15
|
+
pending "properly handles recursive arrays" do
|
16
|
+
a = []; a << a
|
17
|
+
b = [1]; b << b
|
18
|
+
|
19
|
+
a.zip(a).should == [ [a[0], a[0]] ]
|
20
|
+
a.zip(b).should == [ [a[0], b[0]] ]
|
21
|
+
b.zip(a).should == [ [b[0], a[0]], [b[1], a[1]] ]
|
22
|
+
b.zip(b).should == [ [b[0], b[0]], [b[1], b[1]] ]
|
23
|
+
end
|
24
|
+
|
25
|
+
pending "calls #to_ary to convert the argument to an Array" do
|
26
|
+
obj = mock('[3,4]')
|
27
|
+
obj.should_receive(:to_ary).and_return([3, 4])
|
28
|
+
[1, 2].zip(obj).should == [[1, 3], [2, 4]]
|
29
|
+
end
|
30
|
+
|
31
|
+
ruby_version_is "1.9.2" do
|
32
|
+
it "uses #each to extract arguments' elements when #to_ary fails" do
|
33
|
+
obj = Class.new do
|
34
|
+
def each(&b)
|
35
|
+
[3,4].each(&b)
|
36
|
+
end
|
37
|
+
end.new
|
38
|
+
|
39
|
+
[1, 2].zip(obj).should == [[1, 3], [2, 4]]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
12
43
|
it "calls block if supplied" do
|
13
44
|
values = []
|
14
45
|
[1, 2, 3, 4].zip(["a", "b", "c", "d", "e"]) { |value|
|
@@ -17,4 +48,8 @@ describe "Array#zip" do
|
|
17
48
|
|
18
49
|
values.should == [[1, "a"], [2, "b"], [3, "c"], [4, "d"]]
|
19
50
|
end
|
20
|
-
|
51
|
+
|
52
|
+
it "does not return subclass instance on Array subclasses" do
|
53
|
+
ArraySpecs::MyArray[1, 2, 3].zip(["a", "b"]).should be_kind_of(Array)
|
54
|
+
end
|
55
|
+
end
|
data/spec/core/class/new_spec.rb
CHANGED
@@ -100,12 +100,14 @@ describe "Class#new" do
|
|
100
100
|
end
|
101
101
|
|
102
102
|
it "passes the block to #initialize" do
|
103
|
-
|
104
|
-
|
105
|
-
|
103
|
+
lambda {
|
104
|
+
klass = Class.new do
|
105
|
+
def initialize(&block)
|
106
|
+
raise "no block given" unless block_given?
|
107
|
+
end
|
106
108
|
end
|
107
|
-
end
|
108
109
|
|
109
|
-
|
110
|
+
klass.new { 42 }
|
111
|
+
}.should_not raise_error(Exception)
|
110
112
|
end
|
111
|
-
end
|
113
|
+
end
|