From bdb4a40f9ce711bcbd609738b2a80072fa2abbd3 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 28 Oct 2015 21:38:23 +0200 Subject: [PATCH] only string and ast allowed as source --- lib/register/instruction.rb | 6 ++++-- test/register/test_instructions.rb | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/register/instruction.rb b/lib/register/instruction.rb index 0002d751..2123f7cf 100644 --- a/lib/register/instruction.rb +++ b/lib/register/instruction.rb @@ -16,8 +16,10 @@ module Register include Positioned def initialize source , nekst = nil - @source = source - @next = nekst + @source = source + @next = nekst + return unless source + raise "Source must be string or ast node, not #{source.class}" unless source.is_a?(String) or source.is_a?(AST::Node) end attr_reader :source diff --git a/test/register/test_instructions.rb b/test/register/test_instructions.rb index 4e286a55..d904fd61 100644 --- a/test/register/test_instructions.rb +++ b/test/register/test_instructions.rb @@ -3,9 +3,9 @@ require_relative "../helper" module Register class TestInstructions < MiniTest::Test def setup - @label = Label.new(nil , "test") - @branch = Branch.new(nil , @label) - @instruction = Instruction.new(nil) + @label = Label.new("test" , "test") + @branch = Branch.new("test" , @label) + @instruction = Instruction.new("test") end def test_branch_tos1 assert @branch.to_s.include?("Branch")