2019-08-26 08:24:06 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
2019-10-03 23:36:49 +02:00
|
|
|
module Sol
|
2019-08-26 08:24:06 +02:00
|
|
|
class TestBuiltin < MiniTest::Test
|
2019-10-03 23:36:49 +02:00
|
|
|
include SolCompile
|
2019-08-26 08:24:06 +02:00
|
|
|
|
|
|
|
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-10-03 19:55:41 +02:00
|
|
|
def as_slot
|
2019-10-03 23:36:49 +02:00
|
|
|
sol = as_ruby.to_sol
|
|
|
|
sol.to_parfait
|
|
|
|
sol.to_slot(nil)
|
2019-09-24 14:44:33 +02:00
|
|
|
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
|
2019-10-03 23:36:49 +02:00
|
|
|
def test_compile_sol
|
|
|
|
sol = as_ruby.to_sol
|
|
|
|
assert_equal Sol::ClassExpression , sol.class
|
|
|
|
assert_equal Sol::MethodExpression , sol.body.first.class
|
2019-08-26 08:24:06 +02:00
|
|
|
end
|
2019-10-03 23:36:49 +02:00
|
|
|
def test_sol_method
|
|
|
|
sol = as_ruby.to_sol
|
|
|
|
assert_equal :+ , sol.body.first.name
|
|
|
|
assert_equal Sol::ReturnStatement , sol.body.first.body.class
|
|
|
|
assert_equal Sol::MacroExpression , sol.body.first.body.return_value.class
|
2019-08-26 08:24:06 +02:00
|
|
|
end
|
2019-10-03 19:55:41 +02:00
|
|
|
def test_slot_basic
|
2019-10-03 20:07:55 +02:00
|
|
|
slot = as_slot
|
|
|
|
assert_equal SlotMachine::SlotCollection , slot.class
|
|
|
|
assert_equal SlotMachine::MethodCompiler , slot.method_compilers.class
|
2019-10-03 19:55:41 +02:00
|
|
|
end
|
|
|
|
def test_slot_instructions
|
2019-10-03 20:07:55 +02:00
|
|
|
slot_compiler = as_slot.method_compilers
|
|
|
|
assert_equal SlotMachine::Label , slot_compiler.slot_instructions.class
|
|
|
|
assert_equal SlotMachine::IntOperator , slot_compiler.slot_instructions.next.class
|
|
|
|
assert_equal SlotMachine::SlotLoad , slot_compiler.slot_instructions.next(2).class
|
|
|
|
assert_equal SlotMachine::ReturnJump , slot_compiler.slot_instructions.next(3).class
|
2019-08-26 08:24:06 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|