2017-04-08 18:20:11 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Vool
|
|
|
|
class TestClassCompiler < MiniTest::Test
|
|
|
|
include CompilerHelper
|
|
|
|
|
|
|
|
def setup
|
|
|
|
Risc.machine.boot
|
|
|
|
end
|
|
|
|
|
|
|
|
def compile_in_test input
|
2018-03-12 12:53:16 +01:00
|
|
|
VoolCompiler.ruby_to_vool in_Test(input)
|
2017-04-08 18:20:11 +02:00
|
|
|
itest = Parfait.object_space.get_class_by_name(:Test)
|
|
|
|
assert itest
|
|
|
|
itest
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_compile_class_one
|
2018-03-13 11:46:06 +01:00
|
|
|
itest = compile_in_test "def meth; @ivar = 5; end"
|
2017-04-08 18:20:11 +02:00
|
|
|
assert itest.instance_type.names.include?(:ivar) , itest.instance_type.names.inspect
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_compile_class_two
|
2018-03-13 11:46:06 +01:00
|
|
|
itest = compile_in_test "def meth; @ivar = 5; end;def meth2(arg); @trivar = 5; end"
|
2017-04-08 18:20:11 +02:00
|
|
|
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)
|
2018-03-12 12:53:16 +01:00
|
|
|
VoolCompiler.ruby_to_vool "class Space ; end"
|
2017-04-09 09:14:28 +02:00
|
|
|
clazz = Parfait.object_space.get_class_by_name(:Space)
|
|
|
|
assert_equal clazz , space_class
|
|
|
|
end
|
|
|
|
|
2017-04-12 10:51:29 +02:00
|
|
|
def test_class_body_is_scope
|
2018-03-13 11:46:06 +01:00
|
|
|
clazz = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5 ;end")
|
2018-03-16 06:33:29 +01:00
|
|
|
assert_equal MethodStatement , clazz.body.class
|
2017-04-12 10:51:29 +02:00
|
|
|
end
|
|
|
|
|
2017-04-09 09:14:28 +02:00
|
|
|
def test_creates_class_without_deriviation
|
2018-03-12 12:53:16 +01:00
|
|
|
VoolCompiler.ruby_to_vool "class Testing ; end"
|
2017-04-09 09:14:28 +02:00
|
|
|
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
|
2018-03-12 12:53:16 +01:00
|
|
|
VoolCompiler.ruby_to_vool "class Test2 < List ;end"
|
2017-04-09 09:14:28 +02:00
|
|
|
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)
|
2018-03-12 12:53:16 +01:00
|
|
|
VoolCompiler.ruby_to_vool "class Space ;end"
|
2017-04-09 09:14:28 +02:00
|
|
|
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
|
2018-03-12 12:53:16 +01:00
|
|
|
VoolCompiler.ruby_to_vool "class Space ;end"
|
2017-04-09 09:14:28 +02:00
|
|
|
space2 = Parfait.object_space.get_class_by_name(:Space).instance_type
|
|
|
|
assert_equal space1 , space2
|
|
|
|
end
|
|
|
|
|
2017-04-08 18:20:11 +02:00
|
|
|
end
|
|
|
|
end
|