2018-07-20 16:30:08 +02:00
|
|
|
require_relative 'helper'
|
|
|
|
|
|
|
|
module Ruby
|
2019-10-03 23:36:49 +02:00
|
|
|
class TestIfStatementSol < MiniTest::Test
|
2018-07-20 16:30:08 +02:00
|
|
|
include RubyTests
|
|
|
|
|
|
|
|
def setup
|
2019-10-03 23:36:49 +02:00
|
|
|
@lst = compile("if(true) ; a = 1 ; else ; a = 2 ; end").to_sol
|
2018-07-20 16:30:08 +02:00
|
|
|
end
|
|
|
|
def test_class
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::IfStatement , @lst.class
|
2018-07-20 16:30:08 +02:00
|
|
|
end
|
|
|
|
def test_true
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::LocalAssignment , @lst.if_true.class
|
2019-10-02 16:42:24 +02:00
|
|
|
assert @lst.has_true?
|
2018-07-20 16:30:08 +02:00
|
|
|
end
|
|
|
|
def test_false
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::LocalAssignment , @lst.if_false.class
|
2019-10-02 16:42:24 +02:00
|
|
|
assert @lst.has_false?
|
2018-07-20 16:30:08 +02:00
|
|
|
end
|
|
|
|
def test_condition
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::TrueConstant , @lst.condition.class
|
2018-07-20 16:30:08 +02:00
|
|
|
end
|
2019-10-02 16:42:24 +02:00
|
|
|
def test_to_s
|
|
|
|
assert_tos "if (true);a = 1;else;a = 2;end" , @lst
|
|
|
|
end
|
2018-07-20 16:30:08 +02:00
|
|
|
end
|
2019-10-03 23:36:49 +02:00
|
|
|
class TestIfStatementSolHoisted < MiniTest::Test
|
2018-07-20 16:30:08 +02:00
|
|
|
include RubyTests
|
|
|
|
|
|
|
|
def setup
|
2019-10-03 23:36:49 +02:00
|
|
|
@lst = compile("if(foo() == 1) ; a = 1 ; end").to_sol
|
2018-07-20 16:30:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_class
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::Statements , @lst.class
|
2018-07-20 16:30:08 +02:00
|
|
|
end
|
|
|
|
def test_first_class
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::LocalAssignment , @lst.first.class
|
2018-07-20 16:30:08 +02:00
|
|
|
end
|
|
|
|
def test_last_class
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::IfStatement , @lst.last.class
|
2018-07-20 16:30:08 +02:00
|
|
|
end
|
|
|
|
def test_true
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::LocalAssignment , @lst.last.if_true.class
|
2018-07-20 16:30:08 +02:00
|
|
|
end
|
|
|
|
def test_condition
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::SendStatement , @lst.last.condition.class
|
2019-08-16 17:42:57 +02:00
|
|
|
assert_equal :== , @lst.last.condition.name
|
2018-07-20 16:30:08 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|