diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-11-28 04:19:37 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-11-28 04:19:37 +0000 |
commit | 46e3b0fe7b1d39bd783d1bab539f5624e80d73d6 (patch) | |
tree | 35e2e4ad9d9d9965b6642e264779787213490b93 /test/ruby/test_proc.rb | |
parent | 4d3f3af83689790f21b344abbfbe6bbdd483813e (diff) | |
download | ruby-46e3b0fe7b1d39bd783d1bab539f5624e80d73d6.tar.gz |
* iseq.c (simple_default_value): extracts simplest default
argument value.
* iseq.c (rb_iseq_parameters): returns parameter list.
* proc.c (get_proc_iseq, get_method_iseq): handles ifunc and
bmethod.
* proc.c (rb_proc_parameters, rb_method_parameters): added
Proc#parameters and Method#parameters. [ruby-core:19759]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_proc.rb')
-rw-r--r-- | test/ruby/test_proc.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb index 83ef8f38dd..79668a69a2 100644 --- a/test/ruby/test_proc.rb +++ b/test/ruby/test_proc.rb @@ -673,4 +673,47 @@ class TestProc < Test::Unit::TestCase }.call(1,2,3,4,5) assert_equal([1,2,[3],4,5], r, "[ruby-core:19485]") end + + def test_parameters + assert_equal([], proc {}.parameters) + assert_equal([], proc {||}.parameters) + assert_equal([[:req, :a]], proc {|a|}.parameters) + assert_equal([[:req, :a], [:req, :b]], proc {|a, b|}.parameters) + assert_equal([[:opt, :a, :a], [:block, :b]], proc {|a=:a, &b|}.parameters) + assert_equal([[:req, :a], [:opt, :b, :b]], proc {|a, b=:b|}.parameters) + assert_equal([[:rest, :a]], proc {|*a|}.parameters) + assert_equal([[:req, :a], [:rest, :b], [:block, :c]], proc {|a, *b, &c|}.parameters) + assert_equal([[:req, :a], [:rest, :b], [:req, :c]], proc {|a, *b, c|}.parameters) + assert_equal([[:req, :a], [:rest, :b], [:req, :c], [:block, :d]], proc {|a, *b, c, &d|}.parameters) + assert_equal([[:req, :a], [:opt, :b, :b], [:rest, :c], [:req, :d], [:block, :e]], proc {|a, b=:b, *c, d, &e|}.parameters) + assert_equal([[:req], [:block, :b]], proc {|(a), &b|}.parameters) + assert_equal([[:req, :a], [:req, :b], [:opt, :c, :c], [:opt, :d, :d], [:rest, :e], [:req, :f], [:req, :g], [:block, :h]], proc {|a,b,c=:c,d=:d,*e,f,g,&h|}.parameters) + end + + def pm0() end + def pm1(a) end + def pm2(a, b) end + def pmo1(a = :a, &b) end + def pmo2(a, b = :b) end + def pmo3(*a) end + def pmo4(a, *b, &c) end + def pmo5(a, *b, c) end + def pmo6(a, *b, c, &d) end + def pmo7(a, b = :b, *c, d, &e) end + def pma1((a), &b) end + + + def test_bound_parameters + assert_equal([], method(:pm0).to_proc.parameters) + assert_equal([[:req, :a]], method(:pm1).to_proc.parameters) + assert_equal([[:req, :a], [:req, :b]], method(:pm2).to_proc.parameters) + assert_equal([[:opt, :a, :a], [:block, :b]], method(:pmo1).to_proc.parameters) + assert_equal([[:req, :a], [:opt, :b, :b]], method(:pmo2).to_proc.parameters) + assert_equal([[:rest, :a]], method(:pmo3).to_proc.parameters) + assert_equal([[:req, :a], [:rest, :b], [:block, :c]], method(:pmo4).to_proc.parameters) + assert_equal([[:req, :a], [:rest, :b], [:req, :c]], method(:pmo5).to_proc.parameters) + assert_equal([[:req, :a], [:rest, :b], [:req, :c], [:block, :d]], method(:pmo6).to_proc.parameters) + assert_equal([[:req, :a], [:opt, :b, :b], [:rest, :c], [:req, :d], [:block, :e]], method(:pmo7).to_proc.parameters) + assert_equal([[:req], [:block, :b]], method(:pma1).to_proc.parameters) + end end |