more class creation tests

This commit is contained in:
Torsten Ruger 2017-04-09 10:14:28 +03:00
parent 397eca541a
commit b2775455e1
5 changed files with 56 additions and 13 deletions

View File

@ -29,7 +29,6 @@ module Vool
vars.each { |var| ivar_hash[var] = :Object } vars.each { |var| ivar_hash[var] = :Object }
@clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) ) @clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) )
end end
puts "BODY is #{body.class}"
body.collect([]).each {|node| node.set_class(@clazz) } body.collect([]).each {|node| node.set_class(@clazz) }
body.create_objects body.create_objects
end end

View File

@ -27,7 +27,7 @@ module Vool
def make_type( ) def make_type( )
type_hash = {} type_hash = {}
@args.each {|arg| type_hash[arg.children[0]] = :Object } @args.each {|arg| type_hash[arg] = :Object }
Parfait::NamedList.type_for( type_hash ) Parfait::NamedList.type_for( type_hash )
end end

View File

@ -21,6 +21,10 @@ module Vool
@statements.each { |s| s.collect(arr) } @statements.each { |s| s.collect(arr) }
super super
end end
def create_objects
@statements.each{ |s| s.create_objects }
end
end end
class ScopeStatement < Statements class ScopeStatement < Statements

View File

@ -25,5 +25,40 @@ module Vool
assert itest.instance_type.names.include?(:trivar) , itest.instance_type.names.inspect assert itest.instance_type.names.include?(:trivar) , itest.instance_type.names.inspect
end end
def test_doesnt_create_existing_clas
space_class = Parfait.object_space.get_class_by_name(:Space)
VoolCompiler.compile "class Space ; end"
clazz = Parfait.object_space.get_class_by_name(:Space)
assert_equal clazz , space_class
end
def test_creates_class_without_deriviation
VoolCompiler.compile "class Testing ; end"
clazz = Parfait.object_space.get_class_by_name(:Testing)
assert clazz , "No classes created"
assert_equal :Object , clazz.super_class_name
end
def test_creates_class_with_deriviation
VoolCompiler.compile "class Test2 < List ;end"
clazz = Parfait.object_space.get_class_by_name(:Test2)
assert clazz, "No classes created"
assert_equal :List , clazz.super_class_name
end
def test_space_is_unchanged_by_compile
space1 = Parfait.object_space.get_class_by_name(:Space)
VoolCompiler.compile "class Space ;end"
space2 = Parfait.object_space.get_class_by_name(:Space)
assert_equal space1 , space2
end
def test_space_type_is_unchanged_by_compile
space1 = Parfait.object_space.get_class_by_name(:Space).instance_type
VoolCompiler.compile "class Space ;end"
space2 = Parfait.object_space.get_class_by_name(:Space).instance_type
assert_equal space1 , space2
end
end end
end end

View File

@ -14,29 +14,34 @@ module Vool
test.get_method(:meth) test.get_method(:meth)
end end
def test_method_statement_has_class
clazz = VoolCompiler.compile in_Test("def meth; @ivar ;end")
assert_equal Parfait::Class , clazz.body.clazz.class
end
def test_creates_method_in_class
method = create_method
assert method , "No method created"
assert_equal Rubyx::RubyMethod , method.class
end
def test_method_has_source def test_method_has_source
method = create_method method = create_method
assert_equal Vool::InstanceVariable , method.source.class assert_equal Vool::InstanceVariable , method.source.class
end end
def test_method_has_no_locals
method = create_method
assert_equal 1 , method.locals_type.instance_length
end
def test_method_has_no_args def test_method_has_no_args
method = create_method method = create_method
assert_equal 1 , method.args_type.instance_length assert_equal 1 , method.args_type.instance_length
end end
def test_method_has_no_locals def test_creates_method_in_class
method = create_method method = create_method
assert_equal 1 , method.locals_type.instance_length assert method , "No method created"
assert_equal Rubyx::RubyMethod , method.class
end end
def test_method_statement_has_class
clazz = VoolCompiler.compile in_Test("def meth; @ivar ;end")
assert_equal ScopeStatement , clazz.body.class
assert_equal MethodStatement , clazz.body.statements.first.class
assert_equal Parfait::Class , clazz.body.statements.first.clazz.class
end
def test_method_has_one_local def test_method_has_one_local
VoolCompiler.compile in_Test("def meth; local = 5 ;end") VoolCompiler.compile in_Test("def meth; local = 5 ;end")
test = Parfait.object_space.get_class_by_name(:Test) test = Parfait.object_space.get_class_by_name(:Test)