rubyx/test/slot_language/test_slot_compiler.rb
Torsten Rüger 8cac5c064d Start nexr level p i SlotLanguage, calling it MacroMaker
Since we already have Macros. Macros are nothing more than a list of SlotMachine Instructions. This is what we are aiming to create (which is also what is created in Sol .to_slot)

So the idea came to slot the MacroMaker in there after its done
2019-10-06 19:49:53 +03:00

61 lines
1.7 KiB
Ruby

require_relative "helper"
module SlotLanguage
class TestSlotCompiler < MiniTest::Test
include SlotHelper
def test_init
assert SlotCompiler.new
end
def test_compile
assert_equal SlotMaker , compile("a").class
end
def test_label
label = compile("while_label")
assert_equal SlotMachine::Label , label.class
assert_equal :while_label , label.name
end
def test_slot_load_rinst
assert_equal LoadMaker , compile_class("a = @b")
end
def test_slot_load_linst
assert_equal LoadMaker , compile_class("@a = b")
end
def test_slot_load_lrinst
assert_equal LoadMaker , compile_class("@a = @b")
end
def test_slot_load_linst_trav
assert_equal LoadMaker , compile_class("@a = b.c")
end
def test_slot_load_linst_trav2
assert_equal LoadMaker , compile_class("@a.c = b.c")
end
def test_goto
assert_equal SlotMachine::Jump , compile_class("goto(exit_label)")
end
def test_if
check = compile("goto(exit_label) if(a == b)")
assert_equal CheckMaker , check.class
assert_equal SlotMachine::Jump , check.goto.class
end
def test_assign
assign = compile("c = d")
assert_equal LoadMaker , assign.class
end
def test_assign1
assign = compile("c = c.next")
assert_equal LoadMaker , assign.class
end
def test_assign2
assign = compile("c.next = d")
assert_equal LoadMaker , assign.class
end
def test_multiline
multi = compile("start_label;c = c.next;goto(start_label)")
assert_equal Array , multi.class
assert_equal SlotMachine::Label , multi.first.class
assert_equal SlotMachine::Jump , multi.last.class
end
end
end