generalize get_main and get_init to get_method

to get at those know methods that really
__must__ exists, hence the bang, raise if don't
about to add method missing and raise to the list
This commit is contained in:
2019-09-15 12:58:43 +03:00
parent b36ba42990
commit 7ee57f2b08
12 changed files with 100 additions and 77 deletions

View File

@ -45,28 +45,6 @@ module Parfait
def test_all_classes
assert_equal classes.length , @space.classes.length , @space.classes.keys.inspect
end
def test_types
assert @space.types.is_a? Parfait::Dictionary
end
def test_types_attr
assert @space.types.is_a? Parfait::Dictionary
end
def test_types_each
@space.each_type do |type|
assert type.is_a?(Parfait::Type)
end
end
def test_types_hashes
types = @space.types
types.each do |has , type|
assert has.is_a?(::Integer) , has.inspect
end
end
def test_classes_types_in_space_types
@space.classes do |name , clazz|
assert_equal clazz.instance_type , @space.get_type_for(clazz.instance_type.hash) , clazz.name
end
end
def test_word_class
word = @space.classes[:Word]
assert word.instance_type
@ -149,39 +127,6 @@ module Parfait
assert @space.get_class_by_name(:NewerClass)
end
def test_class_types_are_stored
@space.classes.each do |name,clazz|
assert @space.get_type_for(clazz.instance_type.hash)
end
end
def test_class_types_are_identical
@space.classes.each do |name , clazz|
cl_type = @space.get_type_for(clazz.instance_type.hash)
assert_equal cl_type.object_id , clazz.instance_type.object_id
end
end
def test_remove_methods
@space.each_type do | type |
type.method_names.each do |method|
type.remove_method(method)
end
end
assert_equal 0 , @space.get_all_methods.length
end
def test_no_methods_in_types
test_remove_methods
@space.each_type do |type|
assert_equal 0 , type.methods_length , "name #{type.name}"
end
end
def test_no_methods_in_classes
test_remove_methods
@space.classes.each do |name , cl|
assert_equal 0 , cl.instance_type.methods_length , "name #{cl.name}"
end
end
end
class BigTestSpace < BigParfaitTest
def test_address_count

View File

@ -0,0 +1,71 @@
require_relative "helper"
module Parfait
# Most type and method related stuff
class TestSpaceMethod < ParfaitTest
def test_types
assert @space.types.is_a? Parfait::Dictionary
end
def test_types_attr
assert @space.types.is_a? Parfait::Dictionary
end
def test_types_each
@space.each_type do |type|
assert type.is_a?(Parfait::Type)
end
end
def test_types_hashes
types = @space.types
types.each do |has , type|
assert has.is_a?(::Integer) , has.inspect
end
end
def test_classes_types_in_space_types
@space.classes do |name , clazz|
assert_equal clazz.instance_type , @space.get_type_for(clazz.instance_type.hash) , clazz.name
end
end
def test_class_types_are_stored
@space.classes.each do |name,clazz|
assert @space.get_type_for(clazz.instance_type.hash)
end
end
def test_class_types_are_identical
@space.classes.each do |name , clazz|
cl_type = @space.get_type_for(clazz.instance_type.hash)
assert_equal cl_type.object_id , clazz.instance_type.object_id
end
end
def test_remove_methods
@space.each_type do | type |
type.method_names.each do |method|
type.remove_method(method)
end
end
assert_equal 0 , @space.get_all_methods.length
end
def test_no_methods_in_types
test_remove_methods
@space.each_type do |type|
assert_equal 0 , type.methods_length , "name #{type.name}"
end
end
def test_no_methods_in_classes
test_remove_methods
@space.classes.each do |name , cl|
assert_equal 0 , cl.instance_type.methods_length , "name #{cl.name}"
end
end
def test_get_method_raises
assert_raises(RuntimeError){ @space.get_method!(:Space,:main)}
end
end
end

View File

@ -63,6 +63,10 @@ module Parfait
type.add_method(foo)
assert_equal :foo , type.get_method(:foo).name
end
def test_space_get_method
test_get_instance
assert_equal :foo , @space.get_method!(:Object , :foo).name
end
def test_resolve_on_object
add_foo_to :Object
assert_equal :foo , object_type.resolve_method( :foo ).name