2020-02-13 06:53:41 +01:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module SlotLanguage
|
|
|
|
class TestEqualGoto < MiniTest::Test
|
|
|
|
include SlotHelper
|
|
|
|
|
|
|
|
def do_check(check)
|
|
|
|
assert_equal EqualGoto , check.class
|
|
|
|
assert_equal Goto , check.goto.class
|
2020-02-13 13:09:00 +01:00
|
|
|
assert check.left.is_a?(Variable)
|
|
|
|
assert check.right.is_a?(Variable)
|
|
|
|
assert_equal :a , check.left.name
|
|
|
|
assert_equal :b , check.right.name
|
2020-02-13 06:53:41 +01:00
|
|
|
end
|
|
|
|
def test_equal_local
|
|
|
|
check = compile("goto(exit_label) if(a == b)")
|
|
|
|
do_check(check)
|
|
|
|
end
|
|
|
|
def test_equal_inst_left
|
|
|
|
check = compile("goto(exit_label) if(@a == b)")
|
|
|
|
do_check(check)
|
|
|
|
end
|
|
|
|
def test_equal_inst_right
|
|
|
|
check = compile("goto(exit_label) if(a == @b)")
|
|
|
|
do_check(check)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestEqualGotoFull < MiniTest::Test
|
|
|
|
include SlotHelper
|
|
|
|
def setup
|
|
|
|
@expr = compile("start_label;goto(start_label) if( b == c)")
|
|
|
|
end
|
|
|
|
def test_2
|
|
|
|
assert_equal Array , @expr.class
|
|
|
|
assert_equal 2 , @expr.length
|
|
|
|
end
|
|
|
|
def test_label
|
|
|
|
assert_equal SlotMachine::Label , @expr.first.class
|
|
|
|
assert_equal :start_label , @expr.first.name
|
|
|
|
end
|
|
|
|
def test_conditional
|
|
|
|
assert_equal EqualGoto , @expr.last.class
|
|
|
|
assert_equal :start_label , @expr.last.goto.label.name
|
|
|
|
end
|
|
|
|
def test_same_label
|
|
|
|
assert_equal @expr.first.object_id , @expr.last.goto.label.object_id
|
|
|
|
end
|
|
|
|
def test_expression_left
|
2020-02-13 07:10:04 +01:00
|
|
|
assert_equal Variable , @expr.last.left.class
|
2020-02-13 13:09:00 +01:00
|
|
|
assert_equal :b , @expr.last.left.name
|
2020-02-13 06:53:41 +01:00
|
|
|
end
|
|
|
|
def test_expression_right
|
2020-02-13 07:10:04 +01:00
|
|
|
assert_equal Variable , @expr.last.right.class
|
2020-02-13 13:09:00 +01:00
|
|
|
assert_equal :c , @expr.last.right.name
|
2020-02-13 06:53:41 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|