2017-04-02 18:12:42 +02:00
|
|
|
require_relative 'helper'
|
|
|
|
|
|
|
|
module Vool
|
|
|
|
class TestIfStatement < MiniTest::Test
|
|
|
|
|
|
|
|
def basic_if
|
|
|
|
"if(10 < 12) ; true ; end"
|
|
|
|
end
|
|
|
|
def test_if_basic
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( basic_if )
|
2017-04-02 18:12:42 +02:00
|
|
|
assert_equal IfStatement , lst.class
|
|
|
|
end
|
|
|
|
def test_if_basic_cond
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( basic_if )
|
2017-04-02 18:12:42 +02:00
|
|
|
assert_equal SendStatement , lst.condition.class
|
|
|
|
end
|
|
|
|
def test_if_basic_branches
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( basic_if )
|
2017-04-02 18:12:42 +02:00
|
|
|
assert_equal TrueStatement , lst.if_true.class
|
|
|
|
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
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( double_if )
|
2017-04-02 21:52:31 +02:00
|
|
|
assert_equal IfStatement , lst.class
|
|
|
|
end
|
|
|
|
def test_if_double_cond
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( double_if )
|
2017-04-02 21:52:31 +02:00
|
|
|
assert_equal FalseStatement , lst.condition.class
|
|
|
|
end
|
|
|
|
def test_if_double_branches
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( double_if )
|
2017-04-02 21:52:31 +02:00
|
|
|
assert_equal TrueStatement , lst.if_true.class
|
|
|
|
assert_equal FalseStatement, lst.if_false.class
|
|
|
|
end
|
|
|
|
|
|
|
|
def reverse_if
|
|
|
|
"true if(false)"
|
|
|
|
end
|
|
|
|
def test_if_reverse
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( reverse_if )
|
2017-04-02 21:52:31 +02:00
|
|
|
assert_equal IfStatement , lst.class
|
|
|
|
end
|
|
|
|
def test_if_reverse_cond
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( reverse_if )
|
2017-04-02 21:52:31 +02:00
|
|
|
assert_equal FalseStatement , lst.condition.class
|
|
|
|
end
|
|
|
|
def test_if_reverse_branches
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( reverse_if )
|
2017-04-02 21:52:31 +02:00
|
|
|
assert_equal TrueStatement , lst.if_true.class
|
|
|
|
assert_nil lst.if_false
|
|
|
|
end
|
|
|
|
|
|
|
|
def reverse_unless
|
|
|
|
"true unless(false)"
|
|
|
|
end
|
|
|
|
def test_if_reverse
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( reverse_unless )
|
2017-04-02 21:42:51 +02:00
|
|
|
assert_equal IfStatement , lst.class
|
2017-04-02 18:12:42 +02:00
|
|
|
end
|
2017-04-02 21:52:31 +02:00
|
|
|
def test_if_reverse_cond
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( reverse_unless )
|
2017-04-02 21:52:31 +02:00
|
|
|
assert_equal FalseStatement , lst.condition.class
|
|
|
|
end
|
|
|
|
def test_if_reverse_branches
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( reverse_unless )
|
2017-04-02 21:52:31 +02:00
|
|
|
assert_nil lst.if_true
|
|
|
|
assert_equal TrueStatement ,lst.if_false.class
|
|
|
|
end
|
2017-04-02 18:12:42 +02:00
|
|
|
|
2017-04-02 21:52:31 +02:00
|
|
|
def ternary
|
|
|
|
"false ? true : false"
|
|
|
|
end
|
|
|
|
def test_if_ternary
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( ternary )
|
2017-04-02 21:52:31 +02:00
|
|
|
assert_equal IfStatement , lst.class
|
|
|
|
end
|
|
|
|
def test_if_ternary_cond
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( ternary )
|
2017-04-02 21:52:31 +02:00
|
|
|
assert_equal FalseStatement , lst.condition.class
|
|
|
|
end
|
|
|
|
def test_if_ternary_branches
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( ternary )
|
2017-04-02 21:52:31 +02:00
|
|
|
assert_equal TrueStatement , lst.if_true.class
|
|
|
|
assert_equal FalseStatement, lst.if_false.class
|
|
|
|
end
|
2017-04-02 18:12:42 +02:00
|
|
|
end
|
|
|
|
end
|