From f624e38dbb80ab962c0e1da907dcc513cc29513c Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 18 Jul 2018 13:57:38 +0300 Subject: [PATCH] finish assign test start ifs --- test/vool/blocks/helper.rb | 1 + test/vool/blocks/test_assign.rb | 37 ++++++++++++--------------- test/vool/blocks/test_if_condition.rb | 30 ++++++++++++++++++++++ test/vool/test_if_condition.rb | 1 - 4 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 test/vool/blocks/test_if_condition.rb diff --git a/test/vool/blocks/helper.rb b/test/vool/blocks/helper.rb index e69de29b..26258082 100644 --- a/test/vool/blocks/helper.rb +++ b/test/vool/blocks/helper.rb @@ -0,0 +1 @@ +require_relative "../helper" diff --git a/test/vool/blocks/test_assign.rb b/test/vool/blocks/test_assign.rb index 783b01dc..c4c3634b 100644 --- a/test/vool/blocks/test_assign.rb +++ b/test/vool/blocks/test_assign.rb @@ -19,11 +19,8 @@ module VoolBlocks def test_slot_starts_at_message assert_equal :message , @ins.left.known_object end - def test_slot_gets_self - assert_equal :frame , @ins.left.slots[0] - end - def test_slot_assigns_to_local - assert_equal :local , @ins.left.slots[-1] + def test_slots_left + assert_equal [:frame , :local] , @ins.left.slots end def test_slot_assigns_something assert @ins.right @@ -33,41 +30,39 @@ module VoolBlocks end end - #otherwise as above, but assigning instance, so should get a SlotLoad class TestAssignMomInstanceToLocal < MiniTest::Test include MomCompile def setup Parfait.boot! - @ins = compile_first_block( "local = @a" , "@a = 5") + @ins = compile_first_block( "local = @a" , "@a = 5") #second arg in method scope end def test_class_compiles assert_equal Mom::SlotLoad , @ins.class , @ins end + def test_slots_left + assert_equal [:frame, :local] , @ins.left.slots + end + def test_slots_right + assert_equal [:receiver, :a] , @ins.right.slots + end end - #compiling to an argument should result in different second parameter in the slot array class TestAssignToArg < MiniTest::Test include MomCompile def setup Parfait.boot! - @ins = compile_first_method( "arg = 5") + @ins = compile_first_block( "arg = 5") end - def pest_class_compiles + def test_class_compiles assert_equal Mom::SlotLoad , @ins.class , @ins end - def pest_slot_is_set + def test_slot_is_set assert @ins.left end - def pest_slot_starts_at_message - assert_equal :message , @ins.left.known_object - end - def pest_slot_gets_self - assert_equal :arguments , @ins.left.slots[0] - end - def pest_slot_assigns_to_local - assert_equal :arg , @ins.left.slots[-1] + def test_slots_left + assert_equal [:caller, :arguments, :arg] , @ins.left.slots end end @@ -76,12 +71,12 @@ module VoolBlocks def setup Parfait.boot! end - def pest_assigns_const + def test_assigns_const @ins = compile_first_method( "@a = 5") assert_equal Mom::SlotLoad , @ins.class , @ins assert_equal Mom::IntegerConstant , @ins.right.known_object.class , @ins end - def pest_assigns_move + def test_assigns_move @ins = compile_first_method( "@a = arg") assert_equal Mom::SlotLoad , @ins.class , @ins assert_equal Mom::SlotDefinition , @ins.right.class , @ins diff --git a/test/vool/blocks/test_if_condition.rb b/test/vool/blocks/test_if_condition.rb new file mode 100644 index 00000000..af5fc90e --- /dev/null +++ b/test/vool/blocks/test_if_condition.rb @@ -0,0 +1,30 @@ +require_relative "helper" + +module VoolBlocks + class TestConditionIfMom #< MiniTest::Test + include MomCompile + include Mom + + def setup + Parfait.boot! + Risc::Builtin.boot_functions + @ins = compile_first_block( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end") + end + + def test_condition + assert_equal TruthCheck , @ins.next(4).class + end + def test_condition_is_slot + assert_equal SlotDefinition , @ins.next(4).condition.class , @ins + end + def test_hoisted_dynamic_call + assert_equal SimpleCall , @ins.next(2).class + assert_equal :div4 , @ins.next(2).method.name + end + def test_array + check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, TruthCheck, Label , + SlotLoad, Jump, Label, SlotLoad, Label] , @ins + end + + end +end diff --git a/test/vool/test_if_condition.rb b/test/vool/test_if_condition.rb index f8058324..19d4ec4f 100644 --- a/test/vool/test_if_condition.rb +++ b/test/vool/test_if_condition.rb @@ -1,4 +1,3 @@ - require_relative "helper" module Vool