rubyx/test/slot_machine/compiler/test_assignment.rb
Torsten Rüger 8df2e4bf08 SlotLanguage reborn in the Machine
Just added the compiler, that can parse Slot directly into SlotMachine code (no language layer in between)
Still unclear wheather the Maker is a thing, but since it was in the Language layer i did not remove it (yet)
Otherwise just the compiler and all the tests, moved from the slot_language.
2020-02-19 02:19:14 +07:00

67 lines
2.0 KiB
Ruby

require_relative "../helper"
module SlotMachine
class TestAssignment < MiniTest::Test
include SlotHelper
def compile_assign(str)
assign = compile(str)
assert_equal SlotLoad , assign.class
assign
end
def test_slot_load_rinst
assign = compile_assign("a = @b")
assert_equal "receiver.a" , assign.left.slots.to_s
assert_equal "receiver.b" , assign.right.slots.to_s
end
def test_slot_load_linst
assign = compile_assign("@a = b")
assert_equal "receiver.a" , assign.left.slots.to_s
assert_equal "b" , assign.right.slots.to_s
end
def test_slot_load_lrinst
assign = compile_assign("@a = @b")
assert_equal "receiver.a" , assign.left.slots.to_s
assert_equal "receiver.b" , assign.right.slots.to_s
end
def test_assign
assign = compile_assign("a = b")
assert_equal "receiver.a" , assign.left.slots.to_s
assert_equal "b" , assign.right.slots.to_s
end
end
class TestAssignment2 < MiniTest::Test
include SlotHelper
def test_slot_load_linst_trav
assert_equal SlotLoad , compile_class("@a = b.c")
end
def test_assign1
assign = compile("c = c.next")
assert_equal SlotLoad , assign.class
end
def test_shift
load = compile("a = b.c")
assert_equal SlotLoad , load.class
assert_equal "receiver.a" , load.left.slots.to_s
assert_equal "b.c" , load.right.slots.to_s
end
end
class TestAssignment3 < MiniTest::Test
include SlotHelper
def test_inst_ass
assign = compile("@a.b = c")
assert_equal SlotLoad , assign.class
assert_equal SlottedMessage , assign.left.class
assert_equal "receiver.a.b" , assign.left.slots.to_s
end
def test_local_ass
assign = compile("a.b = c")
assert_equal SlotLoad , assign.class
assert_equal SlottedMessage , assign.left.class
assert_equal "a.b" , assign.left.slots.to_s
assert_equal "c" , assign.right.slots.to_s
end
end
end