2017-04-02 18:12:42 +02:00
|
|
|
require_relative 'helper'
|
|
|
|
|
2018-07-19 13:46:51 +02:00
|
|
|
module Ruby
|
2018-07-19 15:30:36 +02:00
|
|
|
class TestIfStatement < MiniTest::Test
|
2018-06-29 21:46:39 +02:00
|
|
|
include RubyTests
|
2017-04-02 18:12:42 +02:00
|
|
|
|
|
|
|
def basic_if
|
|
|
|
"if(10 < 12) ; true ; end"
|
|
|
|
end
|
|
|
|
def test_if_basic
|
2018-06-29 21:46:39 +02:00
|
|
|
lst = compile( basic_if )
|
2017-04-02 18:12:42 +02:00
|
|
|
assert_equal IfStatement , lst.class
|
|
|
|
end
|
|
|
|
def test_if_basic_cond
|
2018-06-29 21:46:39 +02:00
|
|
|
lst = compile( basic_if )
|
2018-03-16 15:09:35 +01:00
|
|
|
assert_equal ScopeStatement , lst.condition.class
|
2017-04-02 18:12:42 +02:00
|
|
|
end
|
|
|
|
def test_if_basic_branches
|
2018-06-29 21:46:39 +02:00
|
|
|
lst = compile( basic_if )
|
2018-03-15 06:54:14 +01:00
|
|
|
assert_equal TrueConstant , lst.if_true.class
|
2017-04-02 18:12:42 +02:00
|
|
|
assert_nil lst.if_false
|
|
|
|
end
|
|
|
|
|
2017-04-02 21:52:31 +02:00
|
|
|
def double_if
|
|
|
|
"if(false) ; true ; else ; false; end"
|
|
|
|
end
|
2017-04-02 21:42:51 +02:00
|
|
|
def test_if_double
|
2018-06-29 21:46:39 +02:00
|
|
|
lst = compile( double_if )
|
2017-04-02 21:52:31 +02:00
|
|
|
assert_equal IfStatement , lst.class
|
|
|
|
end
|
|
|
|
def test_if_double_cond
|
2018-06-29 21:46:39 +02:00
|
|
|
lst = compile( double_if )
|
2018-03-16 15:09:35 +01:00
|
|
|
assert_equal ScopeStatement , lst.condition.class
|
2017-04-02 21:52:31 +02:00
|
|
|
end
|
|
|
|
def test_if_double_branches
|
2018-06-29 21:46:39 +02:00
|
|
|
lst = compile( double_if )
|
2018-03-15 06:54:14 +01:00
|
|
|
assert_equal TrueConstant , lst.if_true.class
|
|
|
|
assert_equal FalseConstant, lst.if_false.class
|
2017-04-02 21:52:31 +02:00
|
|
|
end
|
2017-04-02 18:12:42 +02:00
|
|
|
end
|
|
|
|
end
|