first propper hoisting test

had to change course, normalising and object creation is not possible
in one go
have to now generate random tmp vars  that will have to be picked up
later (sorted by tmp_ prefix?)
This commit is contained in:
Torsten Ruger
2018-03-15 12:46:56 +05:30
parent 9ddcb3224c
commit 3702411043
13 changed files with 149 additions and 54 deletions

View File

@ -30,9 +30,8 @@ module Vool
include CompilerHelper
def test_compile_one_method
lst = RubyCompiler.compile( in_Test("@ivar") )
assert_equal ScopeStatement , lst.body.class
assert_equal InstanceVariable , lst.body.statements.first.class
lst = RubyCompiler.compile( in_Test("@ivar = 4") )
assert_equal IvarAssignment , lst.body.class
end
def test_compile_two_methods
lst = RubyCompiler.compile( in_Test("false; true;") )

View File

@ -27,9 +27,9 @@ module Vool
assert_equal 2 , @lst.body.length
end
def test_body_is_scope_one_statement
input = "def tryout(arg1, arg2) ; true ; end "
input = "def tryout(arg1, arg2) ; a = true ; end "
lst = RubyCompiler.compile( input )
assert_equal ScopeStatement , lst.body.class
assert_equal LocalAssignment , lst.body.class
end
def test_body_is_scope_zero_statement
input = "def tryout(arg1, arg2) ; ; end "

View File

@ -0,0 +1,16 @@
require_relative "../helper"
module VoolHelper
include CompilerHelper
def compile_main( input )
st = Vool::VoolCompiler.ruby_to_vool as_test_main( input )
assert_equal st.class , Vool::ClassStatement
assert_equal st.body.class , Vool::MethodStatement
st.body.body
end
def compile_plain( input )
Vool::VoolCompiler.ruby_to_vool input
end
end

View File

@ -0,0 +1,95 @@
require_relative 'helper'
module Vool
module VoolC
class TestIfStatement < MiniTest::Test
include VoolHelper
def basic_if
"if(10 < 12) ; a = true ; end"
end
def test_if_basic_hoist
lst = compile_main( basic_if )
assert_equal Statements , lst.class
assert_equal IfStatement , lst.statements[1].class
end
def pest_if_basic_cond
lst = RubyCompiler.compile( basic_if )
assert_equal SendStatement , lst.condition.class
end
def pest_if_basic_branches
lst = RubyCompiler.compile( basic_if )
assert_equal TrueConstant , lst.if_true.class
assert_nil lst.if_false
end
def double_if
"if(false) ; true ; else ; false; end"
end
def pest_if_double
lst = RubyCompiler.compile( double_if )
assert_equal IfStatement , lst.class
end
def pest_if_double_cond
lst = RubyCompiler.compile( double_if )
assert_equal FalseConstant , lst.condition.class
end
def pest_if_double_branches
lst = RubyCompiler.compile( double_if )
assert_equal TrueConstant , lst.if_true.class
assert_equal FalseConstant, lst.if_false.class
end
def reverse_if
"true if(false)"
end
def pest_if_reverse
lst = RubyCompiler.compile( reverse_if )
assert_equal IfStatement , lst.class
end
def pest_if_reverse_cond
lst = RubyCompiler.compile( reverse_if )
assert_equal FalseConstant , lst.condition.class
end
def pest_if_reverse_branches
lst = RubyCompiler.compile( reverse_if )
assert_equal TrueConstant , lst.if_true.class
assert_nil lst.if_false
end
def reverse_unless
"true unless(false)"
end
def pest_if_reverse
lst = RubyCompiler.compile( reverse_unless )
assert_equal IfStatement , lst.class
end
def pest_if_reverse_cond
lst = RubyCompiler.compile( reverse_unless )
assert_equal FalseConstant , lst.condition.class
end
def pest_if_reverse_branches
lst = RubyCompiler.compile( reverse_unless )
assert_nil lst.if_true
assert_equal TrueConstant ,lst.if_false.class
end
def ternary
"false ? true : false"
end
def pest_if_ternary
lst = RubyCompiler.compile( ternary )
assert_equal IfStatement , lst.class
end
def pest_if_ternary_cond
lst = RubyCompiler.compile( ternary )
assert_equal FalseConstant , lst.condition.class
end
def pest_if_ternary_branches
lst = RubyCompiler.compile( ternary )
assert_equal TrueConstant , lst.if_true.class
assert_equal FalseConstant, lst.if_false.class
end
end
end
end