diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-06 18:39:36 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-06 18:39:36 +0000 |
commit | 929e0b91be4ddf58b5d0791f538862a872203f93 (patch) | |
tree | 876cf927985459d507eb71e3325d00692290f957 /sample | |
parent | 04d3593b26ccf65e930bebbc6e47cc37bfd557bd (diff) | |
download | ruby-929e0b91be4ddf58b5d0791f538862a872203f93.tar.gz |
* parse.y (f_block_optarg): allow default for block parameters as
long as the value is primary. a patch from Eric Mahurin
<eric.mahurin at gmail.com> in [ruby-core:16880].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19199 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample')
-rw-r--r-- | sample/test.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/sample/test.rb b/sample/test.rb index 3f24bd071a..34e96204af 100644 --- a/sample/test.rb +++ b/sample/test.rb @@ -296,6 +296,64 @@ test_ok(f.call([[42]]) == [[[42]]]) test_ok(f.call([42,55]) == [[42,55]]) test_ok(f.call(42,55) == [42,55]) +f = lambda { |a, b=42, *c| [a,b,c] } +test_ok(f.call(1 ) == [1,42,[ ]] ) +test_ok(f.call(1,43 ) == [1,43,[ ]] ) +test_ok(f.call(1,43,44) == [1,43,[44]] ) + +f = lambda { |a, b=(a|16), *c, &block| [a,b,c,block&&block[]] } +test_ok(f.call(8 ) == [8,24,[ ],nil] ) +test_ok(f.call(8,43 ) == [8,43,[ ],nil] ) +test_ok(f.call(8,43,44) == [8,43,[44],nil] ) +test_ok(f.call(8 ){45} == [8,24,[ ],45 ] ) +test_ok(f.call(8,43 ){45} == [8,43,[ ],45 ] ) +test_ok(f.call(8,43,44){45} == [8,43,[44],45 ] ) + +f = lambda { |a, b=42, *c, d| [a,b,c,d] } +test_ok(f.call(1 ,99) == [1,42,[ ],99] ) +test_ok(f.call(1,43 ,99) == [1,43,[ ],99] ) +test_ok(f.call(1,43,44,99) == [1,43,[44],99] ) + +f = lambda { |a, b=(a|16), &block| [a,b,block&&block[]] } +test_ok(f.call(8 ) == [8,24,nil] ) +test_ok(f.call(8,43) == [8,43,nil] ) +test_ok(f.call(8,43) == [8,43,nil] ) +test_ok(f.call(8 ){45} == [8,24,45 ] ) +test_ok(f.call(8,43){45} == [8,43,45 ] ) +test_ok(f.call(8,43){45} == [8,43,45 ] ) + +f = lambda { |a, b=42, d| [a,b,d] } +test_ok(f.call(1 ,99) == [1,42,99] ) +test_ok(f.call(1,43,99) == [1,43,99] ) +test_ok(f.call(1,43,99) == [1,43,99] ) + +f = lambda { |b=42, *c, &block| [b,c,block&&block[]] } +test_ok(f.call( ) == [42,[ ],nil] ) +test_ok(f.call(43 ) == [43,[ ],nil] ) +test_ok(f.call(43,44) == [43,[44],nil] ) +test_ok(f.call( ){45} == [42,[ ],45 ] ) +test_ok(f.call(43 ){45} == [43,[ ],45 ] ) +test_ok(f.call(43,44){45} == [43,[44],45 ] ) + +f = lambda { |b=42, *c, d| [b,c,d] } +test_ok(f.call( 99) == [42,[ ],99] ) +test_ok(f.call(43 ,99) == [43,[ ],99] ) +test_ok(f.call(43,44,99) == [43,[44],99] ) + +f = lambda { |b=42, &block| [b,block&&block[]] } +test_ok(f.call( ) == [42,nil] ) +test_ok(f.call(43) == [43,nil] ) +test_ok(f.call(43) == [43,nil] ) +test_ok(f.call( ){45} == [42,45 ] ) +test_ok(f.call(43){45} == [43,45 ] ) +test_ok(f.call(43){45} == [43,45 ] ) + +f = lambda { |b=42, d| [b,d] } +test_ok(f.call( 99) == [42,99] ) +test_ok(f.call(43,99) == [43,99] ) +test_ok(f.call(43,99) == [43,99] ) + + a,=*[1] test_ok(a == 1) a,=*[[1]] |