more class creation tests
This commit is contained in:
parent
397eca541a
commit
b2775455e1
@ -29,7 +29,6 @@ module Vool
|
||||
vars.each { |var| ivar_hash[var] = :Object }
|
||||
@clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) )
|
||||
end
|
||||
puts "BODY is #{body.class}"
|
||||
body.collect([]).each {|node| node.set_class(@clazz) }
|
||||
body.create_objects
|
||||
end
|
||||
|
@ -27,7 +27,7 @@ module Vool
|
||||
|
||||
def make_type( )
|
||||
type_hash = {}
|
||||
@args.each {|arg| type_hash[arg.children[0]] = :Object }
|
||||
@args.each {|arg| type_hash[arg] = :Object }
|
||||
Parfait::NamedList.type_for( type_hash )
|
||||
end
|
||||
|
||||
|
@ -21,6 +21,10 @@ module Vool
|
||||
@statements.each { |s| s.collect(arr) }
|
||||
super
|
||||
end
|
||||
|
||||
def create_objects
|
||||
@statements.each{ |s| s.create_objects }
|
||||
end
|
||||
end
|
||||
|
||||
class ScopeStatement < Statements
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user