2019-08-06 17:33:27 +02:00
|
|
|
|
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Vool
|
|
|
|
class TestClassStatement < MiniTest::Test
|
2019-08-08 11:18:36 +02:00
|
|
|
include ScopeHelper
|
|
|
|
def setup
|
2019-08-17 14:58:27 +02:00
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
|
|
|
ruby_tree = Ruby::RubyCompiler.compile( as_test_main("@a = 5") )
|
2019-08-08 11:18:36 +02:00
|
|
|
@vool = ruby_tree.to_vool
|
|
|
|
end
|
|
|
|
def test_class
|
|
|
|
assert_equal ClassStatement , @vool.class
|
|
|
|
end
|
|
|
|
def test_method
|
|
|
|
assert_equal MethodStatement , @vool.body.first.class
|
|
|
|
end
|
|
|
|
def test_create_class
|
|
|
|
assert_equal Parfait::Class , @vool.create_class_object.class
|
|
|
|
end
|
|
|
|
def test_create_class
|
|
|
|
assert_equal :Test , @vool.create_class_object.name
|
|
|
|
end
|
2019-08-17 14:58:27 +02:00
|
|
|
def test_class_instance
|
|
|
|
assert_equal :a , @vool.create_class_object.instance_type.names[1]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class TestClassStatementTypeCreation < MiniTest::Test
|
|
|
|
include ScopeHelper
|
|
|
|
def setup
|
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
|
|
|
end
|
|
|
|
def assert_type_for(input)
|
|
|
|
ruby_tree = Ruby::RubyCompiler.compile( as_test_main(input) )
|
|
|
|
vool = ruby_tree.to_vool
|
|
|
|
assert_equal ClassStatement , vool.class
|
|
|
|
clazz = vool.create_class_object
|
|
|
|
assert_equal Parfait::Class , clazz.class
|
|
|
|
assert_equal :a , clazz.instance_type.names[1]
|
|
|
|
end
|
|
|
|
def test_while_cond
|
|
|
|
assert_type_for("while(@a) ; 1 == 1 ; end")
|
|
|
|
end
|
|
|
|
def test_while_cond_eq
|
|
|
|
assert_type_for("while(@a==1); 1 == 1 ; end")
|
|
|
|
end
|
|
|
|
def test_if_cond
|
|
|
|
assert_type_for("if(@a); 1 == 1 ; end")
|
|
|
|
end
|
|
|
|
def test_send_1
|
|
|
|
assert_type_for("@a.call")
|
|
|
|
end
|
|
|
|
def test_send_arg
|
|
|
|
assert_type_for("call(@a)")
|
|
|
|
end
|
|
|
|
def test_return
|
|
|
|
assert_type_for("return @a")
|
|
|
|
end
|
|
|
|
def test_return_call
|
|
|
|
assert_type_for("return call(@a)")
|
|
|
|
end
|
|
|
|
def test_return_rec
|
|
|
|
assert_type_for("return @a.call()")
|
|
|
|
end
|
2019-08-08 11:18:36 +02:00
|
|
|
end
|
|
|
|
class TestClassStatementCompile < MiniTest::Test
|
2019-08-06 17:33:27 +02:00
|
|
|
include VoolCompile
|
|
|
|
|
|
|
|
def setup
|
2019-08-17 22:29:42 +02:00
|
|
|
@compiler = compile_first_method( "if(@a) ; @a = 5 ; else; @a = 6 ; end; return")
|
2019-08-07 11:06:06 +02:00
|
|
|
@ins = @compiler.mom_instructions
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
|
|
|
|
2019-08-07 11:06:06 +02:00
|
|
|
def test_label
|
|
|
|
assert_equal Label , @ins.class , @ins
|
|
|
|
assert_equal "Test_Type.main" , @ins.name , @ins
|
|
|
|
end
|
2019-08-06 17:33:27 +02:00
|
|
|
def test_condition_compiles_to_check
|
2019-08-07 11:06:06 +02:00
|
|
|
assert_equal TruthCheck , @ins.next.class , @ins
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
|
|
|
def test_condition_is_slot
|
2019-08-07 11:06:06 +02:00
|
|
|
assert_equal SlotDefinition , @ins.next.condition.class , @ins
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
|
|
|
def test_label_after_check
|
2019-08-07 11:06:06 +02:00
|
|
|
assert_equal Label , @ins.next(2).class , @ins
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
|
|
|
def test_label_last
|
|
|
|
assert_equal Label , @ins.last.class , @ins
|
|
|
|
end
|
|
|
|
def test_array
|
2019-08-07 11:06:06 +02:00
|
|
|
check_array [Label, TruthCheck, Label, SlotLoad, Jump ,
|
2019-08-17 22:29:42 +02:00
|
|
|
Label, SlotLoad, Label, SlotLoad, ReturnJump ,
|
|
|
|
Label, ReturnSequence, Label] , @ins
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|