diff --git a/test/compiler/fragments/test_methods.rb b/test/compiler/fragments/test_methods.rb deleted file mode 100644 index ed35d3dd..00000000 --- a/test/compiler/fragments/test_methods.rb +++ /dev/null @@ -1,174 +0,0 @@ -require_relative 'helper' - -module Virtual - class TestMethods < MiniTest::Test - include Fragments - - def test_simplest_function - @string_input = < 5) - return 10 - else - return 20 - end - end -end -HERE - @expect = [[MethodEnter,Set,Set,Register::GetSlot,Register::GetSlot, - Register::OperatorInstruction,Register::IsZeroBranch], - [Set,Register::AlwaysBranch],[Set],[],[MethodReturn]] - check - end - - def test_function_return_while - @string_input = < 5) - n = n + 1 - return n - end - end -end -HERE - @expect = [[MethodEnter,Set], - [Set,Register::GetSlot,Register::GetSlot,Register::OperatorInstruction, - Register::IsZeroBranch,Set,Register::GetSlot,Register::GetSlot, - Register::OperatorInstruction,Set,Register::AlwaysBranch] , - [],[MethodReturn]] - check - end - end -end diff --git a/test/compiler/statements/test_all.rb b/test/compiler/statements/test_all.rb index a2f1d4bd..dbe9e8ae 100644 --- a/test/compiler/statements/test_all.rb +++ b/test/compiler/statements/test_all.rb @@ -1,2 +1,5 @@ require_relative "test_if" require_relative "test_return" +require_relative "test_assign" +require_relative "test_call" +require_relative "test_while" diff --git a/test/compiler/statements/test_while.rb b/test/compiler/statements/test_while.rb new file mode 100644 index 00000000..b033fab3 --- /dev/null +++ b/test/compiler/statements/test_while.rb @@ -0,0 +1,61 @@ +require_relative 'helper' + +module Register + class TestWhile < MiniTest::Test + include Statements + + + def test_while_mini + @string_input = < 0) + n = n - 1 + end + end +end +HERE + @expect = [[Virtual::MethodEnter,LoadConstant,SetSlot],[GetSlot,LoadConstant,OperatorInstruction, + IsZeroBranch,GetSlot,LoadConstant,OperatorInstruction,SetSlot,AlwaysBranch], + [],[Virtual::MethodReturn]] + check + end + + + def test_while_return + @string_input = < 5) + n = n + 1 + return n + end + end +end +HERE + @expect = [[Virtual::MethodEnter,LoadConstant,SetSlot], + [GetSlot,LoadConstant,OperatorInstruction,IsZeroBranch, + GetSlot,LoadConstant,OperatorInstruction,SetSlot, + GetSlot,AlwaysBranch] , + [],[Virtual::MethodReturn]] + check + end + end +end