diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-10-29 17:47:24 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-10-29 17:47:24 +0000 |
commit | 525336fcc97a0c0fc8dae2e6f9fe63dfc6e645ab (patch) | |
tree | 23b84c6d3aa98723fea6577ecedbb3d15a49baba /test/ruby | |
parent | 2e0b6e28ada7713aab10343c2850f32dec4652ac (diff) | |
download | ruby-525336fcc97a0c0fc8dae2e6f9fe63dfc6e645ab.tar.gz |
* eval.c (proc_invoke): single array value to normal Proc#call
(i.e. not via lambda call), should be treated just like yield.
[ruby-dev:21726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_assignment.rb | 14 | ||||
-rw-r--r-- | test/ruby/test_iterator.rb | 26 |
2 files changed, 33 insertions, 7 deletions
diff --git a/test/ruby/test_assignment.rb b/test/ruby/test_assignment.rb index e78021558f..51d1c780f8 100644 --- a/test/ruby/test_assignment.rb +++ b/test/ruby/test_assignment.rb @@ -130,13 +130,13 @@ class TestAssignment < Test::Unit::TestCase def f; yield; end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])} def f; yield nil; end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])} def f; yield 1; end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])} - def f; yield []; end; f {|a,b,*c| assert_equal([[],nil,[]], [a,b,c])} - def f; yield [1]; end; f {|a,b,*c| assert_equal([[1],nil,[]], [a,b,c])} - def f; yield [nil]; end; f {|a,b,*c| assert_equal([[nil],nil,[]], [a,b,c])} - def f; yield [[]]; end; f {|a,b,*c| assert_equal([[[]],nil,[]], [a,b,c])} - def f; yield [*[]]; end; f {|a,b,*c| assert_equal([[],nil,[]], [a,b,c])} - def f; yield [*[1]]; end; f {|a,b,*c| assert_equal([[1],nil,[]], [a,b,c])} - def f; yield [*[1,2]]; end; f {|a,b,*c| assert_equal([[1,2],nil,[]], [a,b,c])} + def f; yield []; end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])} + def f; yield [1]; end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])} + def f; yield [nil]; end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])} + def f; yield [[]]; end; f {|a,b,*c| assert_equal([[],nil,[]], [a,b,c])} + def f; yield [*[]]; end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])} + def f; yield [*[1]]; end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])} + def f; yield [*[1,2]]; end; f {|a,b,*c| assert_equal([1,2,[]], [a,b,c])} def f; yield *nil; end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])} def f; yield *1; end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])} diff --git a/test/ruby/test_iterator.rb b/test/ruby/test_iterator.rb index 60bfad50a9..c8631653f3 100644 --- a/test/ruby/test_iterator.rb +++ b/test/ruby/test_iterator.rb @@ -328,6 +328,32 @@ class TestIterator < Test::Unit::TestCase lambda(&get_block{|a,n| assert(a,n)}).call(true, "marity") end + def foo + yield([:key, :value]) + end + def bar(&blk) + blk.call([:key, :value]) + end + + def test_yield_vs_call + foo{|k,v| assert_equal([:key, :value], [k,v])} + bar{|k,v| assert_equal([:key, :value], [k,v])} + end + + class H + def each + yield [:key, :value] + end + end + + def test_assoc_yield + [{:key=>:value}, H.new].each {|h| + h.each{|a| assert_equal([:key, :value], a)} + h.each{|*a| assert_equal([[:key, :value]], a)} + h.each{|k,v| assert_equal([:key, :value], [k,v])} + } + end + class ITER_TEST1 def a block_given? |