implements resolve_method on parfait type
with associated changes to class adds note about the not being the final version
This commit is contained in:
@ -16,6 +16,7 @@ class TestClass < MiniTest::Test
|
||||
assert_equal :Object , @try.super_class_name
|
||||
end
|
||||
def test_new_superclass
|
||||
assert_equal "Class(Object)" , @try.super_class!.inspect
|
||||
assert_equal "Class(Object)" , @try.super_class.inspect
|
||||
end
|
||||
def test_new_methods
|
||||
@ -31,7 +32,7 @@ class TestClass < MiniTest::Test
|
||||
def test_remove_method
|
||||
assert_equal false , @try.remove_instance_method( :foo)
|
||||
end
|
||||
def test_add_method
|
||||
def test_add_nil_method_raises
|
||||
assert_raises{ @try.add_instance_method(nil)}
|
||||
end
|
||||
def test_add_instance_variable_changes_type
|
||||
|
@ -9,28 +9,33 @@ class TestMethodApi < MiniTest::Test
|
||||
@try_type = @try_class.instance_type
|
||||
end
|
||||
|
||||
def foo_method for_class = :Try
|
||||
def foo_method( for_class = :Try)
|
||||
args = Parfait::Type.for_hash( @try_class , { bar: :Integer})
|
||||
::Parfait::TypedMethod.new @space.get_class_by_name(for_class).instance_type , :foo , args
|
||||
end
|
||||
|
||||
def add_foo_to( clazz = :Try )
|
||||
foo = foo_method( clazz )
|
||||
assert_equal foo , @space.get_class_by_name(clazz).instance_type.add_method(foo)
|
||||
foo
|
||||
end
|
||||
def object_type
|
||||
@space.get_class_by_name(:Object).instance_type
|
||||
end
|
||||
def test_new_methods
|
||||
assert_equal @try_type.method_names.class, @try_type.methods.class
|
||||
assert_equal @try_type.method_names.get_length , @try_type.methods.get_length
|
||||
end
|
||||
|
||||
def test_add_method
|
||||
before = @try_type.methods.get_length
|
||||
foo = foo_method
|
||||
assert_equal foo , @try_type.add_method(foo)
|
||||
add_foo_to
|
||||
assert_equal 1 , @try_type.methods.get_length - before
|
||||
assert @try_type.method_names.inspect.include?(":foo")
|
||||
end
|
||||
def test_remove_method
|
||||
test_add_method
|
||||
add_foo_to
|
||||
assert_equal true , @try_type.remove_method(:foo)
|
||||
end
|
||||
def test_remove_nothere
|
||||
def test_remove_not_there
|
||||
assert_raises RuntimeError do
|
||||
@try_type.remove_method(:foo)
|
||||
end
|
||||
@ -41,7 +46,7 @@ class TestMethodApi < MiniTest::Test
|
||||
assert @try_type.method_names.inspect.include?("bar")
|
||||
end
|
||||
def test_method_get
|
||||
test_add_method
|
||||
add_foo_to
|
||||
assert_equal Parfait::TypedMethod , @try_type.get_method(:foo).class
|
||||
end
|
||||
def test_method_get_nothere
|
||||
@ -55,4 +60,20 @@ class TestMethodApi < MiniTest::Test
|
||||
type.add_method(foo)
|
||||
assert_equal :foo , type.get_method(:foo).name
|
||||
end
|
||||
def test_resolve_on_object
|
||||
add_foo_to :Object
|
||||
assert_equal :foo , object_type.resolve_method( :foo ).name
|
||||
end
|
||||
def test_resolve_super
|
||||
add_foo_to :Object
|
||||
assert_equal :foo , @try_class.instance_type.resolve_method( :foo ).name
|
||||
end
|
||||
def test_resolve_is_get
|
||||
add_foo_to
|
||||
assert_equal :foo , @try_class.instance_type.resolve_method( :foo ).name
|
||||
assert_equal :foo , @try_class.instance_type.get_method( :foo ).name
|
||||
end
|
||||
def test_resolve_fail
|
||||
assert_nil object_type.resolve_method( :foo )
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user