From 5335d08408a7e5a3bd08c72db7b958dcc45cc653 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 2 Apr 2017 22:52:31 +0300 Subject: [PATCH] more condition tests --- test/vool/test_if_statement.rb | 64 +++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/test/vool/test_if_statement.rb b/test/vool/test_if_statement.rb index a176587f..59d4eafe 100644 --- a/test/vool/test_if_statement.rb +++ b/test/vool/test_if_statement.rb @@ -20,10 +20,72 @@ module Vool assert_nil lst.if_false end + def double_if + "if(false) ; true ; else ; false; end" + end def test_if_double - lst = Compiler.compile( "if(false) ; true ; else ; false; end" ) + lst = Compiler.compile( double_if ) assert_equal IfStatement , lst.class end + def test_if_double_cond + lst = Compiler.compile( double_if ) + assert_equal FalseStatement , lst.condition.class + end + def test_if_double_branches + lst = Compiler.compile( double_if ) + 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 + lst = Compiler.compile( reverse_if ) + assert_equal IfStatement , lst.class + end + def test_if_reverse_cond + lst = Compiler.compile( reverse_if ) + assert_equal FalseStatement , lst.condition.class + end + def test_if_reverse_branches + lst = Compiler.compile( reverse_if ) + assert_equal TrueStatement , lst.if_true.class + assert_nil lst.if_false + end + + def reverse_unless + "true unless(false)" + end + def test_if_reverse + lst = Compiler.compile( reverse_unless ) + assert_equal IfStatement , lst.class + end + def test_if_reverse_cond + lst = Compiler.compile( reverse_unless ) + assert_equal FalseStatement , lst.condition.class + end + def test_if_reverse_branches + lst = Compiler.compile( reverse_unless ) + assert_nil lst.if_true + assert_equal TrueStatement ,lst.if_false.class + end + + def ternary + "false ? true : false" + end + def test_if_ternary + lst = Compiler.compile( ternary ) + assert_equal IfStatement , lst.class + end + def test_if_ternary_cond + lst = Compiler.compile( ternary ) + assert_equal FalseStatement , lst.condition.class + end + def test_if_ternary_branches + lst = Compiler.compile( ternary ) + assert_equal TrueStatement , lst.if_true.class + assert_equal FalseStatement, lst.if_false.class + end end end