From 98f3898acde82bcc3df4073b91c7f7070a620a89 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 20 Apr 2018 10:27:06 +0300 Subject: [PATCH] fix while tests --- test/mom/test_while_cmp.rb | 70 +++++++++++++++++++ .../{test_while.rb => test_while_simple.rb} | 2 +- test/risc/builtin/test_simple_int.rb | 8 +++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 test/mom/test_while_cmp.rb rename test/mom/{test_while.rb => test_while_simple.rb} (96%) diff --git a/test/mom/test_while_cmp.rb b/test/mom/test_while_cmp.rb new file mode 100644 index 00000000..534d95a9 --- /dev/null +++ b/test/mom/test_while_cmp.rb @@ -0,0 +1,70 @@ +require_relative "helper" + +module Risc + class TestWhileCmp < MiniTest::Test + include Statements + + def setup + super + @input = "while(5 > 0) ; @a = true; end" + @expect = [Label, LoadConstant, LoadConstant, SlotToReg, RegToSlot, + RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, + SlotToReg, RegToSlot, SlotToReg, RegToSlot, SlotToReg, + RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, + SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, + RegToSlot, SlotToReg, LoadConstant, FunctionCall, Label, + SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, + LoadConstant, OperatorInstruction, IsZero, LoadConstant, OperatorInstruction, + IsZero, LoadConstant, SlotToReg, RegToSlot, Branch, + Label] + end + + def test_while_instructions + assert_nil msg = check_nil , msg + end + def test_label + assert_equal Risc::Label , produce_body.class + end + def test_int_load_5 + produced = produce_body + load = produced.next(16) + assert_equal Risc::LoadConstant , load.class + assert_equal Parfait::Integer , load.constant.class + assert_equal 5 , load.constant.value + end + def test_int_load_0 + produced = produce_body + load = produced.next(19) + assert_equal Risc::LoadConstant , load.class + assert_equal Parfait::Integer , load.constant.class + assert_equal 0 , load.constant.value + end + def test_false_check + produced = produce_body + assert_equal Risc::IsZero , produced.next(37).class + assert produced.next(37).label.name.start_with?("merge_label") , produced.next(37).label.name + end + def test_nil_load + produced = produce_body + assert_equal Risc::LoadConstant , produced.next(38).class + assert_equal Parfait::NilClass , produced.next(38).constant.class + end + def pest_nil_check + produced = produce_body + assert_equal produced.next(13) , produced.next(8).label + end + + def test_back_jump # should jump back to condition label + produced = produce_body + assert_equal Risc::Branch , produced.next(44).class + assert_equal produced , produced.next(44).label + end + + def test_merge_label + produced = produce_body + assert_equal Risc::Label , produced.next(45).class + assert produced.next(45).name.start_with?("merge_") , produced.next(29).name + end + + end +end diff --git a/test/mom/test_while.rb b/test/mom/test_while_simple.rb similarity index 96% rename from test/mom/test_while.rb rename to test/mom/test_while_simple.rb index 067593c3..ab23764b 100644 --- a/test/mom/test_while.rb +++ b/test/mom/test_while_simple.rb @@ -1,7 +1,7 @@ require_relative "helper" module Risc - class TestWhile < MiniTest::Test + class TestWhileSimple < MiniTest::Test include Statements def setup diff --git a/test/risc/builtin/test_simple_int.rb b/test/risc/builtin/test_simple_int.rb index 4274d752..17316c84 100644 --- a/test/risc/builtin/test_simple_int.rb +++ b/test/risc/builtin/test_simple_int.rb @@ -17,6 +17,14 @@ module Risc run_all "5 - 15" assert_equal -10 , get_return.value end + def test_rshift + run_all "#{2**8} >> 3" + assert_equal 2**5 , get_return.value + end + def test_lshift + run_all "#{2**8} << 3" + assert_equal 2**11 , get_return.value + end def test_div10 run_all "45.div10" assert_equal 4 , get_return.value