2015-10-24 16:12:36 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
2017-01-19 08:02:29 +01:00
|
|
|
module Risc
|
2015-10-24 16:12:36 +02:00
|
|
|
class TestInstructions < MiniTest::Test
|
|
|
|
def setup
|
2015-10-28 20:38:23 +01:00
|
|
|
@label = Label.new("test" , "test")
|
|
|
|
@branch = Branch.new("test" , @label)
|
|
|
|
@instruction = Instruction.new("test")
|
2015-10-24 16:12:36 +02:00
|
|
|
end
|
2015-10-25 11:10:56 +01:00
|
|
|
def test_branch_tos1
|
|
|
|
assert @branch.to_s.include?("Branch")
|
|
|
|
assert @branch.to_s.include?("test")
|
|
|
|
end
|
|
|
|
def test_branch_tos2
|
|
|
|
branch = Branch.new(nil ,nil)
|
|
|
|
assert branch.to_s.include?("Branch")
|
|
|
|
end
|
|
|
|
def test_label_tos1
|
|
|
|
assert @label.to_s.include?("Label")
|
|
|
|
end
|
|
|
|
def test_label_tos2
|
|
|
|
assert Label.new(nil,nil).to_s.include?("Label")
|
|
|
|
end
|
2015-10-24 16:12:36 +02: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
|
|
|
|
def test_append_not_empty
|
|
|
|
@instruction.append @branch
|
|
|
|
@instruction.append @label
|
|
|
|
assert_equal @label, @instruction.last
|
|
|
|
end
|
|
|
|
def test_next1
|
2016-12-06 11:08:18 +01:00
|
|
|
assert_nil @instruction.next
|
2015-10-24 16:12:36 +02:00
|
|
|
end
|
|
|
|
def test_next2
|
|
|
|
@instruction.set_next @label
|
|
|
|
assert_equal @label , @instruction.next
|
2016-12-06 11:08:18 +01:00
|
|
|
assert_nil @instruction.next(2)
|
2015-10-24 16:12:36 +02:00
|
|
|
end
|
|
|
|
def test_replace
|
|
|
|
@instruction.append @branch
|
|
|
|
@instruction.replace_next @label
|
|
|
|
assert_equal @label, @instruction.last
|
|
|
|
assert_equal @label, @instruction.next
|
2017-01-04 20:32:09 +01:00
|
|
|
assert_equal 2 , @instruction.length , @instruction.to_arr
|
2015-10-24 16:12:36 +02:00
|
|
|
end
|
2015-11-03 10:23:15 +01:00
|
|
|
def test_each_label1
|
|
|
|
@instruction.set_next @label
|
|
|
|
start = Label.new("test" , "test" , @instruction)
|
|
|
|
count = 0
|
|
|
|
start.each_label { |l| count += 1 }
|
|
|
|
assert_equal 2 , count
|
|
|
|
end
|
|
|
|
def test_each_label2
|
|
|
|
@instruction.set_next @branch
|
|
|
|
start = Label.new("test" , "test" , @instruction)
|
|
|
|
count = 0
|
|
|
|
start.each_label { |l| count += 1 }
|
|
|
|
assert_equal 2 , count
|
|
|
|
end
|
2015-11-03 15:22:24 +01:00
|
|
|
def test_label_is_method
|
|
|
|
label = Label.new("test" , "Object.test")
|
|
|
|
assert label.is_method
|
|
|
|
end
|
|
|
|
def test_label_is_not_method
|
|
|
|
assert ! @label.is_method
|
|
|
|
end
|
2015-10-24 16:12:36 +02:00
|
|
|
end
|
|
|
|
end
|