rubyx/test/vool/compilers/test_class_compiler.rb

65 lines
2.0 KiB
Ruby
Raw Normal View History

require_relative "helper"
module Vool
class TestClassCompiler < MiniTest::Test
include CompilerHelper
def setup
Risc.machine.boot
end
def compile_in_test input
VoolCompiler.compile in_Test(input)
itest = Parfait.object_space.get_class_by_name(:Test)
assert itest
itest
end
def test_compile_class_one
itest = compile_in_test "def meth; @ivar; end"
assert itest.instance_type.names.include?(:ivar) , itest.instance_type.names.inspect
end
def test_compile_class_two
itest = compile_in_test "def meth; @ivar; end;def meth2(arg); @trivar = 5; end"
assert itest.instance_type.names.include?(:trivar) , itest.instance_type.names.inspect
end
2017-04-09 09:14:28 +02:00
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