2015-10-14 21:49:05 +03:00
|
|
|
require_relative '../../helper'
|
2015-10-19 14:46:12 +03:00
|
|
|
require "interpreter/interpreter"
|
|
|
|
|
|
|
|
# Fragments are small programs that we run through the interpreter and really only check
|
|
|
|
# - the no. of instructions processed
|
|
|
|
# - the stdout output
|
|
|
|
|
2014-05-21 21:13:12 +03:00
|
|
|
|
2014-05-21 21:37:04 +03:00
|
|
|
|
2014-05-21 21:13:12 +03:00
|
|
|
module Fragments
|
|
|
|
|
2015-10-19 14:46:12 +03:00
|
|
|
def setup
|
|
|
|
@stdout = ""
|
|
|
|
end
|
2015-07-18 14:33:09 +03:00
|
|
|
def check
|
2015-10-22 18:16:29 +03:00
|
|
|
machine = Register.machine.boot
|
2015-10-09 21:53:22 +03:00
|
|
|
machine.parse_and_compile @string_input
|
2015-10-19 14:46:12 +03:00
|
|
|
machine.collect
|
2015-11-05 12:22:48 +02:00
|
|
|
@interpreter = Interpreter::Interpreter.new
|
|
|
|
@interpreter.start machine.init
|
2015-10-19 14:46:12 +03:00
|
|
|
count = 0
|
|
|
|
begin
|
|
|
|
count += 1
|
|
|
|
#puts interpreter.instruction
|
2015-11-05 12:22:48 +02:00
|
|
|
@interpreter.tick
|
|
|
|
end while( ! @interpreter.instruction.nil?)
|
2015-10-19 14:46:12 +03:00
|
|
|
assert_equal @length , count
|
2015-11-05 12:22:48 +02:00
|
|
|
assert_equal @stdout , @interpreter.stdout
|
2014-06-05 13:02:36 +03:00
|
|
|
end
|
2015-05-16 12:53:10 +03:00
|
|
|
|
2015-11-05 17:00:41 +02:00
|
|
|
def check_return val
|
|
|
|
check
|
2015-11-07 22:20:21 +02:00
|
|
|
assert_equal Parfait::Message , @interpreter.get_register(:r0).class
|
|
|
|
assert_equal val , @interpreter.get_register(:r0).return_value
|
2015-11-05 17:00:41 +02:00
|
|
|
end
|
2014-05-21 21:13:12 +03:00
|
|
|
end
|