2018-07-04 22:21:11 +02:00
|
|
|
|
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Vool
|
2018-07-18 09:13:19 +02:00
|
|
|
class TestBlockArg < MiniTest::Test
|
2019-10-03 19:55:41 +02:00
|
|
|
include SlotMachineCompile
|
2018-07-04 22:21:11 +02:00
|
|
|
|
|
|
|
def setup
|
2019-10-03 19:55:41 +02:00
|
|
|
@ret = compile_slot( as_main("self.main {|elem| elem = 5 } "))
|
2018-07-04 22:21:11 +02:00
|
|
|
end
|
|
|
|
def test_is_compiler
|
2019-10-03 19:55:41 +02:00
|
|
|
assert_equal SlotMachine::SlotCollection , @ret.class
|
2018-07-04 22:21:11 +02:00
|
|
|
end
|
2018-07-07 21:42:00 +02:00
|
|
|
def test_has_method
|
2019-09-28 11:41:38 +02:00
|
|
|
assert_equal Parfait::CallableMethod , @ret.method_compilers.get_method.class
|
2018-07-07 21:42:00 +02:00
|
|
|
end
|
|
|
|
def test_method_has_block
|
2019-09-28 11:41:38 +02:00
|
|
|
assert @ret.method_compilers.get_method.blocks , "No block created"
|
2018-07-07 21:42:00 +02:00
|
|
|
end
|
|
|
|
end
|
2018-07-18 09:13:19 +02:00
|
|
|
class TestBlockLocal < MiniTest::Test
|
2019-10-03 19:55:41 +02:00
|
|
|
include SlotMachineCompile
|
2018-07-07 21:42:00 +02:00
|
|
|
def setup
|
2019-10-03 19:55:41 +02:00
|
|
|
@ret = compile_slot( as_main("self.main {|elem| local = 5 } "))
|
2019-09-28 11:41:38 +02:00
|
|
|
@block = @ret.method_compilers.get_method.blocks
|
2018-07-07 21:42:00 +02:00
|
|
|
end
|
|
|
|
def test_block_arg_type
|
|
|
|
assert_equal Parfait::Type, @block.arguments_type.class
|
|
|
|
end
|
|
|
|
def test_block_arg_type_name
|
|
|
|
assert_equal 1, @block.arguments_type.variable_index(:elem)
|
|
|
|
end
|
|
|
|
def test_block_local_type
|
|
|
|
assert_equal Parfait::Type, @block.frame_type.class
|
|
|
|
end
|
|
|
|
def test_block_frame_type_name
|
|
|
|
assert_equal 1, @block.frame_type.variable_index(:local)
|
2018-07-04 22:21:11 +02:00
|
|
|
end
|
|
|
|
end
|
2018-07-18 09:13:19 +02:00
|
|
|
class TestBlockMethodArg < MiniTest::Test
|
2019-10-03 19:55:41 +02:00
|
|
|
include SlotMachineCompile
|
2018-07-18 09:13:19 +02:00
|
|
|
|
2018-07-09 16:55:45 +02:00
|
|
|
def setup
|
|
|
|
end
|
2018-07-18 09:13:19 +02:00
|
|
|
def test_method_arg_compiles
|
2019-10-03 19:55:41 +02:00
|
|
|
ret = compile_slot( as_main("self.main {|elem| arg = 5 } "))
|
2018-07-18 09:13:19 +02:00
|
|
|
assert ret
|
|
|
|
end
|
|
|
|
def test_method_local_compiles
|
2019-10-03 19:55:41 +02:00
|
|
|
ret = compile_slot( as_main("local = 5 ; self.main {|elem| local = 10 } "))
|
2018-07-18 09:13:19 +02:00
|
|
|
assert ret
|
2018-07-09 16:55:45 +02:00
|
|
|
end
|
|
|
|
end
|
2018-07-04 22:21:11 +02:00
|
|
|
end
|