mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/ruby/test_method.rb: added. [ruby-dev:26761]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8946 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0b1038f514
commit
f613a10f5e
2 changed files with 46 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
|||
Mon Aug 8 20:40:35 2005 NAKAMURA, Hiroshi <nakahiro@sarion.co.jp>
|
||||
|
||||
* test/ruby/test_method.rb: added. [ruby-dev:26761]
|
||||
|
||||
Mon Aug 8 01:26:37 2005 Mauricio Fernandez <mfp@acm.org>
|
||||
|
||||
* parse.y (f_larglist): mistake in syntax rule. [ruby-core:05535]
|
||||
|
|
42
test/ruby/test_method.rb
Normal file
42
test/ruby/test_method.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require 'test/unit'
|
||||
|
||||
class TestMethod < Test::Unit::TestCase
|
||||
def m0() end
|
||||
def m1(a) end
|
||||
def m2(a, b) end
|
||||
def mo1(a = nil, &b) end
|
||||
def mo2(a, b = nil) end
|
||||
def mo3(*a) end
|
||||
def mo4(a, *b, &c) end
|
||||
|
||||
class Base
|
||||
def foo() :base end
|
||||
end
|
||||
class Derived < Base
|
||||
def foo() :derived end
|
||||
end
|
||||
|
||||
def test_arity
|
||||
assert_equal(0, method(:m0).arity)
|
||||
assert_equal(1, method(:m1).arity)
|
||||
assert_equal(2, method(:m2).arity)
|
||||
assert_equal(-1, method(:mo1).arity)
|
||||
assert_equal(-2, method(:mo2).arity)
|
||||
assert_equal(-1, method(:mo3).arity)
|
||||
assert_equal(-2, method(:mo4).arity)
|
||||
end
|
||||
|
||||
def test_unbind
|
||||
assert_equal(:derived, Derived.new.foo)
|
||||
um = Derived.new.method(:foo).unbind
|
||||
assert_instance_of(UnboundMethod, um)
|
||||
Derived.class_eval do
|
||||
def foo() :changed end
|
||||
end
|
||||
assert_equal(:changed, Derived.new.foo)
|
||||
assert_equal(:derived, um.bind(Derived.new).call)
|
||||
assert_raise(TypeError) do
|
||||
um.bind(Base.new)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue