rubyx/test/compiler/statements/helper.rb

38 lines
1.0 KiB
Ruby
Raw Normal View History

2015-10-15 08:47:11 +02:00
require_relative '../../helper'
module Statements
def check
2015-10-22 17:16:29 +02:00
machine = Register.machine
machine.boot unless machine.booted
2015-10-15 08:47:11 +02:00
machine.parse_and_compile @string_input
2015-10-28 20:40:48 +01:00
produced = Register.machine.space.get_main.instructions
2015-10-15 08:47:11 +02:00
assert @expect , "No output given"
#assert_equal @expect.length , produced.instructions.length , "instructions length #{produced.instructions.to_ac}"
2015-10-28 20:40:48 +01:00
compare_instructions produced , @expect
produced
end
def compare_instructions instruction , expect
index = 0
start = instruction
begin
should = expect[index]
assert should , "No instruction at #{index}"
assert_equal instruction.class , should , "Expected at #{index+1}\n#{should(start)}"
index += 1
instruction = instruction.next
end while( instruction )
2015-10-15 08:47:11 +02:00
end
def should start
str = start.to_ac.to_s
str.gsub!("Register::","")
ret = ""
str.split(",").each_slice(7).each do |line|
2015-11-09 22:27:15 +01:00
ret += " " + line.join(",") + " ,\n"
end
ret
end
2015-10-15 08:47:11 +02:00
end