Sha256: b19b27042114fdbfc3e19b750afeb337b4d8253a48fe8884991d1bf06aa5e942

Contents?: true

Size: 915 Bytes

Versions: 1

Compression:

Stored size: 915 Bytes

Contents

# frozen_string_literal: true

require 'tataru'

describe Tataru::Instructions::GotoIfInstruction do
  it 'branches if result is non zero' do
    mem = Tataru::Memory.new
    instr = Tataru::Instructions::GotoIfInstruction.new(5)

    mem.hash[:temp] = { result: 1 }

    instr.memory = mem
    instr.run

    expect(mem.program_counter).to eq 4
  end

  it 'does nothing if result is zero' do
    mem = Tataru::Memory.new
    instr = Tataru::Instructions::GotoIfInstruction.new(6)

    mem.hash[:temp] = { result: 0 }

    instr.memory = mem
    instr.run

    expect(mem.program_counter).to eq 0
  end

  it 'goes to label if param is label' do
    mem = Tataru::Memory.new
    instr = Tataru::Instructions::GotoIfInstruction.new('function')

    mem.hash[:labels] = { 'function' => 10 }
    mem.hash[:temp] = { result: 1 }

    instr.memory = mem
    instr.run

    expect(mem.program_counter).to eq 9
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tataru-0.2.0 spec/instructions/goto_if_instruction_spec.rb