1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
require 'test_helper'
require 'tins/xt'
module Tins
class MethodDescriptionTest < Test::Unit::TestCase
class A
def foo
end
def self.foo
end
end
def test_static_nonstatic
assert_equal 'Tins::MethodDescriptionTest::A#foo()', A.instance_method(:foo).to_s
assert_equal '#<UnboundMethod: Tins::MethodDescriptionTest::A#foo()>', A.instance_method(:foo).inspect
assert_equal 'Tins::MethodDescriptionTest::A.foo()', A.method(:foo).to_s
assert_equal '#<Method: Tins::MethodDescriptionTest::A.foo()>', A.method(:foo).inspect
end
class B
def foo(x, y = 1, *r, &b)
end
def bar(x, y = 2, *r, &b)
end
def bar2(x, z = 2, *r, &b)
end
def baz(x, y = 2, z = 3, *r, &b)
end
end
def test_standard_parameters_namespace
assert_equal 'Tins::MethodDescriptionTest::B#foo(x,y=?,*r,&b)',
B.instance_method(:foo).to_s
end
def test_standard_parameters_name
assert_equal 'foo(x,y=?,*r,&b)',
B.instance_method(:foo).description(style: :name)
end
def test_standard_parameters_signature
assert_kind_of Tins::MethodDescription::Signature,
B.instance_method(:foo).signature
end
def test_signature_equalitites
assert_equal(
B.instance_method(:foo).signature,
B.instance_method(:bar).signature
)
assert_equal(
B.instance_method(:foo).signature,
B.instance_method(:bar2).signature
)
assert_false\
B.instance_method(:foo).signature.eql?(
B.instance_method(:bar2).signature
)
assert_operator(
B.instance_method(:foo).signature,
:===,
B.instance_method(:bar2)
)
assert_not_equal(
B.instance_method(:bar).signature,
B.instance_method(:baz).signature
)
end
def test_a_cstyle_method_from_hash
assert_equal "Hash#store(x1,x2)", ({}.method(:store).description)
end
class C
def foo(x, k: true, &b)
end
def bar(x, **k, &b)
end
end
def test_keyword_parameters
assert_equal 'Tins::MethodDescriptionTest::C#foo(x,k:?,&b)', C.instance_method(:foo).to_s
assert_equal 'Tins::MethodDescriptionTest::C#bar(x,**k,&b)', C.instance_method(:bar).to_s
end
if RUBY_VERSION >= "2.1"
eval %{
class D
def foo(x, k:, &b)
end
end
def test_keyword_parameters_required
assert_equal 'Tins::MethodDescriptionTest::D#foo(x,k:,&b)', D.instance_method(:foo).to_s
end
}
end
end
end
|