fix and test return

return was in the wrong message
better tests now
This commit is contained in:
Torsten Ruger 2015-11-05 12:22:48 +02:00
parent ff759bf0c1
commit 4014ad27fe
5 changed files with 63 additions and 31 deletions

View File

@ -30,7 +30,7 @@ module Soml
ret = use_reg( :Integer )
# the effect of the method is that the NewMessage Return slot will be filled, return it
# but move it into a register too
add_code Register.get_slot(statement, :message , :return_value , ret )
add_code Register.get_slot(statement, :new_message , :return_value , ret )
ret
end

View File

@ -16,16 +16,16 @@ module Fragments
machine = Register.machine.boot
machine.parse_and_compile @string_input
machine.collect
interpreter = Interpreter::Interpreter.new
interpreter.start machine.init
@interpreter = Interpreter::Interpreter.new
@interpreter.start machine.init
count = 0
begin
count += 1
#puts interpreter.instruction
interpreter.tick
end while( ! interpreter.instruction.nil?)
@interpreter.tick
end while( ! @interpreter.instruction.nil?)
assert_equal @length , count
assert_equal @stdout , interpreter.stdout
assert_equal @stdout , @interpreter.stdout
end
end

View File

@ -1,10 +1,10 @@
require_relative "test_if"
require_relative "test_class"
require_relative "test_foo"
require_relative "test_functions"
require_relative "test_hello"
require_relative "test_if"
require_relative "test_putint"
require_relative "test_recursive_fibo"
require_relative "test_return"
#require_relative "test_while_fibo"

View File

@ -1,24 +0,0 @@
require_relative 'helper'
class TestFoo < MiniTest::Test
include Fragments
def test_foo2
@string_input = <<HERE
class Object
int foo(int x)
int a = 5
return a
end
int main()
foo( 4 )
end
end
HERE
@length = 41
check
end
end

View File

@ -0,0 +1,56 @@
require_relative 'helper'
class TestReturn < MiniTest::Test
include Fragments
def check_return val
check
assert_equal Parfait::Message , @interpreter.get_register(:r1).class
assert_equal val , @interpreter.get_register(:r1).return_value
end
def test_return1
@string_input = <<HERE
class Object
int main()
return 5
end
end
HERE
@length = 18
check_return 5
end
def test_return2
@string_input = <<HERE
class Object
int foo(int x)
return x
end
int main()
return foo( 5 )
end
end
HERE
@length = 38
check_return 5
end
def test_return3
@string_input = <<HERE
class Object
int foo(int x)
int a = 5
return a
end
int main()
return foo( 4 )
end
end
HERE
@length = 42
check_return 5
end
end