unify fragment and parfait test code
so that we can test fragments remotely too
This commit is contained in:
@ -1,36 +1,20 @@
|
||||
require_relative '../../helper'
|
||||
require "register/interpreter"
|
||||
require_relative '../helper'
|
||||
|
||||
# Fragments are small programs that we run through the interpreter and really only check
|
||||
# - the no. of instructions processed
|
||||
# - the stdout output
|
||||
|
||||
|
||||
|
||||
module Fragments
|
||||
include RuntimeTests
|
||||
|
||||
# define setup to NOT load parfait.
|
||||
def setup
|
||||
@stdout = ""
|
||||
end
|
||||
def check
|
||||
machine = Register.machine.boot
|
||||
machine.parse_and_compile @string_input
|
||||
machine.collect
|
||||
@interpreter = Register::Interpreter.new
|
||||
@interpreter.start machine.init
|
||||
count = 0
|
||||
begin
|
||||
count += 1
|
||||
#puts interpreter.instruction
|
||||
@interpreter.tick
|
||||
end while( ! @interpreter.instruction.nil?)
|
||||
assert_equal @length , count
|
||||
assert_equal @stdout , @interpreter.stdout
|
||||
@machine = Register.machine.boot
|
||||
end
|
||||
|
||||
def check_return val
|
||||
check
|
||||
assert_equal Parfait::Message , @interpreter.get_register(:r0).class
|
||||
assert_equal val , @interpreter.get_register(:r0).return_value
|
||||
def main()
|
||||
@string_input
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -30,7 +30,7 @@ class Object
|
||||
end
|
||||
HERE
|
||||
@length = 505
|
||||
check_return 80
|
||||
check 80
|
||||
end
|
||||
|
||||
def test_class_method
|
||||
@ -47,7 +47,7 @@ class Object
|
||||
end
|
||||
HERE
|
||||
@length = 33
|
||||
check_return 5
|
||||
check 5
|
||||
end
|
||||
|
||||
def test_class_method_fails
|
||||
|
@ -17,7 +17,7 @@ class Object
|
||||
end
|
||||
HERE
|
||||
@length = 25
|
||||
check_return 4
|
||||
check 4
|
||||
end
|
||||
|
||||
def test_if_zero
|
||||
|
@ -29,6 +29,6 @@ class Object
|
||||
end
|
||||
HERE
|
||||
@length = 2525
|
||||
check_return 21
|
||||
check 21
|
||||
end
|
||||
end
|
||||
|
@ -12,7 +12,7 @@ class Object
|
||||
end
|
||||
HERE
|
||||
@length = 15
|
||||
check_return 5
|
||||
check 5
|
||||
end
|
||||
|
||||
def test_return2
|
||||
@ -28,7 +28,7 @@ class Object
|
||||
end
|
||||
HERE
|
||||
@length = 35
|
||||
check_return 5
|
||||
check 5
|
||||
end
|
||||
|
||||
def test_return3
|
||||
@ -45,7 +45,7 @@ class Object
|
||||
end
|
||||
HERE
|
||||
@length = 39
|
||||
check_return 5
|
||||
check 5
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -31,14 +31,14 @@ HERE
|
||||
fibo 48
|
||||
@length = 1241
|
||||
# this is not the correct fibo, just what comes from wrapping (smaller than below)
|
||||
check_return 512559680
|
||||
check 512559680
|
||||
end
|
||||
|
||||
# highest 32 bit fibo
|
||||
def test_while_fibo47
|
||||
fibo 47
|
||||
@length = 1216
|
||||
check_return 2971215073
|
||||
check 2971215073
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,5 +1,6 @@
|
||||
require_relative 'helper'
|
||||
|
||||
module Soml
|
||||
class TestWord < MiniTest::Test
|
||||
include Fragments
|
||||
|
||||
@ -21,3 +22,4 @@ HERE
|
||||
check
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user