opal 0.3.16 → 0.3.17
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +8 -7
- data/README.md +21 -13
- data/Rakefile +64 -78
- data/bin/opal +18 -29
- data/core/alpha.rb +2 -9
- data/core/array.rb +106 -50
- data/core/basic_object.rb +10 -8
- data/core/boolean.rb +2 -0
- data/core/class.rb +25 -13
- data/core/comparable.rb +6 -6
- data/core/enumerable.rb +90 -94
- data/core/enumerator.rb +3 -3
- data/core/hash.rb +86 -46
- data/core/kernel.rb +55 -39
- data/core/load_order +2 -5
- data/core/match_data.rb +1 -1
- data/core/module.rb +45 -20
- data/core/nil_class.rb +6 -2
- data/core/numeric.rb +20 -10
- data/core/proc.rb +2 -2
- data/core/range.rb +72 -13
- data/core/regexp.rb +5 -3
- data/core/runtime.js +228 -287
- data/core/string.rb +345 -37
- data/core/top_self.rb +1 -1
- data/lib/opal.rb +13 -91
- data/lib/opal/builder.rb +47 -120
- data/lib/opal/builder_task.rb +74 -0
- data/lib/opal/{parser/grammar.rb → grammar.rb} +1094 -1083
- data/lib/opal/{parser/grammar.y → grammar.y} +7 -0
- data/lib/opal/{parser/lexer.rb → lexer.rb} +32 -11
- data/lib/opal/{parser/parser.rb → parser.rb} +232 -238
- data/lib/opal/{parser/scope.rb → scope.rb} +72 -9
- data/lib/opal/version.rb +2 -3
- data/opal.gemspec +1 -2
- data/{core_spec → spec}/core/array/allocate_spec.rb +1 -3
- data/{core_spec → spec}/core/array/append_spec.rb +1 -4
- data/{core_spec → spec}/core/array/assoc_spec.rb +1 -4
- data/{core_spec → spec}/core/array/at_spec.rb +1 -3
- data/{core_spec → spec}/core/array/clear_spec.rb +1 -3
- data/spec/core/array/clone_spec.rb +15 -0
- data/{core_spec/core/array/shared/collect.rb → spec/core/array/collect_spec.rb} +1 -1
- data/{core_spec → spec}/core/array/compact_spec.rb +1 -3
- data/{core_spec → spec}/core/array/concat_spec.rb +1 -3
- data/{core_spec → spec}/core/array/constructor_spec.rb +9 -3
- data/{core_spec → spec}/core/array/count_spec.rb +1 -3
- data/{core_spec → spec}/core/array/delete_at_spec.rb +1 -4
- data/{core_spec → spec}/core/array/delete_if_spec.rb +1 -4
- data/{core_spec → spec}/core/array/delete_spec.rb +1 -4
- data/{core_spec → spec}/core/array/each_index_spec.rb +1 -4
- data/{core_spec → spec}/core/array/each_spec.rb +1 -4
- data/{core_spec → spec}/core/array/element_reference_spec.rb +74 -4
- data/{core_spec → spec}/core/array/empty_spec.rb +1 -4
- data/{core_spec/core/array/shared/eql.rb → spec/core/array/eql_spec.rb} +1 -1
- data/{core_spec → spec}/core/array/fetch_spec.rb +1 -4
- data/{core_spec → spec}/core/array/first_spec.rb +1 -3
- data/{core_spec → spec}/core/array/flatten_spec.rb +1 -3
- data/{core_spec → spec}/core/array/include_spec.rb +1 -3
- data/{core_spec → spec}/core/array/insert_spec.rb +1 -4
- data/{core_spec → spec}/core/array/last_spec.rb +1 -4
- data/{core_spec/core/array/shared/length.rb → spec/core/array/length_spec.rb} +1 -1
- data/spec/core/array/map_spec.rb +53 -0
- data/{core_spec → spec}/core/array/plus_spec.rb +1 -4
- data/{core_spec → spec}/core/array/pop_spec.rb +1 -4
- data/{core_spec → spec}/core/array/push_spec.rb +1 -4
- data/{core_spec → spec}/core/array/rassoc_spec.rb +1 -4
- data/{core_spec → spec}/core/array/reject_spec.rb +1 -4
- data/{core_spec/core/array/shared/replace.rb → spec/core/array/replace_spec.rb} +1 -1
- data/{core_spec → spec}/core/array/reverse_each_spec.rb +1 -4
- data/{core_spec → spec}/core/array/reverse_spec.rb +1 -4
- data/spec/core/array/size_spec.rb +6 -0
- data/spec/core/array/to_ary_spec.rb +6 -0
- data/spec/core/array/uniq_spec.rb +22 -0
- data/spec/core/array/zip_spec.rb +20 -0
- data/{core_spec → spec}/core/class/new_spec.rb +1 -4
- data/{core_spec → spec}/core/enumerable/all_spec.rb +1 -4
- data/{core_spec → spec}/core/enumerable/any_spec.rb +1 -4
- data/{core_spec/core/enumerable/shared/collect.rb → spec/core/enumerable/collect_spec.rb} +1 -1
- data/{core_spec → spec}/core/enumerable/count_spec.rb +2 -5
- data/{core_spec → spec}/core/enumerable/fixtures/classes.rb +1 -2
- data/{core_spec → spec}/core/false/and_spec.rb +1 -3
- data/{core_spec → spec}/core/false/inspect_spec.rb +1 -3
- data/{core_spec → spec}/core/false/or_spec.rb +1 -3
- data/{core_spec → spec}/core/false/to_s_spec.rb +1 -3
- data/{core_spec → spec}/core/false/xor_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/allocate_spec.rb +1 -3
- data/spec/core/hash/assoc_spec.rb +25 -0
- data/{core_spec → spec}/core/hash/clear_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/clone_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/default_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/delete_if_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/element_reference_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/element_set_spec.rb +1 -3
- data/spec/core/hash/merge_spec.rb +37 -0
- data/{core_spec → spec}/core/hash/new_spec.rb +1 -3
- data/{core_spec → spec}/core/matchdata/to_a_spec.rb +1 -3
- data/{core_spec → spec}/core/nil/and_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/inspect_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/nil_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/or_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_a_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_f_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_i_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_s_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/xor_spec.rb +1 -4
- data/{core_spec → spec}/core/numeric/equal_value_spec.rb +1 -3
- data/{core_spec → spec}/core/regexp/match_spec.rb +10 -3
- data/{core_spec → spec}/core/symbol/to_proc_spec.rb +1 -3
- data/{core_spec → spec}/core/true/and_spec.rb +1 -3
- data/{core_spec → spec}/core/true/inspect_spec.rb +1 -3
- data/{core_spec → spec}/core/true/or_spec.rb +1 -3
- data/{core_spec → spec}/core/true/to_s_spec.rb +1 -3
- data/{core_spec → spec}/core/true/xor_spec.rb +1 -3
- data/spec/index.html +11 -0
- data/{core_spec → spec}/language/alias_spec.rb +1 -3
- data/{core_spec → spec}/language/and_spec.rb +1 -4
- data/{core_spec → spec}/language/array_spec.rb +1 -4
- data/{core_spec → spec}/language/block_spec.rb +20 -3
- data/{core_spec → spec}/language/break_spec.rb +40 -3
- data/{core_spec → spec}/language/case_spec.rb +1 -4
- data/{core_spec → spec}/language/defined_spec.rb +9 -3
- data/{core_spec → spec}/language/ensure_spec.rb +38 -3
- data/{core_spec → spec}/language/hash_spec.rb +1 -3
- data/{core_spec → spec}/language/if_spec.rb +1 -4
- data/{core_spec → spec}/language/loop_spec.rb +1 -3
- data/spec/language/metaclass_spec.rb +13 -0
- data/{core_spec → spec}/language/next_spec.rb +47 -3
- data/{core_spec → spec}/language/or_spec.rb +1 -4
- data/{core_spec → spec}/language/predefined_spec.rb +1 -3
- data/{core_spec/language/regexp/interpolation_spec.rb → spec/language/regexp_spec.rb} +6 -3
- data/{core_spec → spec}/language/send_spec.rb +38 -4
- data/spec/language/singleton_class_spec.rb +31 -0
- data/spec/language/super_spec.rb +188 -0
- data/{core_spec → spec}/language/symbol_spec.rb +1 -3
- data/{core_spec → spec}/language/undef_spec.rb +1 -3
- data/{core_spec → spec}/language/unless_spec.rb +1 -4
- data/{core_spec → spec}/language/until_spec.rb +1 -3
- data/{core_spec → spec}/language/variables_spec.rb +1 -3
- data/{core_spec → spec}/language/while_spec.rb +1 -3
- data/{spec → test}/builder/build_source_spec.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/adam.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/bar/a.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/bar/wow/b.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/bar/wow/cow/c.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/beynon.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/charles.js +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/a.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/b.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/x.js +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/y.js +0 -0
- data/{spec → test}/grammar/alias_spec.rb +0 -0
- data/{spec → test}/grammar/and_spec.rb +0 -0
- data/{spec → test}/grammar/array_spec.rb +0 -0
- data/{spec → test}/grammar/attrasgn_spec.rb +0 -0
- data/{spec → test}/grammar/begin_spec.rb +0 -0
- data/{spec → test}/grammar/block_spec.rb +0 -0
- data/{spec → test}/grammar/break_spec.rb +0 -0
- data/{spec → test}/grammar/call_spec.rb +0 -0
- data/{spec → test}/grammar/class_spec.rb +0 -0
- data/{spec → test}/grammar/const_spec.rb +0 -0
- data/{spec → test}/grammar/cvar_spec.rb +0 -0
- data/{spec → test}/grammar/def_spec.rb +0 -0
- data/{spec → test}/grammar/false_spec.rb +0 -0
- data/{spec → test}/grammar/file_spec.rb +0 -0
- data/{spec → test}/grammar/gvar_spec.rb +0 -0
- data/{spec → test}/grammar/hash_spec.rb +0 -0
- data/{spec → test}/grammar/iasgn_spec.rb +0 -0
- data/{spec → test}/grammar/if_spec.rb +0 -0
- data/{spec → test}/grammar/iter_spec.rb +0 -0
- data/{spec → test}/grammar/ivar_spec.rb +0 -0
- data/{spec → test}/grammar/lasgn_spec.rb +0 -0
- data/{spec → test}/grammar/line_spec.rb +0 -0
- data/{spec → test}/grammar/lvar_spec.rb +0 -0
- data/{spec → test}/grammar/masgn_spec.rb +0 -0
- data/{spec → test}/grammar/module_spec.rb +0 -0
- data/{spec → test}/grammar/nil_spec.rb +0 -0
- data/{spec → test}/grammar/not_spec.rb +0 -0
- data/{spec → test}/grammar/op_asgn1_spec.rb +0 -0
- data/{spec → test}/grammar/op_asgn2_spec.rb +0 -0
- data/{spec → test}/grammar/or_spec.rb +0 -0
- data/{spec → test}/grammar/return_spec.rb +0 -0
- data/{spec → test}/grammar/sclass_spec.rb +0 -0
- data/{spec → test}/grammar/self_spec.rb +0 -0
- data/{spec → test}/grammar/str_spec.rb +0 -0
- data/{spec → test}/grammar/super_spec.rb +0 -0
- data/{spec → test}/grammar/true_spec.rb +0 -0
- data/{spec → test}/grammar/undef_spec.rb +0 -0
- data/{spec → test}/grammar/unless_spec.rb +0 -0
- data/{spec → test}/grammar/while_spec.rb +0 -0
- data/{spec → test}/grammar/xstr_spec.rb +0 -0
- data/{spec → test}/grammar/yield_spec.rb +0 -0
- data/{spec → test}/spec_helper.rb +0 -0
- metadata +330 -264
- data/core/debug.js +0 -59
- data/core/debug.rb +0 -35
- data/core/dir.rb +0 -90
- data/core/file.rb +0 -83
- data/core/gemlib.rb +0 -30
- data/core/io.rb +0 -44
- data/core_spec/README.md +0 -34
- data/core_spec/core/array/collect_spec.rb +0 -3
- data/core_spec/core/array/element_set_spec.rb +0 -7
- data/core_spec/core/array/eql_spec.rb +0 -3
- data/core_spec/core/array/equal_value_spec.rb +0 -3
- data/core_spec/core/array/fixtures/classes.rb +0 -8
- data/core_spec/core/array/length_spec.rb +0 -3
- data/core_spec/core/array/map_spec.rb +0 -3
- data/core_spec/core/array/replace_spec.rb +0 -3
- data/core_spec/core/enumerable/collect_spec.rb +0 -3
- data/core_spec/core/enumerable/detect_spec.rb +0 -3
- data/core_spec/core/enumerable/find_spec.rb +0 -3
- data/core_spec/core/enumerable/first_spec.rb +0 -3
- data/core_spec/core/enumerable/shared/entries.rb +0 -7
- data/core_spec/core/enumerable/shared/find.rb +0 -49
- data/core_spec/core/enumerable/shared/take.rb +0 -31
- data/core_spec/core/enumerable/to_a_spec.rb +0 -7
- data/core_spec/core/hash/assoc_spec.rb +0 -29
- data/core_spec/core/object/is_a_spec.rb +0 -2
- data/core_spec/core/object/shared/kind_of.rb +0 -0
- data/core_spec/core/regexp/shared/match.rb +0 -11
- data/core_spec/language/fixtures/block.rb +0 -19
- data/core_spec/language/fixtures/break.rb +0 -39
- data/core_spec/language/fixtures/defined.rb +0 -9
- data/core_spec/language/fixtures/ensure.rb +0 -37
- data/core_spec/language/fixtures/next.rb +0 -46
- data/core_spec/language/fixtures/send.rb +0 -36
- data/core_spec/language/fixtures/super.rb +0 -43
- data/core_spec/language/regexp_spec.rb +0 -7
- data/core_spec/language/string_spec.rb +0 -4
- data/core_spec/language/super_spec.rb +0 -18
- data/core_spec/language/versions/hash_1.9.rb +0 -20
- data/core_spec/opal/opal/defined_spec.rb +0 -15
- data/core_spec/opal/opal/function_spec.rb +0 -11
- data/core_spec/opal/opal/native_spec.rb +0 -16
- data/core_spec/opal/opal/null_spec.rb +0 -10
- data/core_spec/opal/opal/number_spec.rb +0 -11
- data/core_spec/opal/opal/object_spec.rb +0 -16
- data/core_spec/opal/opal/string_spec.rb +0 -11
- data/core_spec/opal/opal/typeof_spec.rb +0 -9
- data/core_spec/opal/opal/undefined_spec.rb +0 -10
- data/core_spec/opal/true/case_compare_spec.rb +0 -12
- data/core_spec/opal/true/class_spec.rb +0 -10
- data/core_spec/release_runner.html +0 -17
- data/core_spec/runner.html +0 -16
- data/core_spec/spec_helper.rb +0 -23
- data/lib/opal/context.rb +0 -269
- data/lib/opal/dependency_builder.rb +0 -133
- data/lib/opal/environment.rb +0 -87
- data/lib/opal/parser/sexp.rb +0 -17
@@ -1,10 +1,7 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
-
|
4
1
|
describe "Array#empty?" do
|
5
2
|
it "returns true if the array has no elements" do
|
6
3
|
[].empty?.should == true
|
7
4
|
[1].empty?.should == false
|
8
5
|
[1, 2].empty?.should == false
|
9
6
|
end
|
10
|
-
end
|
7
|
+
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
-
|
4
1
|
describe "Array#fetch" do
|
5
2
|
it "returns the element at the passed index" do
|
6
3
|
[1, 2, 3].fetch(1).should == 2
|
@@ -23,4 +20,4 @@ describe "Array#fetch" do
|
|
23
20
|
[1, 2, 3].fetch(-4, :not_found).should == :not_found
|
24
21
|
[nil].fetch(0, :not_found).should == nil
|
25
22
|
end
|
26
|
-
end
|
23
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
1
|
describe "Array#first" do
|
4
2
|
it "returns the first element" do
|
5
3
|
%w[a b c].first.should == 'a'
|
@@ -51,4 +49,4 @@ describe "Array#first" do
|
|
51
49
|
a.first(3)
|
52
50
|
a.should == [1, 2, 3]
|
53
51
|
end
|
54
|
-
end
|
52
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
1
|
describe "Array#flatten" do
|
4
2
|
it "returns a one-dimensional flattening recursively" do
|
5
3
|
[[[1, [2, 3]], [2, 3, [4, [4, [5, 5]], [1, 2, 3]]], [4]], []].flatten.should == [1, 2, 3, 2, 3, 4, 4, 5, 5, 1, 2, 3, 4]
|
@@ -38,4 +36,4 @@ describe "Array#flatten!" do
|
|
38
36
|
it "takes an optional argument that determines the level of recursion" do
|
39
37
|
[1, 2, [3, [4, 5]]].flatten!(1).should == [1, 2, 3, [4, 5]]
|
40
38
|
end
|
41
|
-
end
|
39
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
1
|
describe "Array#include?" do
|
4
2
|
it "returns true if object is present, false otherwise" do
|
5
3
|
[1, 2, "a", "b"].include?("c").should == false
|
@@ -17,4 +15,4 @@ describe "Array#include?" do
|
|
17
15
|
|
18
16
|
[1, 2.0, 3].include?(2).should == true
|
19
17
|
end
|
20
|
-
end
|
18
|
+
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
-
|
4
1
|
describe "Array#insert" do
|
5
2
|
it "returns self" do
|
6
3
|
ary = []
|
@@ -56,4 +53,4 @@ describe "Array#insert" do
|
|
56
53
|
[].insert(10).should == []
|
57
54
|
[].insert(-2).should == []
|
58
55
|
end
|
59
|
-
end
|
56
|
+
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
-
|
4
1
|
describe "Array#last" do
|
5
2
|
it "returns the last element" do
|
6
3
|
[1, 1, 1, 1, 2].last.should == 2
|
@@ -54,4 +51,4 @@ describe "Array#last" do
|
|
54
51
|
a.last(3)
|
55
52
|
a.should == [1, 2, 3]
|
56
53
|
end
|
57
|
-
end
|
54
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
describe "Array#map" do
|
2
|
+
it "returns a copy of array with each element replaced by the value returned by block" do
|
3
|
+
a = ['a', 'b', 'c', 'd']
|
4
|
+
b = a.map { |i| i + '!' }
|
5
|
+
b.should == ['a!', 'b!', 'c!', 'd!']
|
6
|
+
b.object_id.should_not == a.object_id
|
7
|
+
end
|
8
|
+
|
9
|
+
it "does not change self" do
|
10
|
+
a = ['a', 'b', 'c', 'd']
|
11
|
+
b = a.map { |i| i + '!' }
|
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
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "Array#map!" do
|
29
|
+
it "replaces each element with the value returned by block" do
|
30
|
+
a = [7, 9, 3, 5]
|
31
|
+
a.map! { |i| i - 1 }.should equal(a)
|
32
|
+
a.should == [6, 8, 2, 4]
|
33
|
+
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
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
-
|
4
1
|
describe "Array#+" do
|
5
2
|
it "concatenates two arrays" do
|
6
3
|
([ 1, 2, 3 ] + [ 3, 4, 5 ] ).should == [1, 2, 3, 3, 4, 5]
|
@@ -13,4 +10,4 @@ describe "Array#+" do
|
|
13
10
|
ary = [1, 2, 3]
|
14
11
|
(ary + ary).should == [1, 2, 3, 1, 2, 3]
|
15
12
|
end
|
16
|
-
end
|
13
|
+
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
-
|
4
1
|
describe "Array#pop" do
|
5
2
|
it "removes and returns the last element of the array" do
|
6
3
|
a = ["a", 1, nil, true]
|
@@ -76,4 +73,4 @@ describe "Array#pop" do
|
|
76
73
|
lambda { [1, 2, 3].pop(-1) }.should raise_error(ArgumentError)
|
77
74
|
end
|
78
75
|
end
|
79
|
-
end
|
76
|
+
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
-
|
4
1
|
describe "Array#push" do
|
5
2
|
it "appends the arguments to the array" do
|
6
3
|
a = [ "a", "b", "c" ]
|
@@ -16,4 +13,4 @@ describe "Array#push" do
|
|
16
13
|
a.push("foo")
|
17
14
|
a.should == ["b", "c", "foo"]
|
18
15
|
end
|
19
|
-
end
|
16
|
+
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
-
|
4
1
|
describe "Array#rassoc" do
|
5
2
|
it "returns the first contained array whose second element it == object" do
|
6
3
|
ary = [[1, "a", 0.5], [2, "b"], [3, "b"], [4, "c"], [], [5], [6, "d"]]
|
@@ -9,4 +6,4 @@ describe "Array#rassoc" do
|
|
9
6
|
ary.rassoc("d").should == [6, "d"]
|
10
7
|
ary.rassoc("z").should == nil
|
11
8
|
end
|
12
|
-
end
|
9
|
+
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
-
|
4
1
|
describe "Array#reject" do
|
5
2
|
it "returns a new array without elements for which block is true" do
|
6
3
|
ary = [1, 2, 3, 4, 5]
|
@@ -51,4 +48,4 @@ describe "Array#reject!" do
|
|
51
48
|
a.reject! { true }
|
52
49
|
a.reject! { true }.should == nil
|
53
50
|
end
|
54
|
-
end
|
51
|
+
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
-
|
4
1
|
describe "Array#reverse_each" do
|
5
2
|
before :each do
|
6
3
|
ScratchPad.record []
|
@@ -15,4 +12,4 @@ describe "Array#reverse_each" do
|
|
15
12
|
a = [:a, :b, :c]
|
16
13
|
a.reverse_each { |x| }.should equal(a)
|
17
14
|
end
|
18
|
-
end
|
15
|
+
end
|
@@ -1,9 +1,6 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
-
|
4
1
|
describe "Array#reverse" do
|
5
2
|
it "returns a new array with the elements in reverse order" do
|
6
3
|
[].reverse.should == []
|
7
4
|
[1, 3, 5, 2].reverse.should == [2, 5, 3, 1]
|
8
5
|
end
|
9
|
-
end
|
6
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
describe "Array#uniq" do
|
2
|
+
it "returns an array with no duplicates" do
|
3
|
+
["a", "a", "b", "b", "c"].uniq.should == ["a", "b", "c"]
|
4
|
+
end
|
5
|
+
|
6
|
+
it "uses eql? semantics" do
|
7
|
+
[1.0, 1].should == [1.0, 1]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "Array#uniq!" do
|
12
|
+
it "modifies the array in place" do
|
13
|
+
a = [ "a", "a", "b", "b", "c" ]
|
14
|
+
a.uniq!
|
15
|
+
a.should == ["a", "b", "c"]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns self" do
|
19
|
+
a = [ "a", "a", "b", "b", "c" ]
|
20
|
+
a.should equal(a.uniq!)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
describe "Array#zip" do
|
2
|
+
it "returns an array of arrays containing corresponding elements of each array" do
|
3
|
+
[1, 2, 3, 4].zip(["a", "b", "c", "d", "e"]).should ==
|
4
|
+
[[1, "a"], [2, "b"], [3, "c"], [4, "d"]]
|
5
|
+
end
|
6
|
+
|
7
|
+
it "fills in missing values with nil" do
|
8
|
+
[1, 2, 3, 4, 5].zip(["a", "b", "c", "d"]).should ==
|
9
|
+
[[1, "a"], [2, "b"], [3, "c"], [4, "d"], [5, nil]]
|
10
|
+
end
|
11
|
+
|
12
|
+
it "calls block if supplied" do
|
13
|
+
values = []
|
14
|
+
[1, 2, 3, 4].zip(["a", "b", "c", "d", "e"]) { |value|
|
15
|
+
values << value
|
16
|
+
}.should == nil
|
17
|
+
|
18
|
+
values.should == [[1, "a"], [2, "b"], [3, "c"], [4, "d"]]
|
19
|
+
end
|
20
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
1
|
describe "Class.new with a block given" do
|
4
2
|
it "uses the given block as the class' body" do
|
5
3
|
klass = Class.new do
|
@@ -15,5 +13,4 @@ describe "Class.new with a block given" do
|
|
15
13
|
klass.message.should == "text"
|
16
14
|
klass.new.hello.should == "hello again"
|
17
15
|
end
|
18
|
-
end
|
19
|
-
|
16
|
+
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
-
|
4
1
|
describe "Enumerable#all?" do
|
5
2
|
|
6
3
|
before :each do
|
@@ -99,4 +96,4 @@ describe "Enumerable#all?" do
|
|
99
96
|
}.should raise_error(RuntimeError)
|
100
97
|
end
|
101
98
|
#end
|
102
|
-
end
|
99
|
+
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
-
|
4
1
|
describe "Enumerable#any?" do
|
5
2
|
before :each do
|
6
3
|
@enum = EnumerableSpecs::Numerous.new
|
@@ -112,4 +109,4 @@ describe "Enumerable#any?" do
|
|
112
109
|
}.should raise_error(RuntimeError)
|
113
110
|
end
|
114
111
|
#end
|
115
|
-
end
|
112
|
+
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
-
|
4
1
|
describe "Enumerable#count" do
|
5
2
|
before :each do
|
6
3
|
@elements = [1, 2, 4, 2]
|
@@ -24,6 +21,6 @@ describe "Enumerable#count" do
|
|
24
21
|
end
|
25
22
|
|
26
23
|
it "ignores the block when given an argument" do
|
27
|
-
|
24
|
+
@numerous.count(4){|x| x%2==0 }.should == 1
|
28
25
|
end
|
29
|
-
end
|
26
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
1
|
describe "FalseClass#&" do
|
4
2
|
it "returns false" do
|
5
3
|
(false & true).should == false
|
@@ -8,4 +6,4 @@ describe "FalseClass#&" do
|
|
8
6
|
(false & "").should == false
|
9
7
|
(false & mock('x')).should == false
|
10
8
|
end
|
11
|
-
end
|
9
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
1
|
describe "FalseClass#|" do
|
4
2
|
it "returns false if other is nil or false, otherwise true" do
|
5
3
|
(false | false).should == false
|
@@ -8,4 +6,4 @@ describe "FalseClass#|" do
|
|
8
6
|
(false | "").should == true
|
9
7
|
(false | mock('x')).should == true
|
10
8
|
end
|
11
|
-
end
|
9
|
+
end
|