From c5ac24c850854856433fd240914de0e0bcad11c4 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 9 Sep 2017 23:36:43 +0300 Subject: [PATCH] check the instructions that are produced in mom --- test/mom/test_if_statement.rb | 3 +++ test/mom/test_while_statement.rb | 3 +++ test/support/compiling.rb | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/test/mom/test_if_statement.rb b/test/mom/test_if_statement.rb index e2b70ca9..8ae01a2d 100644 --- a/test/mom/test_if_statement.rb +++ b/test/mom/test_if_statement.rb @@ -23,5 +23,8 @@ module Mom def test_length assert_equal 9 , @stats.length end + def test_array + check_array [SlotConstant,TruthCheck,Label,SimpleCall,SlotConstant,Label,SimpleCall,SlotConstant,Label] , @stats + end end end diff --git a/test/mom/test_while_statement.rb b/test/mom/test_while_statement.rb index a7bc0fc2..6babbd93 100644 --- a/test/mom/test_while_statement.rb +++ b/test/mom/test_while_statement.rb @@ -23,5 +23,8 @@ module Mom def test_length assert_equal 4 , @stats.length end + def test_array + check_array [Label,SlotConstant,TruthCheck,Label] , @stats + end end end diff --git a/test/support/compiling.rb b/test/support/compiling.rb index 4a563ca3..87a00903 100644 --- a/test/support/compiling.rb +++ b/test/support/compiling.rb @@ -34,6 +34,25 @@ module MomCompile def compile_first_method_flat(input) compile_first_method(input).flatten end + + def check_array( should , is ) + index = 0 + test = is + while(test) + assert_equal should[index] , test.class , "Wrong class for #{index+1}, #{dump(is)}" + index += 1 + test = test.next + end + end + def dump(is) + res =[] + while(is) + res << is.class.name.split("::").last + is = is.next + end + "[#{res.join(',')}]" + end + end