2015-10-24 17:12:36 +03:00
|
|
|
require_relative "../helper"
|
|
|
|
|
2017-01-19 09:02:29 +02:00
|
|
|
module Risc
|
2015-10-24 17:12:36 +03:00
|
|
|
class TestInstructions < MiniTest::Test
|
|
|
|
def setup
|
2018-05-31 00:07:58 +03:00
|
|
|
@label = Label.new("test" , "test",FakeAddress.new(5))
|
2015-10-28 21:38:23 +02:00
|
|
|
@branch = Branch.new("test" , @label)
|
|
|
|
@instruction = Instruction.new("test")
|
2015-10-24 17:12:36 +03:00
|
|
|
end
|
2015-10-25 12:10:56 +02:00
|
|
|
def test_branch_tos1
|
|
|
|
assert @branch.to_s.include?("Branch")
|
|
|
|
assert @branch.to_s.include?("test")
|
|
|
|
end
|
|
|
|
def test_branch_tos2
|
2018-11-24 22:40:22 +02:00
|
|
|
branch = Branch.new(nil ,@label)
|
2015-10-25 12:10:56 +02:00
|
|
|
assert branch.to_s.include?("Branch")
|
|
|
|
end
|
|
|
|
def test_label_tos1
|
|
|
|
assert @label.to_s.include?("Label")
|
|
|
|
end
|
|
|
|
def test_label_tos2
|
2018-05-31 00:07:58 +03:00
|
|
|
assert Label.new("nil",nil,FakeAddress.new(2)).to_s.include?("Label")
|
2015-10-25 12:10:56 +02:00
|
|
|
end
|
2015-10-24 17:12:36 +03:00
|
|
|
def test_last_empty
|
|
|
|
assert_equal @instruction, @instruction.last
|
|
|
|
end
|
|
|
|
def test_last_not_empty
|
|
|
|
@instruction.set_next @branch
|
|
|
|
assert_equal @branch, @instruction.last
|
|
|
|
end
|
|
|
|
def test_append_empty
|
|
|
|
@instruction.append @branch
|
|
|
|
assert_equal @branch, @instruction.last
|
|
|
|
end
|
|
|
|
def test_insert
|
|
|
|
@instruction.insert @branch
|
|
|
|
assert_equal @branch, @instruction.last
|
|
|
|
end
|
2018-03-18 10:36:01 +05:30
|
|
|
def test_insert_two
|
|
|
|
@branch << @label
|
|
|
|
@instruction.insert @branch
|
|
|
|
assert_equal @label , @instruction.last
|
|
|
|
end
|
2015-10-24 17:12:36 +03:00
|
|
|
def test_append_not_empty
|
|
|
|
@instruction.append @branch
|
|
|
|
@instruction.append @label
|
|
|
|
assert_equal @label, @instruction.last
|
|
|
|
end
|
|
|
|
def test_next1
|
2016-12-06 12:08:18 +02:00
|
|
|
assert_nil @instruction.next
|
2015-10-24 17:12:36 +03:00
|
|
|
end
|
|
|
|
def test_next2
|
|
|
|
@instruction.set_next @label
|
|
|
|
assert_equal @label , @instruction.next
|
2016-12-06 12:08:18 +02:00
|
|
|
assert_nil @instruction.next(2)
|
2015-10-24 17:12:36 +03:00
|
|
|
end
|
2015-11-03 16:22:24 +02:00
|
|
|
def test_label_is_method
|
2018-05-31 00:07:58 +03:00
|
|
|
label = Label.new("test" , "Object.test" , FakeAddress.new(5))
|
2015-11-03 16:22:24 +02:00
|
|
|
assert label.is_method
|
|
|
|
end
|
|
|
|
def test_label_is_not_method
|
|
|
|
assert ! @label.is_method
|
|
|
|
end
|
2018-04-08 18:52:17 +03:00
|
|
|
def test_insert_self
|
|
|
|
assert_raises {@label.insert(@label)}
|
|
|
|
end
|
2015-10-24 17:12:36 +03:00
|
|
|
end
|
|
|
|
end
|