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
|
|
|
|
Parfait.boot!({})
|
|
|
|
ruby_tree = Ruby::RubyCompiler.compile( as_test_main("a = 5") )
|
|
|
|
@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
|
|
|
|
end
|
|
|
|
class TestClassStatementCompile < MiniTest::Test
|
2019-08-06 17:33:27 +02:00
|
|
|
include VoolCompile
|
|
|
|
|
|
|
|
def setup
|
2019-08-07 11:06:06 +02:00
|
|
|
@compiler = compile_first_method( "if(@a) ; @a = 5 ; else; @a = 6 ; end")
|
|
|
|
@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 ,
|
|
|
|
Label, SlotLoad, Label, Label, ReturnSequence ,
|
|
|
|
Label] , @ins
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|