opal 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +3 -0
- data/.travis.yml +0 -4
- data/README.md +6 -0
- data/Rakefile +30 -6
- data/bin/opal +6 -82
- data/corelib/{opal/array.rb → array.rb} +40 -56
- data/corelib/{opal/basic_object.rb → basic_object.rb} +2 -2
- data/corelib/{opal/boolean.rb → boolean.rb} +0 -8
- data/corelib/class.rb +47 -0
- data/corelib/{opal/comparable.rb → comparable.rb} +0 -0
- data/corelib/{opal/enumerable.rb → enumerable.rb} +208 -141
- data/corelib/{opal/enumerator.rb → enumerator.rb} +3 -3
- data/corelib/{opal/error.rb → error.rb} +1 -0
- data/corelib/{opal/hash.rb → hash.rb} +67 -56
- data/corelib/io.rb +39 -0
- data/corelib/{opal/kernel.rb → kernel.rb} +35 -31
- data/corelib/{opal/class.rb → module.rb} +29 -57
- data/corelib/native.rb +148 -0
- data/corelib/{opal/nil_class.rb → nil_class.rb} +2 -10
- data/corelib/{opal/numeric.rb → numeric.rb} +39 -14
- data/corelib/opal.rb +42 -25
- data/corelib/{opal/proc.rb → proc.rb} +3 -3
- data/corelib/{opal/range.rb → range.rb} +5 -1
- data/corelib/{opal/regexp.rb → regexp.rb} +0 -0
- data/corelib/{opal/runtime.js → runtime.js} +96 -188
- data/corelib/{opal/string.rb → string.rb} +20 -15
- data/corelib/struct.rb +139 -0
- data/corelib/{opal/time.rb → time.rb} +0 -0
- data/lib/opal.rb +4 -0
- data/lib/opal/cli.rb +79 -32
- data/lib/opal/cli_options.rb +91 -0
- data/lib/opal/erb.rb +41 -8
- data/lib/opal/grammar.rb +24 -10
- data/lib/opal/grammar.y +15 -4
- data/lib/opal/grammar_helpers.rb +4 -0
- data/lib/opal/lexer.rb +214 -143
- data/lib/opal/parser.rb +596 -562
- data/lib/opal/require_parser.rb +1 -1
- data/lib/opal/source_map.rb +15 -30
- data/lib/opal/target_scope.rb +24 -5
- data/lib/opal/version.rb +1 -1
- data/mri_spec/cli_spec.rb +18 -0
- data/mri_spec/fixtures/opal_file.rb +2 -0
- data/mri_spec/spec_helper.rb +17 -0
- data/opal.gemspec +5 -2
- data/spec/{rubyspec/filters → filters}/bugs/alias.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/ancestors.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array.rb +0 -0
- data/spec/filters/bugs/array/combination.rb +11 -0
- data/spec/filters/bugs/array/count.rb +3 -0
- data/spec/filters/bugs/array/delete_if.rb +3 -0
- data/spec/filters/bugs/array/drop.rb +3 -0
- data/spec/filters/bugs/array/drop_while.rb +5 -0
- data/spec/filters/bugs/array/eql.rb +3 -0
- data/spec/filters/bugs/array/flatten.rb +9 -0
- data/spec/filters/bugs/array/minus.rb +5 -0
- data/spec/filters/bugs/array/multipliy.rb +9 -0
- data/spec/filters/bugs/array/new.rb +3 -0
- data/spec/filters/bugs/array/pop.rb +6 -0
- data/spec/filters/bugs/array/rassoc.rb +4 -0
- data/spec/filters/bugs/array/rindex.rb +6 -0
- data/spec/filters/bugs/array/select.rb +3 -0
- data/spec/filters/bugs/array/shift.rb +7 -0
- data/spec/filters/bugs/array/shuffle.rb +11 -0
- data/spec/filters/bugs/array/slice.rb +7 -0
- data/spec/filters/bugs/array/take.rb +3 -0
- data/spec/filters/bugs/array/to_a.rb +3 -0
- data/spec/filters/bugs/array/try_convert.rb +7 -0
- data/spec/filters/bugs/array/uniq.rb +10 -0
- data/spec/filters/bugs/array/zip.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_delete.rb +1 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_fetch.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_first.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_flatten.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_intersection.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_join.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/break.rb +0 -0
- data/spec/filters/bugs/case.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/coerce_integer.rb +0 -0
- data/spec/filters/bugs/enumerable_sort_by.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/kernel/instance_variables.rb +0 -0
- data/spec/filters/bugs/kernel/rand.rb +4 -0
- data/spec/filters/bugs/language/array.rb +3 -0
- data/spec/filters/bugs/language/block.rb +6 -0
- data/spec/filters/bugs/language/break.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class_variables.rb +0 -0
- data/spec/filters/bugs/language/def.rb +27 -0
- data/spec/filters/bugs/language/defined.rb +3 -0
- data/spec/filters/bugs/language/ensure.rb +4 -0
- data/spec/filters/bugs/language/execution.rb +4 -0
- data/spec/filters/bugs/language/for.rb +18 -0
- data/spec/filters/bugs/language/if.rb +13 -0
- data/spec/filters/bugs/language/loop.rb +4 -0
- data/spec/filters/bugs/language/metaclass.rb +14 -0
- data/spec/filters/bugs/language/module.rb +6 -0
- data/spec/filters/bugs/language/next.rb +3 -0
- data/spec/filters/bugs/language/or.rb +3 -0
- data/spec/filters/bugs/language/order.rb +4 -0
- data/spec/filters/bugs/language/precedence.rb +10 -0
- data/spec/filters/bugs/language/proc.rb +24 -0
- data/spec/filters/bugs/language/redo.rb +5 -0
- data/spec/filters/bugs/language/rescue.rb +9 -0
- data/spec/filters/bugs/language/retry.rb +5 -0
- data/spec/filters/bugs/language/send.rb +10 -0
- data/spec/filters/bugs/language/super.rb +9 -0
- data/spec/filters/bugs/language/until.rb +8 -0
- data/spec/filters/bugs/language/variables.rb +37 -0
- data/spec/filters/bugs/language/while.rb +6 -0
- data/spec/filters/bugs/language/yield.rb +5 -0
- data/spec/{rubyspec/filters → filters}/bugs/module/class_variables.rb +0 -0
- data/spec/filters/bugs/module/method_defined.rb +6 -0
- data/spec/filters/bugs/parser.rb +10 -0
- data/spec/{rubyspec/filters → filters}/bugs/public_methods.rb +1 -0
- data/spec/filters/bugs/return.rb +7 -0
- data/spec/filters/bugs/singleton/instance.rb +4 -0
- data/spec/filters/bugs/source_map.rb +3 -0
- data/spec/filters/bugs/string/center.rb +4 -0
- data/spec/filters/bugs/string/lines.rb +3 -0
- data/spec/{rubyspec/filters → filters}/mspec/mocks.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/ruby_exe.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/should_receive.rb +0 -0
- data/spec/{rubyspec/filters → filters}/parser/block_args.rb +0 -0
- data/spec/{rubyspec/filters → filters}/unsupported/array_subclasses.rb +1 -0
- data/spec/filters/unsupported/frozen.rb +32 -0
- data/spec/filters/unsupported/immutable_strings.rb +3 -0
- data/spec/filters/unsupported/tainted.rb +17 -0
- data/spec/filters/unsupported/trusted.rb +15 -0
- data/spec/opal/class/constants_spec.rb +7 -0
- data/spec/opal/erb/erb_spec.rb +7 -1
- data/spec/opal/erb/inline_block.opalerb +3 -0
- data/spec/opal/hash/allocate_spec.rb +16 -0
- data/spec/opal/hash/new_spec.rb +10 -0
- data/spec/opal/hash/to_s_spec.rb +9 -0
- data/spec/opal/kernel/instance_variable_defined_spec.rb +15 -0
- data/spec/opal/kernel/rand_spec.rb +5 -5
- data/spec/opal/kernel/respond_to_spec.rb +14 -1
- data/spec/opal/language/block_spec.rb +13 -0
- data/spec/opal/language/rescue_spec.rb +27 -0
- data/spec/opal/language/return_spec.rb +38 -0
- data/spec/opal/language/singleton_class_spec.rb +13 -0
- data/spec/opal/language/super_spec.rb +99 -0
- data/spec/opal/language/variables_spec.rb +20 -0
- data/spec/opal/module/attr_accessor_spec.rb +8 -0
- data/spec/opal/module/constants_spec.rb +2 -2
- data/spec/opal/native/alias_native_spec.rb +18 -0
- data/spec/opal/native/each_spec.rb +14 -0
- data/spec/opal/native/element_reference_spec.rb +14 -0
- data/spec/opal/native/method_missing_spec.rb +39 -0
- data/spec/opal/native/new_spec.rb +19 -0
- data/spec/opal/native/nil_spec.rb +14 -0
- data/spec/opal/runtime2/class_hierarchy_spec.rb +2 -2
- data/spec/opal/source_map_spec.rb +3 -7
- data/spec/ospec/main.rb.erb +2 -5
- data/spec/parser/alias_spec.rb +4 -4
- data/spec/parser/and_spec.rb +2 -2
- data/spec/parser/array_spec.rb +6 -6
- data/spec/parser/attrasgn_spec.rb +8 -8
- data/spec/parser/begin_spec.rb +11 -11
- data/spec/parser/block_spec.rb +3 -3
- data/spec/parser/break_spec.rb +4 -4
- data/spec/parser/call_spec.rb +50 -48
- data/spec/parser/class_spec.rb +2 -2
- data/spec/parser/const_spec.rb +1 -1
- data/spec/parser/cvar_spec.rb +1 -1
- data/spec/parser/def_spec.rb +5 -5
- data/spec/parser/gvar_spec.rb +2 -2
- data/spec/parser/hash_spec.rb +4 -4
- data/spec/parser/iasgn_spec.rb +3 -3
- data/spec/parser/if_spec.rb +6 -6
- data/spec/parser/iter_spec.rb +6 -6
- data/spec/parser/lambda_spec.rb +5 -5
- data/spec/parser/lasgn_spec.rb +2 -2
- data/spec/parser/line_spec.rb +2 -2
- data/spec/parser/lvar_spec.rb +5 -5
- data/spec/parser/masgn_spec.rb +1 -1
- data/spec/parser/module_spec.rb +2 -2
- data/spec/parser/not_spec.rb +4 -4
- data/spec/parser/op_asgn1_spec.rb +2 -2
- data/spec/parser/op_asgn2_spec.rb +2 -2
- data/spec/parser/or_spec.rb +2 -2
- data/spec/parser/parse_spec.rb +66 -0
- data/spec/parser/parser_spec.rb +32 -38
- data/spec/parser/regexp_spec.rb +4 -4
- data/spec/parser/return_spec.rb +4 -4
- data/spec/parser/sclass_spec.rb +4 -4
- data/spec/parser/str_spec.rb +3 -3
- data/spec/parser/super_spec.rb +6 -6
- data/spec/parser/undef_spec.rb +3 -3
- data/spec/parser/unless_spec.rb +4 -4
- data/spec/parser/while_spec.rb +3 -3
- data/spec/parser/xstr_spec.rb +3 -3
- data/spec/parser/yield_spec.rb +6 -6
- data/spec/rubyspec/core/array/drop_spec.rb +1 -1
- data/spec/rubyspec/core/array/keep_if_spec.rb +1 -3
- data/spec/rubyspec/core/array/length_spec.rb +1 -3
- data/spec/rubyspec/core/array/map_spec.rb +2 -6
- data/spec/rubyspec/core/array/minus_spec.rb +3 -3
- data/spec/rubyspec/core/array/multiply_spec.rb +14 -16
- data/spec/rubyspec/core/array/new_spec.rb +3 -5
- data/spec/rubyspec/core/array/plus_spec.rb +2 -2
- data/spec/rubyspec/core/array/pop_spec.rb +4 -4
- data/spec/rubyspec/core/array/rassoc_spec.rb +2 -2
- data/spec/rubyspec/core/array/reject_spec.rb +2 -6
- data/spec/rubyspec/core/array/replace_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_each_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_spec.rb +4 -4
- data/spec/rubyspec/core/array/rindex_spec.rb +1 -1
- data/spec/rubyspec/core/array/select_spec.rb +3 -7
- data/spec/rubyspec/core/array/shared/collect.rb +7 -0
- data/spec/rubyspec/core/array/shared/index.rb +1 -1
- data/spec/rubyspec/core/array/shared/keep_if.rb +3 -0
- data/spec/rubyspec/core/array/shared/length.rb +3 -0
- data/spec/rubyspec/core/array/shared/replace.rb +3 -0
- data/spec/rubyspec/core/array/shared/slice.rb +3 -0
- data/spec/rubyspec/core/array/shuffle_spec.rb +1 -1
- data/spec/rubyspec/core/array/size_spec.rb +1 -3
- data/spec/rubyspec/core/array/slice_spec.rb +4 -6
- data/spec/rubyspec/core/array/sort_spec.rb +2 -2
- data/spec/rubyspec/core/array/to_a_spec.rb +1 -1
- data/spec/rubyspec/core/array/try_convert_spec.rb +7 -7
- data/spec/rubyspec/core/array/uniq_spec.rb +7 -7
- data/spec/rubyspec/core/array/zip_spec.rb +1 -1
- data/spec/rubyspec/core/enumerable/collect_spec.rb +24 -0
- data/spec/rubyspec/core/enumerable/count_spec.rb +35 -19
- data/spec/rubyspec/core/enumerable/find_spec.rb +5 -0
- data/spec/rubyspec/core/hash/each_pair_spec.rb +7 -7
- data/spec/rubyspec/core/hash/each_spec.rb +13 -7
- data/spec/rubyspec/core/module/method_defined_spec.rb +4 -4
- data/spec/rubyspec/core/module/public_method_defined_spec.rb +19 -0
- data/spec/rubyspec/core/module/remove_const_spec.rb +23 -0
- data/spec/rubyspec/core/numeric/step_spec.rb +14 -0
- data/spec/rubyspec/core/string/center_spec.rb +43 -65
- data/spec/rubyspec/core/string/lines_spec.rb +1 -1
- data/spec/rubyspec/core/string/ljust_spec.rb +25 -9
- data/spec/rubyspec/core/string/rjust_spec.rb +26 -10
- data/spec/rubyspec/core/struct/fixtures/classes.rb +26 -0
- data/spec/rubyspec/core/struct/initialize_spec.rb +11 -0
- data/spec/rubyspec/core/struct/new_spec.rb +24 -0
- data/spec/rubyspec/fixtures/constants.rb +7 -0
- data/spec/rubyspec/language/break_spec.rb +1 -1
- data/spec/rubyspec/language/case_spec.rb +30 -30
- data/spec/rubyspec/language/def_spec.rb +34 -34
- data/spec/rubyspec/language/defined_spec.rb +2 -2
- data/spec/rubyspec/language/ensure_spec.rb +2 -2
- data/spec/rubyspec/language/execution_spec.rb +2 -2
- data/spec/rubyspec/language/for_spec.rb +17 -17
- data/spec/rubyspec/language/hash_spec.rb +3 -3
- data/spec/rubyspec/language/if_spec.rb +11 -11
- data/spec/rubyspec/language/loop_spec.rb +3 -3
- data/spec/rubyspec/language/metaclass_spec.rb +14 -14
- data/spec/rubyspec/language/module_spec.rb +6 -6
- data/spec/rubyspec/language/next_spec.rb +5 -5
- data/spec/rubyspec/language/not_spec.rb +1 -1
- data/spec/rubyspec/language/or_spec.rb +1 -1
- data/spec/rubyspec/language/order_spec.rb +3 -5
- data/spec/rubyspec/language/precedence_spec.rb +19 -19
- data/spec/rubyspec/language/proc_spec.rb +29 -29
- data/spec/rubyspec/language/redo_spec.rb +3 -5
- data/spec/rubyspec/language/rescue_spec.rb +7 -7
- data/spec/rubyspec/language/retry_spec.rb +2 -2
- data/spec/rubyspec/language/return_spec.rb +12 -12
- data/spec/rubyspec/language/send_spec.rb +9 -9
- data/spec/rubyspec/language/singleton_class_spec.rb +3 -4
- data/spec/rubyspec/language/super_spec.rb +7 -11
- data/spec/rubyspec/language/until_spec.rb +10 -10
- data/spec/rubyspec/language/variables_spec.rb +59 -67
- data/spec/rubyspec/language/versions/array_1.9.rb +1 -1
- data/spec/rubyspec/language/versions/block_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/break_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/literal_lambda_1.9.rb +12 -12
- data/spec/rubyspec/language/versions/send_1.9.rb +23 -23
- data/spec/rubyspec/language/versions/symbol_1.9.rb +2 -2
- data/spec/rubyspec/language/versions/variables_1.9.rb +1 -1
- data/spec/rubyspec/language/while_spec.rb +4 -4
- data/spec/rubyspec/language/yield_spec.rb +3 -3
- data/spec/rubyspec/library/erb/util/html_escape_spec.rb +10 -0
- data/spec/rubyspec/library/singleton/clone_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/dup_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/fixtures/classes.rb +18 -0
- data/spec/rubyspec/library/singleton/instance_spec.rb +30 -0
- data/spec/spec_helper.rb +214 -0
- data/stdlib/buffer.rb +40 -0
- data/stdlib/buffer/array.rb +66 -0
- data/stdlib/buffer/view.rb +70 -0
- data/stdlib/erb.rb +11 -20
- data/stdlib/forwardable.rb +71 -0
- data/stdlib/json.rb +78 -0
- data/stdlib/ostruct.rb +69 -0
- data/stdlib/rbconfig.rb +1 -0
- data/stdlib/singleton.rb +40 -0
- data/stdlib/stringio.rb +173 -0
- data/stdlib/template.rb +44 -0
- metadata +285 -79
- data/corelib/opal/native.rb +0 -31
- data/spec/opal/class/bridge_class_spec.rb +0 -39
- data/spec/opal/native_spec.rb +0 -209
- data/spec/ospec/runner.rb +0 -223
- data/spec/rubyspec/filters/bugs/block_args.rb +0 -3
- data/spec/rubyspec/filters/bugs/case.rb +0 -8
- data/spec/rubyspec/filters/bugs/language/module.rb +0 -3
- data/spec/rubyspec/filters/unsupported/frozen.rb +0 -4
- data/spec/rubyspec/filters/unsupported/tainted.rb +0 -7
@@ -1,29 +1,45 @@
|
|
1
1
|
require File.expand_path('../../../spec_helper', __FILE__)
|
2
2
|
require File.expand_path('../fixtures/classes', __FILE__)
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
ruby_version_is "1.8.7" do
|
5
|
+
describe "Enumerable#count" do
|
6
|
+
before :each do
|
7
|
+
@elements = [1, 2, 4, 2]
|
8
|
+
@numerous = EnumerableSpecs::Numerous.new(*@elements)
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
it "returns size when no argument or a block" do
|
12
|
+
@numerous.count.should == 4
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
it "counts nils if given nil as an argument" do
|
16
|
+
EnumerableSpecs::Numerous.new(nil, nil, nil, false).count(nil).should == 3
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
it "accepts an argument for comparison using ==" do
|
20
|
+
@numerous.count(2).should == 2
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
it "uses a block for comparison" do
|
24
|
+
@numerous.count{|x| x%2==0 }.should == 3
|
25
|
+
end
|
26
|
+
|
27
|
+
it "ignores the block when given an argument" do
|
28
|
+
@numerous.count(4){|x| x%2==0 }.should == 1
|
29
|
+
end
|
30
|
+
|
31
|
+
ruby_version_is ""..."1.9" do
|
32
|
+
it "gathers whole arrays as elements when each yields multiple" do
|
33
|
+
multi = EnumerableSpecs::YieldsMulti.new
|
34
|
+
multi.count {|e| e == [1, 2]}.should == 1
|
35
|
+
end
|
36
|
+
end
|
25
37
|
|
26
|
-
|
27
|
-
|
38
|
+
ruby_version_is "1.9" do
|
39
|
+
it "gathers initial args as elements when each yields multiple" do
|
40
|
+
multi = EnumerableSpecs::YieldsMulti.new
|
41
|
+
multi.count {|e| e == 1 }.should == 1
|
42
|
+
end
|
43
|
+
end
|
28
44
|
end
|
29
45
|
end
|
@@ -48,4 +48,9 @@ describe "Enumerable#find" do
|
|
48
48
|
fail_proc = lambda { "yay" }
|
49
49
|
@empty.find(fail_proc) {|e| true}.should == "yay"
|
50
50
|
end
|
51
|
+
|
52
|
+
it "gathers whole arrays as elements when each yields multiple" do
|
53
|
+
multi = EnumerableSpecs::YieldsMulti.new
|
54
|
+
multi.find {|e| e == [1, 2] }.should == [1, 2]
|
55
|
+
end
|
51
56
|
end
|
@@ -7,12 +7,12 @@ describe "Hash#each_pair" do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
# FIXME: should be: h.each { |k,| ary << k }
|
10
|
-
it "yields the key only to a block expecting |key,|" do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
10
|
+
#it "yields the key only to a block expecting |key,|" do
|
11
|
+
# ary = []
|
12
|
+
# h = {"a" => 1, "b" => 2, "c" => 3}
|
13
|
+
# h.each_pair { |k| ary << k }
|
14
|
+
# ary.should == ["a", "b", "c"]
|
15
|
+
#end
|
16
16
|
|
17
17
|
it "uses the same order as keys() and values()" do
|
18
18
|
h = {:a => 1, :b => 2, :c => 3, :d => 5}
|
@@ -27,4 +27,4 @@ describe "Hash#each_pair" do
|
|
27
27
|
keys.should == h.keys
|
28
28
|
values.should == h.values
|
29
29
|
end
|
30
|
-
end
|
30
|
+
end
|
@@ -1,4 +1,10 @@
|
|
1
1
|
describe "Hash#each" do
|
2
|
+
it "yields a [[key, value]] Array for each pair to a block expecting |*args|" do
|
3
|
+
all_args = []
|
4
|
+
{1 => 2, 3 => 4}.each { |*args| all_args << args }
|
5
|
+
all_args.sort.should == [[[1, 2]], [[3, 4]]]
|
6
|
+
end
|
7
|
+
|
2
8
|
it "yields the key and value of each pair to a block expecting |key, value|" do
|
3
9
|
r = {}
|
4
10
|
h = {:a => 1, :b => 2, :c => 3, :d => 5}
|
@@ -7,12 +13,12 @@ describe "Hash#each" do
|
|
7
13
|
end
|
8
14
|
|
9
15
|
# FIXME: should be: h.each { |k,| ary << k }
|
10
|
-
it "yields the key only to a block expecting |key,|" do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
+
#it "yields the key only to a block expecting |key,|" do
|
17
|
+
# ary = []
|
18
|
+
# h = {"a" => 1, "b" => 2, "c" => 3}
|
19
|
+
# h.each { |k| ary << k }
|
20
|
+
# ary.should == ["a", "b", "c"]
|
21
|
+
#end
|
16
22
|
|
17
23
|
it "uses the same order as keys() and values()" do
|
18
24
|
h = {:a => 1, :b => 2, :c => 3, :d => 5}
|
@@ -27,4 +33,4 @@ describe "Hash#each" do
|
|
27
33
|
keys.should == h.keys
|
28
34
|
values.should == h.values
|
29
35
|
end
|
30
|
-
end
|
36
|
+
end
|
@@ -2,7 +2,7 @@ require File.expand_path('../../../spec_helper', __FILE__)
|
|
2
2
|
require File.expand_path('../fixtures/classes', __FILE__)
|
3
3
|
|
4
4
|
describe "Module#method_defined?" do
|
5
|
-
|
5
|
+
it "returns true if a public or private method with the given name is defined in self, self's ancestors or one of self's included modules" do
|
6
6
|
# Defined in Child
|
7
7
|
ModuleSpecs::Child.method_defined?(:public_child).should == true
|
8
8
|
ModuleSpecs::Child.method_defined?("private_child").should == false
|
@@ -24,13 +24,13 @@ describe "Module#method_defined?" do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# unlike alias_method, module_function, public, and friends,
|
27
|
-
|
27
|
+
it "does not search Object or Kernel when called on a module" do
|
28
28
|
m = Module.new
|
29
29
|
|
30
30
|
m.method_defined?(:module_specs_public_method_on_kernel).should be_false
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
it "raises a TypeError when the given object is not a string/symbol/fixnum" do
|
34
34
|
c = Class.new
|
35
35
|
o = mock('123')
|
36
36
|
|
@@ -40,7 +40,7 @@ describe "Module#method_defined?" do
|
|
40
40
|
lambda { c.method_defined?(o) }.should raise_error(TypeError)
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
it "converts the given name to a string using to_str" do
|
44
44
|
c = Class.new { def test(); end }
|
45
45
|
(o = mock('test')).should_receive(:to_str).and_return("test")
|
46
46
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
|
4
|
+
describe "Module#public_method_defined?" do
|
5
|
+
it "returns true if the named public method is defined by module or its ancestors" do
|
6
|
+
ModuleSpecs::CountsMixin.public_method_defined?("public_3").should == true
|
7
|
+
|
8
|
+
ModuleSpecs::CountsParent.public_method_defined?("public_3").should == true
|
9
|
+
ModuleSpecs::CountsParent.public_method_defined?("public_2").should == true
|
10
|
+
|
11
|
+
ModuleSpecs::CountsChild.public_method_defined?("public_3").should == true
|
12
|
+
ModuleSpecs::CountsChild.public_method_defined?("public_2").should == true
|
13
|
+
ModuleSpecs::CountsChild.public_method_defined?("public_1").should == true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns false if the named method is not defined by the module or its ancestors" do
|
17
|
+
ModuleSpecs::CountsMixin.public_method_defined?(:public_10).should == false
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../../../fixtures/constants', __FILE__)
|
3
|
+
|
4
|
+
describe "Module#remove_const" do
|
5
|
+
it "removes the constant specified by a String or Symbol from the receiver's constant table" do
|
6
|
+
ConstantSpecs::ModuleM::CS_CONST252 = :const252
|
7
|
+
ConstantSpecs::ModuleM::CS_CONST252.should == :const252
|
8
|
+
|
9
|
+
ConstantSpecs::ModuleM.send :remove_const, :CS_CONST252
|
10
|
+
lambda { ConstantSpecs::ModuleM::CS_CONST252 }.should raise_error(NameError)
|
11
|
+
|
12
|
+
ConstantSpecs::ModuleM::CS_CONST253 = :const253
|
13
|
+
ConstantSpecs::ModuleM::CS_CONST253.should == :const253
|
14
|
+
|
15
|
+
ConstantSpecs::ModuleM.send :remove_const, "CS_CONST253"
|
16
|
+
lambda { ConstantSpecs::ModuleM::CS_CONST253 }.should raise_error(NameError)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns the value of the removed constant" do
|
20
|
+
ConstantSpecs::ModuleM::CS_CONST254 = :const254
|
21
|
+
ConstantSpecs::ModuleM.send(:remove_const, :CS_CONST254).should == :const254
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
#require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
|
4
|
+
describe "Numeric#step" do
|
5
|
+
before :each do
|
6
|
+
ScratchPad.record []
|
7
|
+
@prc = lambda { |x| ScratchPad << x }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "defaults to step = 1" do
|
11
|
+
1.step(5, &@prc)
|
12
|
+
ScratchPad.recorded.should == [1, 2, 3, 4, 5]
|
13
|
+
end
|
14
|
+
end
|
@@ -1,71 +1,49 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
3
|
+
require File.expand_path('../fixtures/classes.rb', __FILE__)
|
4
|
+
|
5
|
+
describe "String#center with length, padding" do
|
6
|
+
it "returns a new string of specified length with self centered and padded with padstr" do
|
7
|
+
"one".center(9, '.').should == "...one..."
|
8
|
+
"hello".center(20, '123').should == "1231231hello12312312"
|
9
|
+
"middle".center(13, '-').should == "---middle----"
|
10
|
+
|
11
|
+
"".center(1, "abcd").should == "a"
|
12
|
+
"".center(2, "abcd").should == "aa"
|
13
|
+
"".center(3, "abcd").should == "aab"
|
14
|
+
"".center(4, "abcd").should == "abab"
|
15
|
+
"".center(6, "xy").should == "xyxxyx"
|
16
|
+
"".center(11, "12345").should == "12345123451"
|
17
|
+
|
18
|
+
"|".center(2, "abcd").should == "|a"
|
19
|
+
"|".center(3, "abcd").should == "a|a"
|
20
|
+
"|".center(4, "abcd").should == "a|ab"
|
21
|
+
"|".center(5, "abcd").should == "ab|ab"
|
22
|
+
"|".center(6, "xy").should == "xy|xyx"
|
23
|
+
"|".center(7, "xy").should == "xyx|xyx"
|
24
|
+
"|".center(11, "12345").should == "12345|12345"
|
25
|
+
"|".center(12, "12345").should == "12345|123451"
|
26
|
+
|
27
|
+
"||".center(3, "abcd").should == "||a"
|
28
|
+
"||".center(4, "abcd").should == "a||a"
|
29
|
+
"||".center(5, "abcd").should == "a||ab"
|
30
|
+
"||".center(6, "abcd").should == "ab||ab"
|
31
|
+
"||".center(8, "xy").should == "xyx||xyx"
|
32
|
+
"||".center(12, "12345").should == "12345||12345"
|
33
|
+
"||".center(13, "12345").should == "12345||123451"
|
5
34
|
end
|
6
35
|
|
7
|
-
it "
|
8
|
-
"
|
36
|
+
it "pads with whitespace if no padstr is given" do
|
37
|
+
"two".center(5).should == " two "
|
38
|
+
"hello".center(20).should == " hello "
|
9
39
|
end
|
10
40
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
it "works with bigger patterns" do
|
21
|
-
"abc".center(7, '~!{').should == "~!abc~!"
|
22
|
-
end
|
23
|
-
|
24
|
-
it "repeats the pattern if needed" do
|
25
|
-
"abc".center(10, '~!{').should == "~!{abc~!{~"
|
26
|
-
end
|
41
|
+
it "returns self if it's longer than or as long as the specified length" do
|
42
|
+
"".center(0).should == ""
|
43
|
+
"".center(-1).should == ""
|
44
|
+
"hello".center(4).should == "hello"
|
45
|
+
"hello".center(-1).should == "hello"
|
46
|
+
"this".center(3).should == "this"
|
47
|
+
"radiology".center(8, '-').should == "radiology"
|
27
48
|
end
|
28
|
-
|
29
|
-
describe "centers an even string with an odd number of padding strings" do
|
30
|
-
it "uses default padding" do
|
31
|
-
"abcd".center(7).should == " abcd "
|
32
|
-
end
|
33
|
-
|
34
|
-
it "works with bigger patterns" do
|
35
|
-
"abcd".center(7, '~!{').should == "~abcd~!"
|
36
|
-
end
|
37
|
-
|
38
|
-
it "repeats the pattern if needed" do
|
39
|
-
"abcd".center(11, '~!{').should == "~!{abcd~!{~"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "centers an even string with an even number of padding strings" do
|
44
|
-
it "uses default padding" do
|
45
|
-
"abcd".center(8).should == " abcd "
|
46
|
-
end
|
47
|
-
|
48
|
-
it "works with bigger patterns" do
|
49
|
-
"abcd".center(8, '~!{').should == "~!abcd~!"
|
50
|
-
end
|
51
|
-
|
52
|
-
it "repeats the pattern if needed" do
|
53
|
-
"abcd".center(12, '~!{').should == "~!{~abcd~!{~"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "center an odd string with an even number" do
|
58
|
-
it "uses default padding" do
|
59
|
-
"abc".center(4).should == "abc "
|
60
|
-
end
|
61
|
-
|
62
|
-
it "works with bigger patterns" do
|
63
|
-
"abc".center(4, '~!{').should == "abc~"
|
64
|
-
end
|
65
|
-
|
66
|
-
it "repeats the pattern if needed" do
|
67
|
-
"abc".center(12, '~!{').should == "~!{~abc~!{~!"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
49
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
describe "String#lines" do
|
2
|
-
|
2
|
+
it "should split on the default record separator and return enumerator if not block is given" do
|
3
3
|
"first\nsecond\nthird".lines.class.should == Enumerator
|
4
4
|
"first\nsecond\nthird".lines.entries.class.should == Array
|
5
5
|
"first\nsecond\nthird".lines.entries.size.should == 3
|
@@ -1,17 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
3
|
+
require File.expand_path('../fixtures/classes.rb', __FILE__)
|
4
|
+
|
1
5
|
describe "String#ljust" do
|
2
|
-
it "
|
3
|
-
"
|
4
|
-
|
6
|
+
it "returns a new string of specified length with self left justified and padded with padstr" do
|
7
|
+
"hello".ljust(20, '1234').should == "hello123412341234123"
|
8
|
+
|
9
|
+
"".ljust(1, "abcd").should == "a"
|
10
|
+
"".ljust(2, "abcd").should == "ab"
|
11
|
+
"".ljust(3, "abcd").should == "abc"
|
12
|
+
"".ljust(4, "abcd").should == "abcd"
|
13
|
+
"".ljust(6, "abcd").should == "abcdab"
|
5
14
|
|
6
|
-
|
7
|
-
"
|
15
|
+
"OK".ljust(3, "abcd").should == "OKa"
|
16
|
+
"OK".ljust(4, "abcd").should == "OKab"
|
17
|
+
"OK".ljust(6, "abcd").should == "OKabcd"
|
18
|
+
"OK".ljust(8, "abcd").should == "OKabcdab"
|
8
19
|
end
|
9
20
|
|
10
|
-
it "
|
11
|
-
"
|
21
|
+
it "pads with whitespace if no padstr is given" do
|
22
|
+
"hello".ljust(20).should == "hello "
|
12
23
|
end
|
13
24
|
|
14
|
-
it "
|
15
|
-
"
|
25
|
+
it "returns self if it's longer than or as long as the specified length" do
|
26
|
+
"".ljust(0).should == ""
|
27
|
+
"".ljust(-1).should == ""
|
28
|
+
"hello".ljust(4).should == "hello"
|
29
|
+
"hello".ljust(-1).should == "hello"
|
30
|
+
"this".ljust(3).should == "this"
|
31
|
+
"radiology".ljust(8, '-').should == "radiology"
|
16
32
|
end
|
17
33
|
end
|
@@ -1,17 +1,33 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
3
|
+
require File.expand_path('../fixtures/classes.rb', __FILE__)
|
4
|
+
|
5
|
+
describe "String#rjust with length, padding" do
|
6
|
+
it "returns a new string of specified length with self right justified and padded with padstr" do
|
7
|
+
"hello".rjust(20, '1234').should == "123412341234123hello"
|
8
|
+
|
9
|
+
"".rjust(1, "abcd").should == "a"
|
10
|
+
"".rjust(2, "abcd").should == "ab"
|
11
|
+
"".rjust(3, "abcd").should == "abc"
|
12
|
+
"".rjust(4, "abcd").should == "abcd"
|
13
|
+
"".rjust(6, "abcd").should == "abcdab"
|
5
14
|
|
6
|
-
|
7
|
-
"
|
15
|
+
"OK".rjust(3, "abcd").should == "aOK"
|
16
|
+
"OK".rjust(4, "abcd").should == "abOK"
|
17
|
+
"OK".rjust(6, "abcd").should == "abcdOK"
|
18
|
+
"OK".rjust(8, "abcd").should == "abcdabOK"
|
8
19
|
end
|
9
20
|
|
10
|
-
it "
|
11
|
-
"
|
21
|
+
it "pads with whitespace if no padstr is given" do
|
22
|
+
"hello".rjust(20).should == " hello"
|
12
23
|
end
|
13
24
|
|
14
|
-
it "
|
15
|
-
"
|
25
|
+
it "returns self if it's longer than or as long as the specified length" do
|
26
|
+
"".rjust(0).should == ""
|
27
|
+
"".rjust(-1).should == ""
|
28
|
+
"hello".rjust(4).should == "hello"
|
29
|
+
"hello".rjust(-1).should == "hello"
|
30
|
+
"this".rjust(3).should == "this"
|
31
|
+
"radiology".rjust(8, '-').should == "radiology"
|
16
32
|
end
|
17
33
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module StructClasses
|
2
|
+
|
3
|
+
class Apple < Struct; end
|
4
|
+
|
5
|
+
Ruby = Struct.new(:version, :platform)
|
6
|
+
|
7
|
+
Car = Struct.new(:make, :model, :year)
|
8
|
+
|
9
|
+
class Honda < Car
|
10
|
+
def initialize(*args)
|
11
|
+
self.make = "Honda"
|
12
|
+
super(*args)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class SubclassX < Struct
|
17
|
+
end
|
18
|
+
|
19
|
+
class SubclassX
|
20
|
+
attr_reader :key
|
21
|
+
def initialize(*)
|
22
|
+
@key = :value
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|