Sha256: 0bb6f2d0765c588ec1b436b1421022a555676b4fde70532ee595d2c8f77fe6ba

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

require 'spec_helper'

require 'ronin/asm/instruction'
require 'ronin/asm/register'
require 'ronin/asm/immediate_operand'
require 'ronin/asm/memory_operand'

describe Instruction do
  let(:register) { Register.new(:eax, 4) }
  let(:immediate)  { ImmediateOperand.new(0xff, 1)  }

  describe "#initialize" do
    let(:name)     { :mov }
    let(:operands) { [immediate, register] }

    subject { described_class.new(name,operands) }

    it "should set the name" do
      subject.name.should == :mov
    end

    it "should set the operands" do
      subject.operands.should == operands
    end

    context "when given an Integer operand" do
      let(:integer) { 0xff }

      subject { described_class.new(name, [integer, register]) }

      it "should wrap the operand to in a ImmediateOperand" do
        subject.operands[0].should be_kind_of(ImmediateOperand)
        subject.operands[0].value.should == integer
      end
    end

    context "when given a nil operand" do
      subject { described_class.new(name, [nil, register]) }

      it "should wrap the operand to in a ImmediateOperand" do
        subject.operands[0].should be_kind_of(ImmediateOperand)
        subject.operands[0].value.should == 0
      end
    end
  end

  describe "#width" do
    subject { described_class.new(:mov, [immediate, register]) }

    it "should return the maximum width of the operands" do
      subject.width.should == register.width
    end

    context "when one of the operands does not define #width" do
      subject { described_class.new(:mov, [:label, register]) }

      it "should ignore them" do
        subject.width.should == register.width
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ronin-asm-0.2.0 spec/asm/instruction_spec.rb
ronin-asm-0.1.0 spec/instruction_spec.rb