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,9 +1,34 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
require File.expand_path('../shared/join', __FILE__)
|
4
|
+
|
1
5
|
describe "Array#join" do
|
2
|
-
|
3
|
-
|
4
|
-
|
6
|
+
it_behaves_like :array_join_with_string_separator, :join
|
7
|
+
|
8
|
+
it_behaves_like :array_join_with_default_separator, :join
|
5
9
|
|
6
10
|
it "does not separate elements when the passed separator is nil" do
|
7
11
|
[1, 2, 3].join(nil).should == '123'
|
8
12
|
end
|
9
|
-
|
13
|
+
|
14
|
+
it "calls #to_str to convert the separator to a String" do
|
15
|
+
sep = mock("separator")
|
16
|
+
sep.should_receive(:to_str).and_return(", ")
|
17
|
+
[1, 2].join(sep).should == "1, 2"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "does not call #to_str on the separator if the array is empty" do
|
21
|
+
sep = mock("separator")
|
22
|
+
sep.should_not_receive(:to_str)
|
23
|
+
[].join(sep).should == ""
|
24
|
+
end
|
25
|
+
|
26
|
+
it "raises a TypeError if the separator cannot be coerced to a String by calling #to_str" do
|
27
|
+
obj = mock("not a string")
|
28
|
+
lambda { [1, 2].join(obj) }.should raise_error(TypeError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "raises a TypeError if passed false as the separator" do
|
32
|
+
lambda { [1, 2].join(false) }.should raise_error(TypeError)
|
33
|
+
end
|
34
|
+
end
|
@@ -1,7 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
array
|
1
|
+
require File.expand_path('../shared/keep_if', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is "1.9" do
|
4
|
+
describe "Array#keep_if" do
|
5
|
+
it "returns the same array if no changes were made" do
|
6
|
+
array = [1, 2, 3]
|
7
|
+
array.keep_if { true }.should equal(array)
|
8
|
+
end
|
9
|
+
|
10
|
+
pending do
|
11
|
+
it_behaves_like :keep_if, :keep_if
|
12
|
+
end
|
6
13
|
end
|
7
|
-
end
|
14
|
+
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#last" do
|
2
5
|
it "returns the last element" do
|
3
6
|
[1, 1, 1, 1, 2].last.should == 2
|
@@ -42,6 +45,37 @@ describe "Array#last" do
|
|
42
45
|
ary.should == [1, 2, 3, 4, 5]
|
43
46
|
end
|
44
47
|
|
48
|
+
it "properly handles recursive arrays" do
|
49
|
+
empty = ArraySpecs.empty_recursive_array
|
50
|
+
empty.last.should equal(empty)
|
51
|
+
|
52
|
+
array = ArraySpecs.recursive_array
|
53
|
+
array.last.should equal(array)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "tries to convert the passed argument to an Integer usinig #to_int" do
|
57
|
+
obj = mock('to_int')
|
58
|
+
def obj.to_int; 2 ; end
|
59
|
+
obj.to_int.should == 2
|
60
|
+
[1, 2, 3, 4, 5].last(obj).should == [4, 5]
|
61
|
+
end
|
62
|
+
|
63
|
+
it "raises a TypeError if the passed argument is not numeric" do
|
64
|
+
lambda { [1,2].last(nil) }.should raise_error(TypeError)
|
65
|
+
lambda { [1,2].last("a") }.should raise_error(TypeError)
|
66
|
+
|
67
|
+
obj = mock("nonnumeric")
|
68
|
+
lambda { [1,2].last(obj) }.should raise_error(TypeError)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "does not return subclass instance on Array subclasses" do
|
72
|
+
ArraySpecs::MyArray[].last(0).should be_kind_of(Array)
|
73
|
+
ArraySpecs::MyArray[].last(2).should be_kind_of(Array)
|
74
|
+
ArraySpecs::MyArray[1, 2, 3].last(0).should be_kind_of(Array)
|
75
|
+
ArraySpecs::MyArray[1, 2, 3].last(1).should be_kind_of(Array)
|
76
|
+
ArraySpecs::MyArray[1, 2, 3].last(2).should be_kind_of(Array)
|
77
|
+
end
|
78
|
+
|
45
79
|
it "is not destructive" do
|
46
80
|
a = [1, 2, 3]
|
47
81
|
a.last
|
@@ -51,4 +85,4 @@ describe "Array#last" do
|
|
51
85
|
a.last(3)
|
52
86
|
a.should == [1, 2, 3]
|
53
87
|
end
|
54
|
-
end
|
88
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
require File.expand_path('../shared/length', __FILE__)
|
4
|
+
|
1
5
|
describe "Array#length" do
|
2
|
-
|
3
|
-
|
4
|
-
[1, 2, 3].length.should == 3
|
6
|
+
pending do
|
7
|
+
it_behaves_like(:array_length, :length)
|
5
8
|
end
|
6
|
-
end
|
9
|
+
end
|
data/spec/core/array/map_spec.rb
CHANGED
@@ -1,53 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
b = a.map { |i| i + '!' }
|
5
|
-
b.should == ['a!', 'b!', 'c!', 'd!']
|
6
|
-
b.object_id.should_not == a.object_id
|
7
|
-
end
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
require File.expand_path('../shared/collect', __FILE__)
|
8
4
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
a.should == ['a', 'b', 'c', 'd']
|
13
|
-
end
|
14
|
-
|
15
|
-
it "returns the evaluated value of block if it broke in the block" do
|
16
|
-
a = ['a', 'b', 'c', 'd']
|
17
|
-
b = a.map {|i|
|
18
|
-
if i == 'c'
|
19
|
-
break 0
|
20
|
-
else
|
21
|
-
i + '!'
|
22
|
-
end
|
23
|
-
}
|
24
|
-
b.should == 0
|
5
|
+
describe "Array#map" do
|
6
|
+
pending do
|
7
|
+
it_behaves_like(:array_collect, :map)
|
25
8
|
end
|
26
9
|
end
|
27
10
|
|
28
11
|
describe "Array#map!" do
|
29
|
-
|
30
|
-
|
31
|
-
a.map! { |i| i - 1 }.should equal(a)
|
32
|
-
a.should == [6, 8, 2, 4]
|
12
|
+
pending do
|
13
|
+
it_behaves_like(:array_collect_b, :map!)
|
33
14
|
end
|
34
|
-
|
35
|
-
it "returns self" do
|
36
|
-
a = [1, 2, 3, 4, 5]
|
37
|
-
b = a.map! {|i| i+1 }
|
38
|
-
a.object_id.should == b.object_id
|
39
|
-
end
|
40
|
-
|
41
|
-
it "returns the evaluated value of block but its contents is partially modified, if it broke in the block" do
|
42
|
-
a = ['a', 'b', 'c', 'd']
|
43
|
-
b = a.map! {|i|
|
44
|
-
if i == 'c'
|
45
|
-
break 0
|
46
|
-
else
|
47
|
-
i + '!'
|
48
|
-
end
|
49
|
-
}
|
50
|
-
b.should == 0
|
51
|
-
a.should == ['a!', 'b!', 'c', 'd']
|
52
|
-
end
|
53
|
-
end
|
15
|
+
end
|
@@ -1,23 +1,87 @@
|
|
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 "creates an array minus any items from other array" do
|
3
|
-
([] - [1, 2, 4]).should == []
|
6
|
+
([] - [ 1, 2, 4 ]).should == []
|
4
7
|
([1, 2, 4] - []).should == [1, 2, 4]
|
5
|
-
([1, 2, 3, 4, 5] - [1, 2, 4]).should == [3, 5]
|
8
|
+
([ 1, 2, 3, 4, 5 ] - [ 1, 2, 4 ]).should == [3, 5]
|
6
9
|
end
|
7
10
|
|
8
11
|
it "removes multiple items on the lhs equal to one on the rhs" do
|
9
12
|
([1, 1, 2, 2, 3, 3, 4, 5] - [1, 2, 4]).should == [3, 3, 5]
|
10
13
|
end
|
11
14
|
|
15
|
+
ruby_bug "#", "1.8.6.277" do
|
16
|
+
pending "properly handles recursive arrays" do
|
17
|
+
empty = ArraySpecs.empty_recursive_array
|
18
|
+
(empty - empty).should == []
|
19
|
+
|
20
|
+
([] - ArraySpecs.recursive_array).should == []
|
21
|
+
|
22
|
+
array = ArraySpecs.recursive_array
|
23
|
+
(array - array).should == []
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
pending "tries to convert the passed arguments to Arrays using #to_ary" do
|
28
|
+
obj = mock('[2,3,3,4]')
|
29
|
+
obj.should_receive(:to_ary).and_return([2, 3, 3, 4])
|
30
|
+
([1, 1, 2, 2, 3, 4] - obj).should == [1, 1]
|
31
|
+
end
|
32
|
+
|
33
|
+
pending "raises a TypeError if the argument cannot be coerced to an Array by calling #to_ary" do
|
34
|
+
obj = mock('not an array')
|
35
|
+
lambda { [1, 2, 3] - obj }.should raise_error(TypeError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "does not return subclass instance for Array subclasses" do
|
39
|
+
(ArraySpecs::MyArray[1, 2, 3] - []).should be_kind_of(Array)
|
40
|
+
(ArraySpecs::MyArray[1, 2, 3] - ArraySpecs::MyArray[]).should be_kind_of(Array)
|
41
|
+
([1, 2, 3] - ArraySpecs::MyArray[]).should be_kind_of(Array)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "does not call to_ary on array subclasses" do
|
45
|
+
([5, 6, 7] - ArraySpecs::ToAryArray[7]).should == [5, 6]
|
46
|
+
end
|
47
|
+
|
48
|
+
pending "removes an item identified as equivalent via #hash and #eql?" do
|
49
|
+
obj1 = mock('1')
|
50
|
+
obj2 = mock('2')
|
51
|
+
obj1.should_receive(:hash).and_return(0)
|
52
|
+
obj2.should_receive(:hash).and_return(0)
|
53
|
+
obj1.should_receive(:eql?).with(obj2).and_return(true)
|
54
|
+
|
55
|
+
([obj1] - [obj2]).should == []
|
56
|
+
end
|
57
|
+
|
58
|
+
pending "doesn't remove an item with the same hash but not #eql?" do
|
59
|
+
obj1 = mock('1')
|
60
|
+
obj2 = mock('2')
|
61
|
+
obj1.should_receive(:hash).and_return(0)
|
62
|
+
obj2.should_receive(:hash).and_return(0)
|
63
|
+
obj1.should_receive(:eql?).with(obj2).and_return(false)
|
64
|
+
|
65
|
+
([obj1] - [obj2]).should == [obj1]
|
66
|
+
end
|
67
|
+
|
68
|
+
pending "removes an identical item even when its #eql? isn't reflexive" do
|
69
|
+
x = mock('x')
|
70
|
+
x.should_receive(:hash).any_number_of_times.and_return(42)
|
71
|
+
x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
|
72
|
+
|
73
|
+
([x] - [x]).should == []
|
74
|
+
end
|
75
|
+
|
12
76
|
it "is not destructive" do
|
13
77
|
a = [1, 2, 3]
|
14
78
|
a - []
|
15
79
|
a.should == [1, 2, 3]
|
16
80
|
a - [1]
|
17
81
|
a.should == [1, 2, 3]
|
18
|
-
a - [1,
|
82
|
+
a - [1,2,3]
|
19
83
|
a.should == [1, 2, 3]
|
20
84
|
a - [:a, :b, :c]
|
21
85
|
a.should == [1, 2, 3]
|
22
86
|
end
|
23
|
-
end
|
87
|
+
end
|
@@ -1,13 +1,145 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
require File.expand_path('../shared/join', __FILE__)
|
4
|
+
|
5
|
+
describe "Array#*" do
|
6
|
+
pending "tries to convert the passed argument to a String using #to_str" do
|
7
|
+
obj = mock('separator')
|
8
|
+
obj.should_receive(:to_str).and_return('::')
|
9
|
+
([1, 2, 3, 4] * obj).should == '1::2::3::4'
|
10
|
+
end
|
11
|
+
|
12
|
+
pending "tires to convert the passed argument to an Integer using #to_int" do
|
13
|
+
obj = mock('count')
|
14
|
+
obj.should_receive(:to_int).and_return(2)
|
15
|
+
([1, 2, 3, 4] * obj).should == [1, 2, 3, 4, 1, 2, 3, 4]
|
16
|
+
end
|
17
|
+
|
18
|
+
pending "raises a TypeError if the argument can neither be converted to a string nor an integer" do
|
19
|
+
obj = mock('not a string or integer')
|
20
|
+
lambda{ [1,2] * obj }.should raise_error(TypeError)
|
21
|
+
end
|
22
|
+
|
23
|
+
pending "converts the passed argument to a String rather than an Integer" do
|
24
|
+
obj = mock('2')
|
25
|
+
def obj.to_int() 2 end
|
26
|
+
def obj.to_str() "2" end
|
27
|
+
([:a, :b, :c] * obj).should == "a2b2c"
|
28
|
+
end
|
29
|
+
|
30
|
+
pending "raises a TypeError is the passed argument is nil" do
|
31
|
+
lambda{ [1,2] * nil }.should raise_error(TypeError)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "raises an ArgumentError when passed 2 or more arguments" do
|
35
|
+
lambda{ [1,2].send(:*, 1, 2) }.should raise_error(ArgumentError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "raises an ArgumentError when passed no arguments" do
|
39
|
+
lambda{ [1,2].send(:*) }.should raise_error(ArgumentError)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
1
43
|
describe "Array#* with an integer" do
|
2
44
|
it "concatenates n copies of the array when passed an integer" do
|
3
|
-
([1, 2, 3] * 0).should == []
|
4
|
-
([1, 2, 3] * 1).should == [1, 2, 3]
|
5
|
-
([1, 2, 3] * 3).should == [1, 2, 3, 1, 2, 3, 1, 2, 3]
|
45
|
+
([ 1, 2, 3 ] * 0).should == []
|
46
|
+
([ 1, 2, 3 ] * 1).should == [1, 2, 3]
|
47
|
+
([ 1, 2, 3 ] * 3).should == [1, 2, 3, 1, 2, 3, 1, 2, 3]
|
48
|
+
([] * 10).should == []
|
49
|
+
end
|
50
|
+
|
51
|
+
it "does not return self even if the passed integer is 1" do
|
52
|
+
ary = [1, 2, 3]
|
53
|
+
(ary * 1).should_not equal(ary)
|
54
|
+
end
|
55
|
+
|
56
|
+
pending "properly handles recursive arrays" do
|
57
|
+
empty = ArraySpecs.empty_recursive_array
|
58
|
+
(empty * 0).should == []
|
59
|
+
(empty * 1).should == empty
|
60
|
+
(empty * 3).should == [empty, empty, empty]
|
61
|
+
|
62
|
+
array = ArraySpecs.recursive_array
|
63
|
+
(array * 0).should == []
|
64
|
+
(array * 1).should == array
|
65
|
+
end
|
66
|
+
|
67
|
+
pending "raises an ArgumentError when passed a negative integer" do
|
68
|
+
lambda { [ 1, 2, 3 ] * -1 }.should raise_error(ArgumentError)
|
69
|
+
lambda { [] * -1 }.should raise_error(ArgumentError)
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "with a subclass of Array" do
|
73
|
+
before :each do
|
74
|
+
ScratchPad.clear
|
75
|
+
|
76
|
+
@array = ArraySpecs::MyArray[1, 2, 3, 4, 5]
|
77
|
+
end
|
78
|
+
|
79
|
+
pending "returns a subclass instance" do
|
80
|
+
(@array * 0).should be_an_instance_of(ArraySpecs::MyArray)
|
81
|
+
(@array * 1).should be_an_instance_of(ArraySpecs::MyArray)
|
82
|
+
(@array * 2).should be_an_instance_of(ArraySpecs::MyArray)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "does not call #initialize on the subclass instance" do
|
86
|
+
(@array * 2).should == [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
|
87
|
+
ScratchPad.recorded.should be_nil
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
ruby_version_is '' ... '1.9' do
|
92
|
+
it "does not copy the taint status of the original array if the passed count is 0" do
|
93
|
+
ary = [1, 2, 3]
|
94
|
+
ary.taint
|
95
|
+
(ary * 0).tainted?.should == false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
ruby_version_is '1.9' do
|
99
|
+
pending "copies the taint status of the original array even if the passed count is 0" do
|
100
|
+
ary = [1, 2, 3]
|
101
|
+
ary.taint
|
102
|
+
(ary * 0).tainted?.should == true
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
pending "copies the taint status of the original array even if the array is empty" do
|
107
|
+
ary = []
|
108
|
+
ary.taint
|
109
|
+
(ary * 3).tainted?.should == true
|
110
|
+
end
|
111
|
+
|
112
|
+
pending "copies the taint status of the original array if the passed count is not 0" do
|
113
|
+
ary = [1, 2, 3]
|
114
|
+
ary.taint
|
115
|
+
(ary * 1).tainted?.should == true
|
116
|
+
(ary * 2).tainted?.should == true
|
117
|
+
end
|
118
|
+
|
119
|
+
ruby_version_is '1.9' do
|
120
|
+
pending "copies the untrusted status of the original array even if the passed count is 0" do
|
121
|
+
ary = [1, 2, 3]
|
122
|
+
ary.untrust
|
123
|
+
(ary * 0).untrusted?.should == true
|
124
|
+
end
|
125
|
+
|
126
|
+
pending "copies the untrusted status of the original array even if the array is empty" do
|
127
|
+
ary = []
|
128
|
+
ary.untrust
|
129
|
+
(ary * 3).untrusted?.should == true
|
130
|
+
end
|
131
|
+
|
132
|
+
pending "copies the untrusted status of the original array if the passed count is not 0" do
|
133
|
+
ary = [1, 2, 3]
|
134
|
+
ary.untrust
|
135
|
+
(ary * 1).untrusted?.should == true
|
136
|
+
(ary * 2).untrusted?.should == true
|
137
|
+
end
|
6
138
|
end
|
7
139
|
end
|
8
140
|
|
9
141
|
describe "Array#* with a string" do
|
10
|
-
|
11
|
-
|
142
|
+
pending do
|
143
|
+
it_behaves_like :array_join_with_string_separator, :*
|
12
144
|
end
|
13
|
-
end
|
145
|
+
end
|
data/spec/core/array/new_spec.rb
CHANGED
@@ -1,12 +1,32 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
|
1
4
|
describe "Array.new" do
|
2
5
|
it "returns an instance of Array" do
|
3
6
|
Array.new.should be_kind_of(Array)
|
4
7
|
end
|
8
|
+
|
9
|
+
pending "returns an instance of a subclass" do
|
10
|
+
ArraySpecs::MyArray.new(1, 2).should be_an_instance_of(ArraySpecs::MyArray)
|
11
|
+
end
|
12
|
+
|
13
|
+
pending "raise an ArgumentError if passed 3 or more arguments" do
|
14
|
+
lambda do
|
15
|
+
[1, 2].send :initialize, 1, 'x', true
|
16
|
+
end.should raise_error(ArgumentError)
|
17
|
+
lambda do
|
18
|
+
[1, 2].send(:initialize, 1, 'x', true) {}
|
19
|
+
end.should raise_error(ArgumentError)
|
20
|
+
end
|
5
21
|
end
|
6
22
|
|
7
23
|
describe "Array.new with no arguments" do
|
8
|
-
|
9
|
-
Array.new.
|
24
|
+
pending "returns an empty array" do
|
25
|
+
Array.new.should be_empty
|
26
|
+
end
|
27
|
+
|
28
|
+
it "does not use the given block" do
|
29
|
+
lambda{ Array.new { raise } }.should_not raise_error
|
10
30
|
end
|
11
31
|
end
|
12
32
|
|
@@ -15,6 +35,27 @@ describe "Array.new with (array)" do
|
|
15
35
|
b = [4, 5, 6]
|
16
36
|
Array.new(b).should == b
|
17
37
|
end
|
38
|
+
|
39
|
+
it "does not use the given block" do
|
40
|
+
lambda{ Array.new([1, 2]) { raise } }.should_not raise_error
|
41
|
+
end
|
42
|
+
|
43
|
+
pending "calls #to_ary to convert the value to an array" do
|
44
|
+
a = mock("array")
|
45
|
+
a.should_receive(:to_ary).and_return([1, 2])
|
46
|
+
a.should_not_receive(:to_int)
|
47
|
+
Array.new(a).should == [1, 2]
|
48
|
+
end
|
49
|
+
|
50
|
+
pending "does not call #to_ary on instances of Array or subclasses of Array" do
|
51
|
+
a = [1, 2]
|
52
|
+
a.should_not_receive(:to_ary)
|
53
|
+
Array.new(a)
|
54
|
+
end
|
55
|
+
|
56
|
+
pending "raises a TypeError if an Array type argument and a default object" do
|
57
|
+
lambda { Array.new([1, 2], 1) }.should raise_error(TypeError)
|
58
|
+
end
|
18
59
|
end
|
19
60
|
|
20
61
|
describe "Array.new with (size, object=nil)" do
|
@@ -30,6 +71,45 @@ describe "Array.new with (size, object=nil)" do
|
|
30
71
|
Array.new(3).should == [nil, nil, nil]
|
31
72
|
end
|
32
73
|
|
74
|
+
pending "raises an ArgumentError if size is negative" do
|
75
|
+
lambda { Array.new(-1, :a) }.should raise_error(ArgumentError)
|
76
|
+
lambda { Array.new(-1) }.should raise_error(ArgumentError)
|
77
|
+
end
|
78
|
+
|
79
|
+
pending do
|
80
|
+
platform_is :wordsize => 32 do
|
81
|
+
it "raises an ArgumentError if size is too large" do
|
82
|
+
max_size = ArraySpecs.max_32bit_size
|
83
|
+
lambda { Array.new(max_size + 1) }.should raise_error(ArgumentError)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
platform_is :wordsize => 64 do
|
88
|
+
it "raises an ArgumentError if size is too large" do
|
89
|
+
max_size = ArraySpecs.max_64bit_size
|
90
|
+
lambda { Array.new(max_size + 1) }.should raise_error(ArgumentError)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
pending "calls #to_int to convert the size argument to an Integer when object is given" do
|
96
|
+
obj = mock('1')
|
97
|
+
obj.should_receive(:to_int).and_return(1)
|
98
|
+
Array.new(obj, :a).should == [:a]
|
99
|
+
end
|
100
|
+
|
101
|
+
pending "calls #to_int to convert the size argument to an Integer when object is not given" do
|
102
|
+
obj = mock('1')
|
103
|
+
obj.should_receive(:to_int).and_return(1)
|
104
|
+
Array.new(obj).should == [nil]
|
105
|
+
end
|
106
|
+
|
107
|
+
pending "raises a TypeError if the size argument is not an Integer type" do
|
108
|
+
obj = mock('nonnumeric')
|
109
|
+
obj.stub!(:to_ary).and_return([1, 2])
|
110
|
+
lambda{ Array.new(obj, :a) }.should raise_error(TypeError)
|
111
|
+
end
|
112
|
+
|
33
113
|
it "yields the index of the element and sets the element to the value of the block" do
|
34
114
|
Array.new(3) { |i| i.to_s }.should == ['0', '1', '2']
|
35
115
|
end
|
@@ -37,4 +117,13 @@ describe "Array.new with (size, object=nil)" do
|
|
37
117
|
it "uses the block value instead of using the default value" do
|
38
118
|
Array.new(3, :obj) { |i| i.to_s }.should == ['0', '1', '2']
|
39
119
|
end
|
40
|
-
|
120
|
+
|
121
|
+
pending "returns the value passed to break" do
|
122
|
+
a = Array.new(3) do |i|
|
123
|
+
break if i == 2
|
124
|
+
i.to_s
|
125
|
+
end
|
126
|
+
|
127
|
+
a.should == nil
|
128
|
+
end
|
129
|
+
end
|