ifs working
This commit is contained in:
@ -4,24 +4,25 @@ require_relative "helper"
|
||||
module Vool
|
||||
class TestConditionIfMom < MiniTest::Test
|
||||
include MomCompile
|
||||
include Mom
|
||||
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@stats = compile_first_method( "if(@a == 5) ; 5.mod4 ; else; 4.mod4 ; end")
|
||||
@first = @stats.first
|
||||
@ins = compile_first_method( "if(@a == 5) ; 5.mod4 ; else; 4.mod4 ; end")
|
||||
end
|
||||
|
||||
def test_if_compiles_as_array
|
||||
assert_equal Mom::IfStatement , @first.class , @stats
|
||||
end
|
||||
def test_condition_compiles_to_slot
|
||||
assert_equal Mom::TruthCheck , @first.condition.class
|
||||
def test_condition
|
||||
assert_equal TruthCheck , @ins.next(12).class
|
||||
end
|
||||
def test_condition_is_slot
|
||||
assert_equal Mom::SlotDefinition , @first.condition.condition.class , @stats
|
||||
assert_equal SlotDefinition , @ins.next(12).condition.class , @ins
|
||||
end
|
||||
def test_hoisetd
|
||||
assert_equal Mom::SlotLoad , @first.hoisted.class
|
||||
def test_hoisted_dynamic_call
|
||||
assert_equal DynamicCall , @ins.next(10).class
|
||||
end
|
||||
def test_array
|
||||
check_array [NotSameCheck,SlotLoad,MessageSetup,SlotLoad,ArgumentTransfer,SimpleCall,SlotLoad,MessageSetup,SlotLoad,ArgumentTransfer,DynamicCall,SlotLoad,TruthCheck,Label,MessageSetup,SlotLoad,ArgumentTransfer,SimpleCall,Jump,Label,MessageSetup,SlotLoad,ArgumentTransfer,SimpleCall,Label], @ins
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
30
test/vool/to_mom/test_if_no_else.rb
Normal file
30
test/vool/to_mom/test_if_no_else.rb
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestIfNoElse < MiniTest::Test
|
||||
include MomCompile
|
||||
include Mom
|
||||
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@ins = compile_first_method( "if(@a) ; 5.mod4 ; end")
|
||||
end
|
||||
|
||||
def test_condition_compiles_to_check
|
||||
assert_equal TruthCheck , @ins.class , @ins
|
||||
end
|
||||
def test_condition_is_slot
|
||||
assert_equal SlotDefinition , @ins.condition.class , @ins
|
||||
end
|
||||
def test_label_after_check
|
||||
assert_equal Label , @ins.next.class , @ins
|
||||
end
|
||||
def test_label_last
|
||||
assert_equal Label , @ins.last.class , @ins
|
||||
end
|
||||
def test_array
|
||||
check_array [TruthCheck,Label,MessageSetup,SlotLoad,ArgumentTransfer,SimpleCall,Label], @ins
|
||||
end
|
||||
end
|
||||
end
|
@ -4,29 +4,27 @@ require_relative "helper"
|
||||
module Vool
|
||||
class TestSimpleIfMom < MiniTest::Test
|
||||
include MomCompile
|
||||
include Mom
|
||||
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@ins = compile_first_method( "if(@a) ; 5.mod4 ; else; 4.mod4 ; end")
|
||||
end
|
||||
|
||||
def test_compiles_not_array
|
||||
assert Array != @ins.class , @ins
|
||||
end
|
||||
def test_if_compiles_as_array
|
||||
assert_equal Mom::IfStatement , @ins.class , @ins
|
||||
end
|
||||
def test_condition_compiles_to_check
|
||||
assert_equal Mom::TruthCheck , @ins.condition.class , @ins
|
||||
assert_equal TruthCheck , @ins.class , @ins
|
||||
end
|
||||
def test_condition_is_slot
|
||||
assert_equal Mom::SlotDefinition , @ins.condition.condition.class , @ins
|
||||
assert_equal SlotDefinition , @ins.condition.class , @ins
|
||||
end
|
||||
def test_nothing_hoisted
|
||||
assert_nil @ins.hoisted , @ins
|
||||
def test_label_after_check
|
||||
assert_equal Label , @ins.next.class , @ins
|
||||
end
|
||||
def test_label_last
|
||||
assert_equal Label , @ins.last.class , @ins
|
||||
end
|
||||
def test_array
|
||||
check_array [SlotLoad,TruthCheck,Label,MessageSetup,ArgumentTransfer,SimpleCall,Label], @ins
|
||||
check_array [TruthCheck,Label,MessageSetup,SlotLoad,ArgumentTransfer,SimpleCall,Jump,Label,MessageSetup,SlotLoad,ArgumentTransfer,SimpleCall,Label], @ins
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user