Skip to content

Commit

Permalink
Normalize the code style of the specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Feb 17, 2025
1 parent e0b2314 commit 8765e4a
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 39 deletions.
19 changes: 9 additions & 10 deletions spec/immediate_operand_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'spec_helper'

require 'ronin/asm/immediate_operand'

describe Ronin::ASM::ImmediateOperand do
Expand All @@ -18,50 +17,50 @@
end

describe "#width" do
describe "default width for" do
context "0x100000000 .. 0xffffffffffffffff" do
context "when #width is not explicitly set by #initialize" do
context "and when between 0x100000000 .. 0xffffffffffffffff" do
subject { described_class.new(0xffffffffffffffff).width }

it { expect(subject).to be == 8 }
end

context "-0x800000000 .. -0x7fffffffffffffff" do
context "and when between -0x800000000 .. -0x7fffffffffffffff" do
subject { described_class.new(-0x7fffffffffffffff).width }

it { expect(subject).to be == 8 }
end

context "0x10000 .. 0xffffffff" do
context "and when between 0x10000 .. 0xffffffff" do
subject { described_class.new(0xffffffff).width }

it { expect(subject).to be == 4 }
end

context "-0x80000 .. -0x7fffffff" do
context "and when between -0x80000 .. -0x7fffffff" do
subject { described_class.new(-0x7fffffff).width }

it { expect(subject).to be == 4 }
end

context "0x100 .. 0xffff" do
context "and when between 0x100 .. 0xffff" do
subject { described_class.new(0xffff).width }

it { expect(subject).to be == 2 }
end

context "-0x80 .. -0x7fff" do
context "and when between -0x80 .. -0x7fff" do
subject { described_class.new(-0x7fff).width }

it { expect(subject).to be == 2 }
end

context "0x0 .. 0xff" do
context "and when between 0x00 .. 0xff" do
subject { described_class.new(0xff).width }

it { expect(subject).to be == 1 }
end

context "0x0 .. -0x7f" do
context "and when between 0x00 .. -0x7f" do
subject { described_class.new(-0x7f).width }

it { expect(subject).to be == 1 }
Expand Down
2 changes: 1 addition & 1 deletion spec/instruction_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

require 'ronin/asm/instruction'

require 'ronin/asm/register'
require 'ronin/asm/immediate_operand'
require 'ronin/asm/memory_operand'
Expand Down
2 changes: 1 addition & 1 deletion spec/memory_operand_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

require 'ronin/asm/memory_operand'

require 'ronin/asm/register'

describe Ronin::ASM::MemoryOperand do
Expand Down
1 change: 0 additions & 1 deletion spec/register_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'spec_helper'

require 'ronin/asm/register'

describe Ronin::ASM::Register do
Expand Down
1 change: 0 additions & 1 deletion spec/shellcode_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: US-ASCII

require 'spec_helper'
require 'ronin/asm/shellcode'

Expand Down
14 changes: 7 additions & 7 deletions spec/syntax/att_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

require 'ronin/asm/syntax/att'

require 'ronin/asm/register'
require 'ronin/asm/immediate_operand'
require 'ronin/asm/memory_operand'
Expand All @@ -10,23 +10,23 @@
describe Ronin::ASM::Syntax::ATT do
subject { described_class }

describe "emit_register" do
describe ".emit_register" do
let(:register) { Ronin::ASM::Register.new(:eax, 4) }

it "must prepend a '%' to the register name" do
expect(subject.emit_register(register)).to eq("%eax")
end
end

describe "emit_immediate_operand" do
describe ".emit_immediate_operand" do
let(:operand) { Ronin::ASM::ImmediateOperand.new(255, 1) }

it "must prepend a '$' to the immediate" do
expect(subject.emit_immediate_operand(operand)).to eq("$0xff")
end
end

describe "emit_memory_operand" do
describe ".emit_memory_operand" do
let(:register) { Ronin::ASM::Register.new(:eax, 4) }
let(:operand) { Ronin::ASM::MemoryOperand.new(register) }

Expand Down Expand Up @@ -70,7 +70,7 @@
end
end

describe "emit_instruction" do
describe ".emit_instruction" do
context "with no operands" do
let(:instruction) { Ronin::ASM::Instruction.new(:ret, []) }

Expand Down Expand Up @@ -105,13 +105,13 @@
end
end

describe "emit_section" do
describe ".emit_section" do
it "must emit the section name" do
expect(subject.emit_section(:text)).to eq(".text")
end
end

describe "emit_program" do
describe ".emit_program" do
let(:program) do
Ronin::ASM::Program.new do
mov eax, 0xff
Expand Down
20 changes: 9 additions & 11 deletions spec/syntax/common_spec.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
require 'spec_helper'

require 'ronin/asm/syntax/common'

require 'ronin/asm/label'

describe Ronin::ASM::Syntax::Common do
subject { described_class }

describe "emit_keyword" do
describe ".emit_keyword" do
let(:name) { :_start }

it "must convert a keyword to a String" do
expect(subject.emit_keyword(name)).to eq(name.to_s)
end
end

describe "emit_integer" do
let(:integer) { 255 }
let(:hexadecimal) { "0xff" }
describe ".emit_integer" do
let(:int) { 255 }

it "must convert it into a hexadecimal value" do
expect(subject.emit_integer(integer)).to eq(hexadecimal)
expect(subject.emit_integer(int)).to eq("0xff")
end

context "when given a negative number" do
let(:negative) { -255 }
let(:hexadecimal) { "-0xff" }
let(:int) { -255 }

it "must convert it into a hexadecimal value" do
expect(subject.emit_integer(negative)).to eq(hexadecimal)
expect(subject.emit_integer(int)).to eq("-0xff")
end
end
end

describe "emit_label" do
let(:name) { '_start' }
describe ".emit_label" do
let(:name) { :_start }
let(:label) { Ronin::ASM::Label.new(name) }

it "must append a ':' to the name" do
Expand Down
14 changes: 7 additions & 7 deletions spec/syntax/intel_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

require 'ronin/asm/syntax/intel'

require 'ronin/asm/register'
require 'ronin/asm/immediate_operand'
require 'ronin/asm/memory_operand'
Expand All @@ -10,23 +10,23 @@
describe Ronin::ASM::Syntax::Intel do
subject { described_class }

describe "emit_register" do
describe ".emit_register" do
let(:register) { Ronin::ASM::Register.new(:eax, 4) }

it "must return the register name" do
expect(subject.emit_register(register)).to eq("eax")
end
end

describe "emit_immediate_operand" do
describe ".emit_immediate_operand" do
let(:operand) { Ronin::ASM::ImmediateOperand.new(255, 1) }

it "must prepend a size specifier" do
expect(subject.emit_immediate_operand(operand)).to eq("BYTE 0xff")
end
end

describe "emit_memory_operand" do
describe ".emit_memory_operand" do
let(:register) { Ronin::ASM::Register.new(:eax, 4) }
let(:operand) { Ronin::ASM::MemoryOperand.new(register) }

Expand Down Expand Up @@ -81,7 +81,7 @@
end
end

describe "emit_instruction" do
describe ".emit_instruction" do
context "with no operands" do
let(:instruction) { Ronin::ASM::Instruction.new(:ret, []) }

Expand All @@ -101,13 +101,13 @@
end
end

describe "emit_section" do
describe ".emit_section" do
it "must emit the section name" do
expect(subject.emit_section(:text)).to eq("section .text")
end
end

describe "emit_program" do
describe ".emit_program" do
let(:program) do
Ronin::ASM::Program.new do
mov eax, 0xff
Expand Down

0 comments on commit 8765e4a

Please sign in to comment.