From f46c4d148e1421175ef53bd557d9d1ea7ec6c4b1 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 23 Mar 2018 11:21:41 +0200 Subject: [PATCH] more return testing --- test/mom/test_return_call.rb | 32 ++++++++++++++++++++++++++++ test/mom/test_return_dynamic.rb | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 test/mom/test_return_call.rb create mode 100644 test/mom/test_return_dynamic.rb diff --git a/test/mom/test_return_call.rb b/test/mom/test_return_call.rb new file mode 100644 index 00000000..27b62c5a --- /dev/null +++ b/test/mom/test_return_call.rb @@ -0,0 +1,32 @@ +require_relative "helper" + +module Risc + class TestReturnCall < MiniTest::Test + include Statements + + def setup + super + @input = "return 5.mod4" + @expect = [LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg , + SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg , + SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg , + RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant , + FunctionCall, Label, SlotToReg, SlotToReg, RegToSlot, SlotToReg , + SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg , + Transfer, SlotToReg, FunctionReturn] + end + + def test_return_instructions + assert_nil msg = check_nil , msg + end + def test_function_return + produced = produce_body + assert_equal FunctionReturn , produced.next(38).class + end + def test_load_5 + produced = produce_body + assert_equal LoadConstant , produced.next(16).class + assert_equal 5 , produced.next(16).constant.value + end + end +end diff --git a/test/mom/test_return_dynamic.rb b/test/mom/test_return_dynamic.rb new file mode 100644 index 00000000..fbab41f3 --- /dev/null +++ b/test/mom/test_return_dynamic.rb @@ -0,0 +1,37 @@ +require_relative "helper" + +module Risc + class TestReturnDynamic < MiniTest::Test + include Statements + + def setup + super + @input = "return @a.mod4" + @expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, NotSame, SlotToReg , + SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot , + LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot , + LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot , + LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg , + RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant , + FunctionCall, Label, SlotToReg, RegToSlot, Label, LoadConstant , + SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg , + SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg , + SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg , + RegToSlot, LoadConstant, SlotToReg, DynamicJump, SlotToReg, SlotToReg , + RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg , + RegToSlot, SlotToReg, Transfer, SlotToReg, FunctionReturn] + end + + def test_return_instructions + assert_nil msg = check_nil , msg + end + def test_function_return + produced = produce_body + assert_equal FunctionReturn , produced.next(76).class + end + def test_cache_check + produced = produce_body + assert_equal NotSame , produced.next(4).class + end + end +end