2018-04-06 13:21:38 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
|
|
|
module Risc
|
2018-06-29 12:27:57 +02:00
|
|
|
class TestCodeBuilder < MiniTest::Test
|
2018-04-06 13:54:24 +02:00
|
|
|
|
|
|
|
def setup
|
2019-02-08 22:03:23 +01:00
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
2018-07-01 13:12:42 +02:00
|
|
|
Risc.boot!
|
2019-10-03 19:55:41 +02:00
|
|
|
label = SlotMachine::Label.new( "source_name", "return_label")
|
2019-09-15 11:58:43 +02:00
|
|
|
@builder = Risc::MethodCompiler.new( FakeCallable.new ,label).builder("source")
|
2018-05-29 19:26:00 +02:00
|
|
|
@label = Risc.label("source","name")
|
2018-08-19 12:16:07 +02:00
|
|
|
@start = @builder.compiler.current
|
|
|
|
end
|
|
|
|
def built
|
|
|
|
@start.next
|
2018-04-06 13:54:24 +02:00
|
|
|
end
|
2018-04-06 23:35:54 +02:00
|
|
|
def test_has_build
|
|
|
|
assert @builder.respond_to?(:build)
|
|
|
|
end
|
|
|
|
def test_has_attribute
|
|
|
|
assert_nil @builder.built
|
|
|
|
end
|
2018-04-06 21:54:54 +02:00
|
|
|
def test_message
|
|
|
|
reg = @builder.message
|
2020-03-02 12:48:21 +01:00
|
|
|
assert_equal :message , reg.symbol
|
2018-07-15 14:16:12 +02:00
|
|
|
assert_equal :Message , reg.type.class_name
|
2018-04-06 21:54:54 +02:00
|
|
|
end
|
2018-04-07 23:50:51 +02:00
|
|
|
def test_if_zero
|
|
|
|
ret = @builder.if_zero @label
|
|
|
|
assert_equal IsZero , ret.class
|
|
|
|
assert_equal @label , ret.label
|
|
|
|
end
|
|
|
|
def test_if_not_zero
|
|
|
|
ret = @builder.if_not_zero @label
|
|
|
|
assert_equal IsNotZero , ret.class
|
|
|
|
assert_equal @label , ret.label
|
|
|
|
end
|
|
|
|
def test_branch
|
|
|
|
ret = @builder.branch @label
|
|
|
|
assert_equal Branch , ret.class
|
|
|
|
assert_equal @label , ret.label
|
|
|
|
end
|
2018-04-06 13:21:38 +02:00
|
|
|
end
|
|
|
|
end
|