opal 0.3.2 → 0.3.6
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/README.md +85 -127
- data/bin/opal +3 -3
- data/lib/core.rb +114 -0
- data/{gems/core/lib → lib}/core/array.rb +68 -187
- data/{gems/core/lib → lib}/core/basic_object.rb +22 -5
- data/lib/core/class.rb +38 -0
- data/{gems/core/lib → lib}/core/dir.rb +1 -1
- data/lib/core/enumerable.rb +33 -0
- data/{gems/core/lib → lib}/core/error.rb +1 -4
- data/{gems/core/lib → lib}/core/false_class.rb +0 -0
- data/{gems/core/lib → lib}/core/file.rb +11 -3
- data/{gems/core/lib → lib}/core/hash.rb +12 -0
- data/{gems/core/lib → lib}/core/kernel.rb +114 -86
- data/lib/core/match_data.rb +33 -0
- data/lib/core/module.rb +97 -0
- data/{gems/core/lib → lib}/core/nil_class.rb +0 -0
- data/{gems/core/lib → lib}/core/numeric.rb +5 -0
- data/{gems/core/lib → lib}/core/object.rb +0 -0
- data/{gems/core/lib → lib}/core/proc.rb +13 -3
- data/{gems/core/lib → lib}/core/range.rb +10 -0
- data/{gems/core/lib → lib}/core/regexp.rb +33 -1
- data/{gems/core/lib → lib}/core/string.rb +25 -10
- data/{gems/core/lib → lib}/core/symbol.rb +3 -3
- data/{gems/core/lib → lib}/core/top_self.rb +0 -0
- data/{gems/core/lib → lib}/core/true_class.rb +0 -0
- data/lib/dev.rb +169 -0
- data/{gems/ospec/lib → lib}/ospec.rb +1 -0
- data/lib/ospec/autorun.rb +8 -0
- data/{gems/ospec/lib → lib}/ospec/dsl.rb +2 -2
- data/{gems/ospec/lib → lib}/ospec/example.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/example/before_and_after_hooks.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/example/errors.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/example/example_group.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/example/example_group_factory.rb +0 -3
- data/{gems/ospec/lib → lib}/ospec/example/example_group_hierarchy.rb +4 -3
- data/{gems/ospec/lib → lib}/ospec/example/example_group_methods.rb +1 -1
- data/{gems/ospec/lib → lib}/ospec/example/example_group_proxy.rb +3 -2
- data/{gems/ospec/lib → lib}/ospec/example/example_methods.rb +1 -1
- data/{gems/ospec/lib → lib}/ospec/example/example_proxy.rb +7 -7
- data/{gems/ospec/lib → lib}/ospec/expectations.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/expectations/errors.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/expectations/fail_with.rb +4 -3
- data/{gems/ospec/lib → lib}/ospec/expectations/handler.rb +6 -0
- data/lib/ospec/helpers/scratch.rb +18 -0
- data/{gems/ospec/lib → lib}/ospec/matchers.rb +2 -2
- data/{gems/ospec/lib → lib}/ospec/matchers/be.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/matchers/generated_descriptions.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/matchers/operator_matcher.rb +2 -0
- data/lib/ospec/matchers/raise_error.rb +38 -0
- data/lib/ospec/runner.rb +90 -0
- data/{gems/ospec/lib → lib}/ospec/runner/example_group_runner.rb +10 -13
- data/lib/ospec/runner/formatter/html_formatter.rb +139 -0
- data/{gems/ospec/lib → lib}/ospec/runner/formatter/terminal_formatter.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/runner/options.rb +1 -3
- data/{gems/ospec/lib → lib}/ospec/runner/reporter.rb +0 -9
- data/lib/racc/parser.rb +165 -0
- data/lib/strscan.rb +52 -0
- data/{lib → opal_lib}/opal.rb +2 -0
- data/opal_lib/opal/build_methods.rb +51 -0
- data/opal_lib/opal/builder.rb +164 -0
- data/opal_lib/opal/bundle.rb +70 -0
- data/opal_lib/opal/command.rb +68 -0
- data/{lib → opal_lib}/opal/context.rb +21 -9
- data/{lib → opal_lib}/opal/context/console.rb +0 -2
- data/opal_lib/opal/context/file_system.rb +34 -0
- data/{lib → opal_lib}/opal/context/loader.rb +26 -8
- data/opal_lib/opal/gem.rb +84 -0
- data/{lib → opal_lib}/opal/rake/builder_task.rb +2 -2
- data/opal_lib/opal/rake/spec_task.rb +32 -0
- data/{lib → opal_lib}/opal/ruby/nodes.rb +730 -109
- data/{lib → opal_lib}/opal/ruby/parser.rb +90 -23
- data/opal_lib/opal/ruby/ruby_parser.rb +4862 -0
- data/opal_lib/opal/ruby/ruby_parser.y +1454 -0
- data/opal_lib/opal/version.rb +4 -0
- data/runtime/class.js +359 -0
- data/runtime/debug.js +84 -0
- data/runtime/fs.js +199 -0
- data/runtime/init.js +558 -0
- data/runtime/loader.js +351 -0
- data/runtime/module.js +109 -0
- data/runtime/post.js +10 -0
- data/runtime/pre.js +7 -0
- data/runtime/runtime.js +351 -0
- metadata +88 -175
- data/.gitignore +0 -7
- data/Changelog +0 -31
- data/LICENSE +0 -75
- data/Rakefile +0 -86
- data/gems/core/README.md +0 -14
- data/gems/core/Rakefile +0 -8
- data/gems/core/core.gemspec +0 -13
- data/gems/core/lib/core.rb +0 -34
- data/gems/core/lib/core/class.rb +0 -31
- data/gems/core/lib/core/module.rb +0 -100
- data/gems/core/lib/core/vm.rb +0 -16
- data/gems/core/spec/core/array/append_spec.rb +0 -30
- data/gems/core/spec/core/array/assoc_spec.rb +0 -29
- data/gems/core/spec/core/array/at_spec.rb +0 -37
- data/gems/core/spec/core/array/clear_spec.rb +0 -22
- data/gems/core/spec/core/array/collect_bang_spec.rb +0 -27
- data/gems/core/spec/core/array/collect_spec.rb +0 -27
- data/gems/core/spec/core/array/compact_spec.rb +0 -41
- data/gems/core/spec/core/array/concat_spec.rb +0 -15
- data/gems/core/spec/core/array/constructor_spec.rb +0 -14
- data/gems/core/spec/core/array/each_spec.rb +0 -9
- data/gems/core/spec/core/array/element_reference_spec.rb +0 -4
- data/gems/core/spec/core/array/first_spec.rb +0 -35
- data/gems/core/spec/core/array/include_spec.rb +0 -9
- data/gems/core/spec/core/array/join_spec.rb +0 -6
- data/gems/core/spec/core/array/last_spec.rb +0 -51
- data/gems/core/spec/core/array/length_spec.rb +0 -6
- data/gems/core/spec/core/array/map_spec.rb +0 -33
- data/gems/core/spec/core/array/reverse_spec.rb +0 -6
- data/gems/core/spec/core/builtin_constants/builtin_constants_spec.rb +0 -7
- data/gems/core/spec/core/false/and_spec.rb +0 -10
- data/gems/core/spec/core/false/inspect_spec.rb +0 -6
- data/gems/core/spec/core/false/or_spec.rb +0 -10
- data/gems/core/spec/core/false/to_s_spec.rb +0 -6
- data/gems/core/spec/core/false/xor_spec.rb +0 -10
- data/gems/core/spec/core/file/join_spec.rb +0 -19
- data/gems/core/spec/core/hash/assoc_spec.rb +0 -32
- data/gems/core/spec/core/kernel/instance_eval_spec.rb +0 -0
- data/gems/core/spec/core/kernel/loop_spec.rb +0 -24
- data/gems/core/spec/core/kernel/raise_spec.rb +0 -0
- data/gems/core/spec/core/module/attr_accessor_spec.rb +0 -28
- data/gems/core/spec/core/number/lt_spec.rb +0 -12
- data/gems/core/spec/core/string/sub_spec.rb +0 -24
- data/gems/core/spec/core/true/and_spec.rb +0 -10
- data/gems/core/spec/core/true/inspect_spec.rb +0 -6
- data/gems/core/spec/core/true/or_spec.rb +0 -10
- data/gems/core/spec/core/true/to_s_spec.rb +0 -6
- data/gems/core/spec/core/true/xor_spec.rb +0 -10
- data/gems/core/spec/language/and_spec.rb +0 -61
- data/gems/core/spec/language/array_spec.rb +0 -68
- data/gems/core/spec/language/block_spec.rb +0 -38
- data/gems/core/spec/language/break_spec.rb +0 -36
- data/gems/core/spec/language/case_spec.rb +0 -103
- data/gems/core/spec/language/def_spec.rb +0 -21
- data/gems/core/spec/language/eigenclass_spec.rb +0 -60
- data/gems/core/spec/language/file_spec.rb +0 -13
- data/gems/core/spec/language/fixtures/block.rb +0 -21
- data/gems/core/spec/language/fixtures/super.rb +0 -293
- data/gems/core/spec/language/hash_spec.rb +0 -29
- data/gems/core/spec/language/if_spec.rb +0 -54
- data/gems/core/spec/language/loop_spec.rb +0 -11
- data/gems/core/spec/language/metaclass_spec.rb +0 -21
- data/gems/core/spec/language/method_spec.rb +0 -124
- data/gems/core/spec/language/next_spec.rb +0 -25
- data/gems/core/spec/language/or_spec.rb +0 -34
- data/gems/core/spec/language/redo_spec.rb +0 -24
- data/gems/core/spec/language/regexp_spec.rb +0 -26
- data/gems/core/spec/language/rescue_spec.rb +0 -20
- data/gems/core/spec/language/return_spec.rb +0 -47
- data/gems/core/spec/language/string_spec.rb +0 -25
- data/gems/core/spec/language/super_spec.rb +0 -32
- data/gems/core/spec/language/until_spec.rb +0 -157
- data/gems/core/spec/language/variables_spec.rb +0 -155
- data/gems/core/spec/language/while_spec.rb +0 -163
- data/gems/core/spec/spec_helper.rb +0 -5
- data/gems/core_fs/README.md +0 -19
- data/gems/dev/Rakefile +0 -5
- data/gems/dev/lib/dev.js +0 -99
- data/gems/dev/lib/dev/generator.js +0 -1264
- data/gems/dev/lib/dev/parser.js +0 -979
- data/gems/dev/lib/dev/ruby_parser.js +0 -1088
- data/gems/dev/lib/dev/ruby_parser.y +0 -1267
- data/gems/dev/lib/dev/string_scanner.js +0 -38
- data/gems/dev/tools/racc2js/README.md +0 -39
- data/gems/dev/tools/racc2js/math_parser.js +0 -222
- data/gems/dev/tools/racc2js/math_parser.rb +0 -133
- data/gems/dev/tools/racc2js/math_parser.y +0 -28
- data/gems/dev/tools/racc2js/parser.js +0 -218
- data/gems/dev/tools/racc2js/racc2js.rb +0 -153
- data/gems/json/README.md +0 -4
- data/gems/json/json.gemspec +0 -14
- data/gems/json/lib/json.rb +0 -64
- data/gems/json/lib/json/ext.rb +0 -51
- data/gems/json/lib/json/json2.js +0 -481
- data/gems/ospec/README.md +0 -0
- data/gems/ospec/lib/ospec/autorun.rb +0 -3
- data/gems/ospec/lib/ospec/runner.rb +0 -40
- data/gems/ospec/lib/ospec/runner/formatter/html_formatter.rb +0 -91
- data/gems/ospec/ospec.gemspec +0 -0
- data/gems/rquery/README.md +0 -9
- data/gems/rquery/lib/rquery.rb +0 -10
- data/gems/rquery/lib/rquery/ajax.rb +0 -4
- data/gems/rquery/lib/rquery/css.rb +0 -96
- data/gems/rquery/lib/rquery/document.rb +0 -25
- data/gems/rquery/lib/rquery/element.rb +0 -292
- data/gems/rquery/lib/rquery/event.rb +0 -108
- data/gems/rquery/lib/rquery/jquery.js +0 -8177
- data/gems/rquery/lib/rquery/request.rb +0 -138
- data/gems/rquery/lib/rquery/response.rb +0 -49
- data/gems/rquery/rquery.gemspec +0 -16
- data/lib/opal.js +0 -1597
- data/lib/opal/builder.rb +0 -117
- data/lib/opal/bundle.rb +0 -131
- data/lib/opal/command.rb +0 -11
- data/lib/opal/context/file_system.rb +0 -19
- data/lib/opal/gem.rb +0 -153
- data/lib/opal/ruby/ruby_parser.rb +0 -5170
- data/lib/opal/ruby/ruby_parser.y +0 -1298
- data/opal.gemspec +0 -15
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "Array#assoc" do
|
|
3
|
-
it "returns the first array whose 1st item is == obj or nil" do
|
|
4
|
-
s1 = ["colors", "red", "blue", "green"]
|
|
5
|
-
s2 = [:letters, "a", "b", "c"]
|
|
6
|
-
s3 = [4]
|
|
7
|
-
s4 = ["colors", "cyan", "yellow", "magenda"]
|
|
8
|
-
s5 = [:letters, "a", "i", "u"]
|
|
9
|
-
s_nil = [nil, nil]
|
|
10
|
-
a = [s1, s2, s3, s4, s5, s_nil]
|
|
11
|
-
a.assoc(s1.first).should == s1
|
|
12
|
-
a.assoc(s2.first).should == s2
|
|
13
|
-
a.assoc(s3.first).should == s3
|
|
14
|
-
a.assoc(s4.first).should == s1
|
|
15
|
-
a.assoc(s5.first).should == s2
|
|
16
|
-
a.assoc(s_nil.first).should == s_nil
|
|
17
|
-
a.assoc(4).should == s3
|
|
18
|
-
a.assoc("key not in array").should == nil
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "ignores any non-Array elements" do
|
|
22
|
-
[1, 2, 3].assoc(2).should == nil
|
|
23
|
-
s1 = [4]
|
|
24
|
-
s2 = [5, 4, 3]
|
|
25
|
-
a = ["foo", [], s1, s2, nil, []]
|
|
26
|
-
a.assoc(s1.first).should == s1
|
|
27
|
-
a.assoc(s2.first).should == s2
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "Array#at" do
|
|
3
|
-
it "returns the (n+1)'th element for the passed index n" do
|
|
4
|
-
a = [1, 2, 3, 4, 5, 6]
|
|
5
|
-
a.at(0).should == 1
|
|
6
|
-
a.at(1).should == 2
|
|
7
|
-
a.at(5).should == 6
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it "returns nil if the given index is greater than or equal to the array's length" do
|
|
11
|
-
a = [1, 2, 3, 4, 5, 6]
|
|
12
|
-
a.at(6).should == nil
|
|
13
|
-
a.at(7).should == nil
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "returns the (-n)'th element from the last, for the given negative index n" do
|
|
17
|
-
a = [1, 2, 3, 4, 5, 6]
|
|
18
|
-
a.at(-1).should == 6
|
|
19
|
-
a.at(-2).should == 5
|
|
20
|
-
a.at(-6).should == 1
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "returns nil if the given index is less than -len, where len is the length of the array" do
|
|
24
|
-
a = [1, 2, 3, 4, 5, 6]
|
|
25
|
-
a.at(-7).should == nil
|
|
26
|
-
a.at(-8).should == nil
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "does not extend the array unless the given index is out of range" do
|
|
30
|
-
a = [1, 2, 3, 4, 5, 6]
|
|
31
|
-
a.length.should == 6
|
|
32
|
-
a.at(100)
|
|
33
|
-
a.length.should == 6
|
|
34
|
-
a.at(-100)
|
|
35
|
-
a.length.should == 6
|
|
36
|
-
end
|
|
37
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "Array#clear" do
|
|
3
|
-
it "removes all elements" do
|
|
4
|
-
a = [1, 2, 3, 4]
|
|
5
|
-
a.clear
|
|
6
|
-
# # a.clear.should == a
|
|
7
|
-
a.should == []
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it "returns self" do
|
|
11
|
-
a = [1]
|
|
12
|
-
oid = a.object_id
|
|
13
|
-
a.clear.object_id.should == oid
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "leaves the Array empty" do
|
|
17
|
-
a = [1]
|
|
18
|
-
a.clear
|
|
19
|
-
a.empty?.should == true
|
|
20
|
-
a.size.should == 0
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "Array#collect!" do
|
|
3
|
-
it "replaces each element with the value returned by block" do
|
|
4
|
-
a = [7, 9, 3, 5]
|
|
5
|
-
a.collect! { |i| i - 1 }
|
|
6
|
-
a.should == [6, 8, 2, 4]
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it "returns self" do
|
|
10
|
-
a = [1, 2, 3, 4, 5]
|
|
11
|
-
b = a.collect! { |i| i + 1 }
|
|
12
|
-
a.object_id.should == b.object_id
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "returns the evaluated value of block but its contents is partially modified, if it broke in the block" do
|
|
16
|
-
a = ['a', 'b', 'c', 'd']
|
|
17
|
-
b = a.collect! do |i|
|
|
18
|
-
if i == 'c'
|
|
19
|
-
break 0
|
|
20
|
-
else
|
|
21
|
-
i + '!'
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
b.should == 0
|
|
25
|
-
a.should == ['a!', 'b!', 'c', 'd']
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "Array#collect" do
|
|
3
|
-
it "returns a copy of array with each element replaced by the value returned by block" do
|
|
4
|
-
a = ['a', 'b', 'c', 'd']
|
|
5
|
-
b = a.collect { |i| i + '!'}
|
|
6
|
-
b.should == ['a!', 'b!', 'c!', 'd!']
|
|
7
|
-
# a.object_id.should_not == a.object_id
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it "does not change self" do
|
|
11
|
-
a = ['a', 'b', 'c', 'd']
|
|
12
|
-
b = a.collect { |i| i + '!' }
|
|
13
|
-
a.should == ['a', 'b', 'c', 'd']
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "returns the evaluated value of the block if it broke in the block" do
|
|
17
|
-
a = ['a', 'b', 'c', 'd']
|
|
18
|
-
b = a.collect do |i|
|
|
19
|
-
if i == 'c'
|
|
20
|
-
break 0
|
|
21
|
-
else
|
|
22
|
-
i + '!'
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
b.should == 0
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "Array#compact" do
|
|
3
|
-
it "returns a copy of array with all nil elements removed" do
|
|
4
|
-
a = [1, 2, 4]
|
|
5
|
-
a.compact.should == [1, 2, 4]
|
|
6
|
-
a = [1, nil, 2, 4]
|
|
7
|
-
a.compact.should == [1, 2, 4]
|
|
8
|
-
a = [1, 2, 4, nil]
|
|
9
|
-
a.compact.should == [1, 2, 4]
|
|
10
|
-
a = [nil, 1, 2, 4]
|
|
11
|
-
a.compact.should == [1, 2, 4]
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "does not return self" do
|
|
15
|
-
a = [1, 2, 3]
|
|
16
|
-
a.compact.object_id.should_not == a.object_id
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe "Array#compact!" do
|
|
21
|
-
it "removes all nil elements" do
|
|
22
|
-
a = ['a', nil, 'b', false, 'c']
|
|
23
|
-
a.compact!.object_id.should == a.object_id
|
|
24
|
-
a.should == ['a', 'b', false, 'c']
|
|
25
|
-
a = [nil, 'a', 'b', false, 'c']
|
|
26
|
-
a.compact!.object_id.should == a.object_id
|
|
27
|
-
a.should == ['a', 'b', false, 'c']
|
|
28
|
-
a = ['a', 'b', false, 'c', nil]
|
|
29
|
-
a.compact!.object_id.should == a.object_id
|
|
30
|
-
a.should == ['a', 'b', false, 'c']
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "returns self if some nil elements are removed" do
|
|
34
|
-
a = ['a', nil, 'b', false, 'c']
|
|
35
|
-
a.compact!.object_id.should == a.object_id
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "returns nil if there are no nil elements to remove" do
|
|
39
|
-
[1, 2, false, 3].compact!.should == nil
|
|
40
|
-
end
|
|
41
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "Array#concat" do
|
|
3
|
-
it "appends the elements in the other array" do
|
|
4
|
-
ary = [1, 2, 3]
|
|
5
|
-
ary.concat([9, 10, 11])
|
|
6
|
-
ary.should == [1, 2, 3, 9, 10, 11]
|
|
7
|
-
ary.concat []
|
|
8
|
-
ary.should == [1, 2, 3, 9, 10, 11]
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "does not loop endlessly when argument is self" do
|
|
12
|
-
ary = ["x", "y"]
|
|
13
|
-
ary.concat(ary).should == ["x", "y", "x", "y"]
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "Array.[]" do
|
|
3
|
-
it "returns a new array populated with the given elements" do
|
|
4
|
-
obj = Object.new
|
|
5
|
-
Array.[](5, true, nil, 'a', "Ruby", obj).should == [5, true, nil, 'a', "Ruby", obj]
|
|
6
|
-
end
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
describe "Array[]" do
|
|
10
|
-
it "is a synonym for .[]" do
|
|
11
|
-
obj = Object.new
|
|
12
|
-
Array[5, true, nil, 'a', "Ruby", obj].should == [5, true, nil, 'a', "Ruby", obj]
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "Array#first" do
|
|
3
|
-
it "returns the first element" do
|
|
4
|
-
# %W{a b c}.first.should == 'a'
|
|
5
|
-
[nil].first.should == nil
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
it "returns nil if self is empty" do
|
|
9
|
-
[].first.should == nil
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "returns the first count elements if given a count" do
|
|
13
|
-
[true, false, true, nil, false].first(2).should == [true, false]
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "returns an empty array when passed count on an empty array" do
|
|
17
|
-
[].first(0).should == []
|
|
18
|
-
[].first(1).should == []
|
|
19
|
-
[].first(2).should == []
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "returns an empty array when passed count == 0" do
|
|
23
|
-
[1, 2, 3, 4, 5].first(0).should == []
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "returns an array containing the first element when passed count == 1" do
|
|
27
|
-
[1, 2, 3, 4, 5].first(1).should == [1]
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "raises an argument error when count is negative"
|
|
31
|
-
|
|
32
|
-
it "returns the entire array when count > length" do
|
|
33
|
-
[1, 2, 3, 4, 5, 6, 7, 8, 9].first(10).should == [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
34
|
-
end
|
|
35
|
-
end
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "Array#last" do
|
|
3
|
-
it "returns the last element" do
|
|
4
|
-
[1, 1, 1, 1, 2].last.should == 2
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
it "returns nil if self is empty" do
|
|
8
|
-
[].last.should == nil
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "returns the last count elements if given a count" do
|
|
12
|
-
[1, 2, 3, 4, 5, 9].last(3).should == [4, 5, 9]
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "returns an empty array when passeed a count on an empty array" do
|
|
16
|
-
[].last(0).should == []
|
|
17
|
-
[].last(1).should == []
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "returns an empty array when count == 0" do
|
|
21
|
-
[1, 2, 3, 4, 5].last(0).should == []
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "returns an array containing the last element when passed count == 1" do
|
|
25
|
-
[1, 2, 3, 4, 5].last(1).should == [5]
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "returns the entire array when count > length" do
|
|
29
|
-
[1, 2, 3, 4, 5, 9].last(10).should == [1, 2, 3, 4, 5, 9]
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "returns an array which is independant to the original when passed count" do
|
|
33
|
-
ary = [1, 2, 3, 4, 5]
|
|
34
|
-
ary.last(0).replace([1, 2])
|
|
35
|
-
ary.should == [1, 2, 3, 4, 5]
|
|
36
|
-
ary.last(1).replace([1, 2])
|
|
37
|
-
ary.should == [1, 2, 3, 4, 5]
|
|
38
|
-
ary.last(6).replace([1, 2])
|
|
39
|
-
ary.should == [1, 2, 3, 4, 5]
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "is not destructive" do
|
|
43
|
-
a = [1, 2, 3]
|
|
44
|
-
a.last
|
|
45
|
-
a.should == [1, 2, 3]
|
|
46
|
-
a.last(2)
|
|
47
|
-
a.should == [1, 2, 3]
|
|
48
|
-
a.last(3)
|
|
49
|
-
a.should == [1, 2, 3]
|
|
50
|
-
end
|
|
51
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "Array#map" do
|
|
3
|
-
it "returns a copy of array with each element replaced by the value returned by block" do
|
|
4
|
-
a = ['a', 'b', 'c', 'd']
|
|
5
|
-
b = a.map { |i| i + '!' }
|
|
6
|
-
b.should == ['a!', 'b!', 'c!', 'd!']
|
|
7
|
-
|
|
8
|
-
# ignore
|
|
9
|
-
# b.object_id.should_not == a.object_id
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "does not return subclass instance"
|
|
13
|
-
|
|
14
|
-
it "does not change self" do
|
|
15
|
-
a = ['a', 'b', 'c', 'd']
|
|
16
|
-
b = a.map { |i| i + '!' }
|
|
17
|
-
a.should == ['a', 'b', 'c', 'd']
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "returns the evaluated value of the block if it broke in the block" do
|
|
21
|
-
a = ['a', 'b', 'c', 'd']
|
|
22
|
-
b = a.map { |i|
|
|
23
|
-
if i == 'c'
|
|
24
|
-
break 0
|
|
25
|
-
else
|
|
26
|
-
i + '!'
|
|
27
|
-
end
|
|
28
|
-
}
|
|
29
|
-
b.should == 0
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "returns an enumerator when no block given"
|
|
33
|
-
end
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "FalseClass#|" do
|
|
3
|
-
it "returns false if other is nil or false, otherwise true" do
|
|
4
|
-
(false | false).should == false
|
|
5
|
-
(false | true).should == true
|
|
6
|
-
(false | nil).should == false
|
|
7
|
-
(false | "").should == true
|
|
8
|
-
(false | 'x').should == true
|
|
9
|
-
end
|
|
10
|
-
end
|