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

@ -25,5 +25,40 @@ module Vool
assert itest.instance_type.names.include?(:trivar) , itest.instance_type.names.inspect
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

View File

@ -14,29 +14,34 @@ module Vool
test.get_method(:meth)
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
method = create_method
assert_equal Vool::InstanceVariable , method.source.class
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
method = create_method
assert_equal 1 , method.args_type.instance_length
end
def test_method_has_no_locals
def test_creates_method_in_class
method = create_method
assert_equal 1 , method.locals_type.instance_length
assert method , "No method created"
assert_equal Rubyx::RubyMethod , method.class
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
VoolCompiler.compile in_Test("def meth; local = 5 ;end")
test = Parfait.object_space.get_class_by_name(:Test)