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-09 21:53:22 +03:00
|
|
|
machine = Virtual.machine.boot
|
|
|
|
machine.parse_and_compile @string_input
|
2015-10-19 14:46:12 +03:00
|
|
|
machine.collect
|
|
|
|
interpreter = Interpreter::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
|
2014-06-05 13:02:36 +03:00
|
|
|
end
|
2015-05-16 12:53:10 +03:00
|
|
|
|
2014-05-21 21:13:12 +03:00
|
|
|
end
|