2019-08-26 08:24:06 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Vool
|
|
|
|
class TestBuiltin < MiniTest::Test
|
|
|
|
include VoolCompile
|
|
|
|
|
|
|
|
def setup
|
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
2019-09-13 19:34:41 +02:00
|
|
|
@code = Builtin.boot_methods({})
|
2019-08-26 08:24:06 +02:00
|
|
|
end
|
|
|
|
def as_ruby
|
|
|
|
@ruby = Ruby::RubyCompiler.compile(@code)
|
|
|
|
end
|
2019-09-24 14:44:33 +02:00
|
|
|
def as_mom
|
|
|
|
vool = as_ruby.to_vool
|
|
|
|
vool.to_parfait
|
|
|
|
vool.to_mom(nil)
|
|
|
|
end
|
2019-08-26 08:24:06 +02:00
|
|
|
def test_boot
|
|
|
|
assert_equal String , @code.class
|
|
|
|
assert @code.include?("Integer")
|
|
|
|
end
|
|
|
|
def test_compile_ruby
|
|
|
|
assert_equal Ruby::ClassStatement , as_ruby.class
|
|
|
|
assert_equal Ruby::MethodStatement , @ruby.body.first.class
|
|
|
|
assert_equal :+ , @ruby.body.first.name
|
|
|
|
end
|
|
|
|
def test_compile_vool
|
|
|
|
vool = as_ruby.to_vool
|
|
|
|
assert_equal Vool::ClassExpression , vool.class
|
|
|
|
assert_equal Vool::MethodExpression , vool.body.first.class
|
|
|
|
end
|
|
|
|
def test_vool_method
|
|
|
|
vool = as_ruby.to_vool
|
|
|
|
assert_equal :+ , vool.body.first.name
|
|
|
|
assert_equal Vool::ReturnStatement , vool.body.first.body.class
|
|
|
|
assert_equal Vool::MacroExpression , vool.body.first.body.return_value.class
|
|
|
|
end
|
|
|
|
def test_mom_basic
|
2019-09-24 14:44:33 +02:00
|
|
|
mom = as_mom
|
2019-08-26 08:24:06 +02:00
|
|
|
assert_equal Mom::MomCollection , mom.class
|
2019-09-28 11:41:38 +02:00
|
|
|
assert_equal Mom::MethodCompiler , mom.method_compilers.class
|
2019-08-26 08:24:06 +02:00
|
|
|
end
|
|
|
|
def test_mom_instructions
|
2019-09-28 11:41:38 +02:00
|
|
|
mom_compiler = as_mom.method_compilers
|
2019-08-26 08:24:06 +02:00
|
|
|
assert_equal Mom::Label , mom_compiler.mom_instructions.class
|
|
|
|
assert_equal Mom::IntOperator , mom_compiler.mom_instructions.next.class
|
|
|
|
assert_equal Mom::SlotLoad , mom_compiler.mom_instructions.next(2).class
|
|
|
|
assert_equal Mom::ReturnJump , mom_compiler.mom_instructions.next(3).class
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|