diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-28 09:20:03 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-28 09:20:03 +0000 |
commit | 1011775a395e901aa897301dc5fecb9270fc1646 (patch) | |
tree | b05880a19cf90ba3fe5790f9cd9e5d4b55059013 /test/ruby | |
parent | a40ca8c047d8c174d1757dcbc82ec16185144717 (diff) |
introduces r21693 again and merges r21713
* array.c (take_items), enum.c (enum_zip): tries to convert to
array first. [ruby-core:21442]
--
* array.c (take_items): to_ary() raises ArgumentError if cannot to
convert to Array. [ruby-dev:37797]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@21814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_array.rb | 8 | ||||
-rw-r--r-- | test/ruby/test_enum.rb | 8 |
2 files changed, 16 insertions, 0 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 9edd31dfa7..1cd018be85 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -1502,6 +1502,14 @@ class TestArray < Test::Unit::TestCase a = [] [1, 2, 3].zip([:a, :b], ["a", "b", "c", "d"]) {|x| a << x } assert_equal([[1, :a, "a"], [2, :b, "b"], [3, nil, "c"]], a) + + ary = Object.new + def ary.to_a; [1, 2]; end + assert_raise(NoMethodError){ %w(a b).zip(ary) } + def ary.each; [3, 4].each{|e|yield e}; end + assert_equal([['a', 3], ['b', 4]], %w(a b).zip(ary)) + def ary.to_ary; [5, 6]; end + assert_equal([['a', 5], ['b', 6]], %w(a b).zip(ary)) end def test_transpose diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index ed82d7787f..a8a88640bd 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -211,6 +211,14 @@ class TestEnumerable < Test::Unit::TestCase a = [] @obj.zip([:a, :b, :c]) {|x,y| a << [x, y] } assert_equal([[1,:a],[2,:b],[3,:c],[1,nil],[2,nil]], a) + + ary = Object.new + def ary.to_a; [1, 2]; end + assert_raise(NoMethodError){ %w(a b).zip(ary) } + def ary.each; [3, 4].each{|e|yield e}; end + assert_equal([[1, 3], [2, 4], [3, nil], [1, nil], [2, nil]], @obj.zip(ary)) + def ary.to_ary; [5, 6]; end + assert_equal([[1, 5], [2, 6], [3, nil], [1, nil], [2, nil]], @obj.zip(ary)) end def test_take |