2019-02-16 22:24:16 +01:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Parfait
|
2019-09-23 19:57:33 +02:00
|
|
|
class TestSingletonClass < ParfaitTest
|
2019-02-16 22:24:16 +01:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
2019-09-24 16:25:19 +02:00
|
|
|
@try = @space.create_class( :Try , :Object).single_class
|
2019-02-16 22:24:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_type_forclass
|
|
|
|
assert_equal "Class(Space)" , @space.get_type.object_class.inspect
|
|
|
|
assert_equal :Space , @space.get_type.object_class.name
|
|
|
|
end
|
|
|
|
def test_new_superclass_name
|
|
|
|
assert_equal :Object , @try.clazz.super_class_name
|
|
|
|
end
|
|
|
|
def test_new_superclass
|
|
|
|
assert_equal "Class(Try)" , @try.clazz.inspect
|
2019-09-23 19:57:33 +02:00
|
|
|
assert_equal "SingletonClass(Try)" , @try.inspect
|
2019-02-16 22:24:16 +01:00
|
|
|
end
|
|
|
|
def test_new_methods
|
|
|
|
assert_equal @try.method_names.class, @try.instance_methods.class
|
|
|
|
assert_equal @try.method_names.get_length , @try.instance_methods.get_length
|
|
|
|
end
|
|
|
|
def test_remove_nothere
|
|
|
|
assert !@try.remove_instance_method(:foo)
|
|
|
|
end
|
|
|
|
def test_resolve
|
|
|
|
assert_nil @try.resolve_method :foo
|
|
|
|
end
|
|
|
|
def test_remove_method
|
|
|
|
assert_equal false , @try.remove_instance_method( :foo)
|
|
|
|
end
|
|
|
|
def test_add_nil_method_raises
|
|
|
|
assert_raises{ @try.add_instance_method(nil)}
|
|
|
|
end
|
|
|
|
def test_add_instance_variable_changes_type
|
2019-09-23 19:42:46 +02:00
|
|
|
before = @try.instance_type
|
|
|
|
@try.add_instance_variable(:counter , :Integer)
|
|
|
|
assert before != @try.instance_type
|
2019-02-16 22:24:16 +01:00
|
|
|
end
|
|
|
|
def test_add_instance_variable_changes_type_hash
|
2019-09-23 19:42:46 +02:00
|
|
|
before = @try.instance_type.hash
|
|
|
|
@try.add_instance_variable(:counter , :Integer)
|
|
|
|
assert before != @try.instance_type.hash
|
|
|
|
end
|
|
|
|
def test_add_instance_variable_changes_class_type
|
|
|
|
@try.add_instance_variable(:counter , :Integer)
|
|
|
|
assert_equal @try.clazz.type , @try.instance_type
|
2019-02-16 22:24:16 +01:00
|
|
|
end
|
2019-09-30 16:09:13 +02:00
|
|
|
def test_name
|
|
|
|
assert_equal :"Try.Single" , @try.name
|
|
|
|
end
|
|
|
|
def test_type_is_single
|
|
|
|
assert_equal true , @try.instance_type.is_single?
|
|
|
|
end
|
2019-10-01 19:55:05 +02:00
|
|
|
def test_super_class
|
|
|
|
assert_equal SingletonClass , @try.super_class.class
|
|
|
|
end
|
|
|
|
def test_super_class_name
|
|
|
|
assert_equal :"Object.Single" , @try.super_class_name
|
|
|
|
end
|
2019-02-16 22:24:16 +01:00
|
|
|
end
|
|
|
|
end
|