2019-08-06 18:33:27 +03:00
|
|
|
require_relative "helper"
|
|
|
|
|
2019-10-03 20:55:41 +03:00
|
|
|
module SlotMachine
|
|
|
|
class TestSlotCollection < MiniTest::Test
|
|
|
|
include SlotMachineCompile
|
2019-08-06 18:33:27 +03:00
|
|
|
|
|
|
|
def setup
|
2019-10-03 20:55:41 +03:00
|
|
|
@comp = compile_slot( "class Test ; def main(); return 'Hi'; end; end;")
|
2019-08-06 18:33:27 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_class
|
2019-10-03 20:55:41 +03:00
|
|
|
assert_equal SlotCollection , @comp.class
|
2019-08-06 18:33:27 +03:00
|
|
|
end
|
|
|
|
def test_compilers
|
2019-09-28 12:41:38 +03:00
|
|
|
assert_equal 3 , @comp.compilers.num_compilers
|
2019-09-15 15:13:11 +03:00
|
|
|
end
|
|
|
|
def test_init_compilers
|
2019-10-03 20:55:41 +03:00
|
|
|
assert_equal SlotCollection , @comp.init_compilers.class
|
2019-08-06 18:33:27 +03:00
|
|
|
end
|
|
|
|
def test_compilers_bare
|
2019-10-03 20:55:41 +03:00
|
|
|
assert_equal 2 , SlotCollection.new.compilers.num_compilers
|
2019-08-06 18:33:27 +03:00
|
|
|
end
|
|
|
|
def test_append_class
|
2019-10-03 20:55:41 +03:00
|
|
|
assert_equal SlotCollection, (@comp.append @comp).class
|
2019-08-06 18:33:27 +03:00
|
|
|
end
|
|
|
|
end
|
2019-10-03 20:55:41 +03:00
|
|
|
class TestSlotCollectionToRisc < MiniTest::Test
|
|
|
|
include SlotMachineCompile
|
2019-08-08 12:18:36 +03:00
|
|
|
|
|
|
|
def setup
|
2019-10-03 20:55:41 +03:00
|
|
|
@comp = compile_slot( "class Space ; def main(); return 'Hi'; end; end;")
|
2019-08-08 12:18:36 +03:00
|
|
|
@collection = @comp.to_risc()
|
|
|
|
end
|
2019-08-10 21:30:00 +03:00
|
|
|
def compiler
|
2019-09-28 15:07:20 +03:00
|
|
|
@collection.method_compilers
|
2019-08-10 21:30:00 +03:00
|
|
|
end
|
|
|
|
def test_has_to_risc
|
2019-08-08 12:18:36 +03:00
|
|
|
assert_equal Risc::RiscCollection, @collection.class
|
|
|
|
end
|
|
|
|
def test_has_risc_compiler
|
2019-08-10 21:30:00 +03:00
|
|
|
assert_equal Risc::MethodCompiler, compiler.class
|
2019-09-28 15:07:20 +03:00
|
|
|
assert_equal 3, @collection.method_compilers.num_compilers
|
2019-08-10 21:30:00 +03:00
|
|
|
end
|
|
|
|
def test_has_risc_instructions
|
|
|
|
assert_equal Risc::Label, compiler.risc_instructions.class
|
2019-08-23 15:31:04 +03:00
|
|
|
assert_equal 13, compiler.risc_instructions.length
|
2019-08-08 12:18:36 +03:00
|
|
|
end
|
|
|
|
end
|
2019-08-06 18:33:27 +03:00
|
|
|
end
|