From 7de2f913a076d228cd664bd9443f35f1abc3c5e1 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 25 Oct 2015 13:19:18 +0200 Subject: [PATCH] more class tests --- lib/parfait/class.rb | 7 +-- test/compiler/statements/test_class.rb | 24 +++++++++++ test/parfait/test_class.rb | 59 ++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 test/compiler/statements/test_class.rb create mode 100644 test/parfait/test_class.rb diff --git a/lib/parfait/class.rb b/lib/parfait/class.rb index 5a732423..e14bf654 100644 --- a/lib/parfait/class.rb +++ b/lib/parfait/class.rb @@ -60,6 +60,7 @@ module Parfait def add_instance_method method raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Method raise "syserr #{method.name.class}" unless method.name.is_a? Symbol + raise "Adding to wrong class, should be #{method.for_class}" if method.for_class != self found = get_instance_method( method.name ) if found self.instance_methods.delete(found) @@ -77,7 +78,7 @@ module Parfait else raise "No such method #{method_name} in #{self.name}" end - self.instance_methods.delete found + return true end def create_instance_method method_name , arguments @@ -85,7 +86,7 @@ module Parfait clazz = object_layout().object_class() raise "??? #{method_name}" unless clazz #puts "Self: #{self.class} clazz: #{clazz.name}" - Method.new( clazz , method_name , arguments ) + add_instance_method Method.new( clazz , method_name , arguments ) end # this needs to be done during booting as we can't have all the classes and superclassses @@ -110,7 +111,7 @@ module Parfait method = get_instance_method(m_name) return method if method if( self.super_class ) - method = self.super_class.resolve_method(m_name) + method = Parfait::Space.object_space.get_class_by_name(self.super_class).resolve_method(m_name) raise "Method not found #{m_name}, for \n#{self}" unless method end method diff --git a/test/compiler/statements/test_class.rb b/test/compiler/statements/test_class.rb new file mode 100644 index 00000000..27df8869 --- /dev/null +++ b/test/compiler/statements/test_class.rb @@ -0,0 +1,24 @@ +require_relative 'helper' + +module Register +class TestBasicClass < MiniTest::Test + include Statements + + def test_class_def + @string_input = <