From 7a690cd38d09fbbdfc309d2799f7f7853a1113c2 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 25 Oct 2015 12:10:56 +0200 Subject: [PATCH] fix to_s --- lib/register/instructions/branch.rb | 2 +- test/register/test_instructions.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/register/instructions/branch.rb b/lib/register/instructions/branch.rb index a5edb203..27dce008 100644 --- a/lib/register/instructions/branch.rb +++ b/lib/register/instructions/branch.rb @@ -10,7 +10,7 @@ module Register attr_reader :label def to_s - "#{self.class.name}: #{label.name}" + "#{self.class.name}: #{label ? label.name : ''}" end alias :inspect :to_s diff --git a/test/register/test_instructions.rb b/test/register/test_instructions.rb index 832f2c04..4e286a55 100644 --- a/test/register/test_instructions.rb +++ b/test/register/test_instructions.rb @@ -7,6 +7,20 @@ module Register @branch = Branch.new(nil , @label) @instruction = Instruction.new(nil) end + 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 def test_last_empty assert_equal @instruction, @instruction.last end