2019-10-04 16:38:51 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module SlotLanguage
|
|
|
|
class TestSlotCompiler < MiniTest::Test
|
2019-10-04 20:06:22 +02:00
|
|
|
include SlotHelper
|
|
|
|
|
2019-10-04 16:38:51 +02:00
|
|
|
def test_init
|
|
|
|
assert SlotCompiler.new
|
|
|
|
end
|
|
|
|
def test_compile
|
2019-10-04 20:06:22 +02:00
|
|
|
assert_equal SlotMaker , compile("a").class
|
|
|
|
end
|
2019-10-06 18:49:53 +02:00
|
|
|
def test_slot_load_rinst
|
2019-10-05 18:37:24 +02:00
|
|
|
assert_equal LoadMaker , compile_class("a = @b")
|
2019-10-05 13:49:45 +02:00
|
|
|
end
|
2019-10-06 18:49:53 +02:00
|
|
|
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
|
2019-10-05 13:49:45 +02:00
|
|
|
def test_if
|
|
|
|
check = compile("goto(exit_label) if(a == b)")
|
|
|
|
assert_equal CheckMaker , check.class
|
2020-02-13 05:59:00 +01:00
|
|
|
assert_equal Goto , check.goto.class
|
2019-10-04 16:38:51 +02:00
|
|
|
end
|
2019-10-05 18:37:24 +02:00
|
|
|
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
|
2019-10-06 18:49:53 +02:00
|
|
|
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
|
2020-02-13 05:59:00 +01:00
|
|
|
assert_equal Goto , multi.last.class
|
2019-10-06 18:49:53 +02:00
|
|
|
end
|
2020-02-09 15:33:34 +01:00
|
|
|
def test_shift
|
|
|
|
load = compile("word = name.member")
|
|
|
|
assert_equal LoadMaker , load.class
|
2020-02-12 09:41:16 +01:00
|
|
|
assert_equal :word , load.left.names.first
|
2020-02-09 15:33:34 +01:00
|
|
|
assert_equal SlotMaker , load.right.class
|
|
|
|
end
|
2019-10-04 16:38:51 +02:00
|
|
|
end
|
|
|
|
end
|