From 830fe2ab2b53e71493f7ebd2558bee8d0574fe05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Tue, 17 Sep 2019 10:16:59 +0300 Subject: [PATCH] More instruction tests --- test/mom/instruction/test_jump.rb | 15 +++++++ test/mom/instruction/test_message_setup.rb | 46 +++++++++++++++++++++ test/mom/instruction/test_not_same_check.rb | 8 +--- 3 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 test/mom/instruction/test_jump.rb create mode 100644 test/mom/instruction/test_message_setup.rb diff --git a/test/mom/instruction/test_jump.rb b/test/mom/instruction/test_jump.rb new file mode 100644 index 00000000..6b2ac19e --- /dev/null +++ b/test/mom/instruction/test_jump.rb @@ -0,0 +1,15 @@ +require_relative "helper" + +module Mom + class TestJump < MomInstructionTest + def instruction + Jump.new( Label.new("ok" , "target")) + end + def test_len + assert_equal 2 , all.length , all_str + end + def test_1_slot + assert_branch risc(1) , "target" + end + end +end diff --git a/test/mom/instruction/test_message_setup.rb b/test/mom/instruction/test_message_setup.rb new file mode 100644 index 00000000..ef709c9d --- /dev/null +++ b/test/mom/instruction/test_message_setup.rb @@ -0,0 +1,46 @@ +require_relative "helper" + +module Mom + class TestMessageSetupInt < MomInstructionTest + def instruction + MessageSetup.new( 1 ) + end + def test_len + assert_equal 4 , all.length , all_str + end + def test_1_slot + assert_slot_to_reg risc(1) ,:r0 , 9 , :r1 + end + def test_2_slot + assert_slot_to_reg risc(2) ,:r0 , 1 , :r2 + end + end + def test_3_reg + assert_reg_to_slot risc(3) , :r1 , :r2 , 4 + end + class TestMessageSetupCache < MomInstructionTest + include Parfait::MethodHelper + + def instruction + method = make_method + cache_entry = Parfait::CacheEntry.new(method.frame_type, method) + MessageSetup.new( cache_entry ) + end + def test_len + assert_equal 5 , all.length , all_str + end + def test_1_load + assert_load risc(1) , Parfait::CacheEntry , :r1 + end + def test_2_slot + assert_slot_to_reg risc(2) ,:r1 , 2 , :r2 + end + def test_3_slot + assert_slot_to_reg risc(3) ,:r0 , 1 , :r3 + end + def test_4_reg + assert_reg_to_slot risc(4) , :r2 , :r3 , 7 + end + + end +end diff --git a/test/mom/instruction/test_not_same_check.rb b/test/mom/instruction/test_not_same_check.rb index 02a88c46..28b7af2b 100644 --- a/test/mom/instruction/test_not_same_check.rb +++ b/test/mom/instruction/test_not_same_check.rb @@ -16,14 +16,10 @@ module Mom assert_slot_to_reg risc(2) ,:r0 , 6 , :r4 end def test_3_op - assert_equal Risc::OperatorInstruction , risc(3).class - assert_equal :r2 , risc(3).left.symbol - assert_equal :r4 , risc(3).right.symbol - assert_equal :- , risc(3).operator + assert_operator risc(3) , :-, :r2 , :r4 end def test_4_zero - assert_equal Risc::IsZero , risc(4).class - assert_label risc(4).label , "target" + assert_zero risc(4) , "target" end end end