2019-08-06 17:33:27 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Mom
|
|
|
|
class TestMethodCompiler < MiniTest::Test
|
2019-08-07 14:08:45 +02:00
|
|
|
include ScopeHelper
|
2019-08-06 17:33:27 +02:00
|
|
|
|
|
|
|
def setup
|
|
|
|
end
|
|
|
|
|
2019-08-17 22:29:42 +02:00
|
|
|
def in_test_vool(body = "@ivar = 5;return")
|
2019-08-10 11:42:47 +02:00
|
|
|
code = in_Test("def meth; #{body};end")
|
|
|
|
RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(code)
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
2019-08-07 14:08:45 +02:00
|
|
|
|
2019-08-10 11:42:47 +02:00
|
|
|
def test_method
|
|
|
|
in_test_vool()
|
2019-09-21 17:50:33 +02:00
|
|
|
method = Parfait.object_space.get_class_by_name(:Test).get_instance_method(:meth)
|
2019-08-10 11:42:47 +02:00
|
|
|
assert_equal Parfait::VoolMethod , method.class
|
|
|
|
end
|
|
|
|
def test_method_mom_col
|
|
|
|
mom = in_test_vool()
|
|
|
|
assert_equal Mom::MomCollection , mom.class
|
2019-09-28 11:41:38 +02:00
|
|
|
assert_equal Mom::MethodCompiler , mom.compilers.class
|
2019-08-10 11:42:47 +02:00
|
|
|
end
|
|
|
|
def test_compiles_risc
|
2019-09-28 11:41:38 +02:00
|
|
|
compiler = in_test_vool().compilers.to_risc
|
2019-08-10 11:42:47 +02:00
|
|
|
assert_equal Risc::MethodCompiler , compiler.class
|
|
|
|
assert_equal Risc::Label , compiler.risc_instructions.class
|
|
|
|
end
|
|
|
|
def test_compiles_all_risc
|
2019-09-28 11:41:38 +02:00
|
|
|
compiler = in_test_vool().compilers.to_risc
|
2019-08-10 11:42:47 +02:00
|
|
|
assert_equal Risc::LoadConstant , compiler.risc_instructions.next.class
|
2019-08-23 14:31:04 +02:00
|
|
|
assert_equal 16 , compiler.risc_instructions.length
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|