Sha256: 6d125cc16479fb2ce0cec7ca4e01c8c03833e74773ad46aa4da6356feae97373

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require 'tataru'

describe Tataru::SubroutineCompiler do
  it 'provides a label' do
    rrep = Tataru::Representations::ResourceRepresentation.new('cat', Tataru::BaseResourceDesc.new, {})
    sc = Tataru::SubroutineCompiler.new(rrep, :pet)

    expect(sc.label).to eq 'pet_cat'
  end

  it 'provides a call instruction' do
    rrep = Tataru::Representations::ResourceRepresentation.new('cat', Tataru::BaseResourceDesc.new, {})
    sc = Tataru::SubroutineCompiler.new(rrep, :pet)

    expect(sc.call_instruction).to eq(call: 'pet_cat')
  end

  it 'throws on unknown subroutine action' do
    rrep = Tataru::Representations::ResourceRepresentation.new('cat', Tataru::BaseResourceDesc.new, {})
    sc = Tataru::SubroutineCompiler.new(rrep, :pet)

    expect { sc.body_instructions }.to raise_error NoMethodError
  end

  it 'provides the standard body instructions' do
    rrep = Tataru::Representations::ResourceRepresentation.new('cat', Tataru::BaseResourceDesc.new, {})
    sc = Tataru::SubroutineCompiler.new(rrep, :pet)
    
    allow(sc).to receive(:pet_instructions) { [:make_pet] }

    expect(sc.body_instructions).to eq [
      :clear,
      :make_pet,
      :return
    ]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tataru-0.2.0 spec/subroutine_compiler_spec.rb