Skip to content

Commit

Permalink
Fix integer parameter range specs
Browse files Browse the repository at this point in the history
They raised NoMethodError before, but this issue was hidden by raise_error
without class argument.

I think the intension was here, that integer parameters out of range
can either raise a RangeError or are truncated to the integer size.
This is what the test verifies now.
  • Loading branch information
larskanis committed Jun 2, 2018
1 parent 55ae232 commit e70b13d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions spec/ffi/number_spec.rb
Expand Up @@ -145,32 +145,32 @@ module LibTest
describe "Integer parameter range checking" do
[ 128, -129 ].each do |i|
it ":char call(:char (#{i}))" do
expect { expect(LibTest.ret_int8_t(i)).to eq(i) }.to raise_error
expect { expect(LibTest.ret_s8(i)).to eq(i) }.to raise_error(Exception) { |error| expect([RSpec::Expectations::ExpectationNotMetError, RangeError]).to be_include(error.class) }
end
end
[ -1, 256 ].each do |i|
it ":uchar call(:uchar (#{i}))" do
expect { expect(LibTest.ret_u_int8_t(i)).to eq(i) }.to raise_error
expect { expect(LibTest.ret_u8(i)).to eq(i) }.to raise_error(Exception) { |error| expect([RSpec::Expectations::ExpectationNotMetError, RangeError]).to be_include(error.class) }
end
end
[ 0x8000, -0x8001 ].each do |i|
it ":short call(:short (#{i}))" do
expect { expect(LibTest.ret_int16_t(i)).to eq(i) }.to raise_error
expect { expect(LibTest.ret_s16(i)).to eq(i) }.to raise_error(Exception) { |error| expect([RSpec::Expectations::ExpectationNotMetError, RangeError]).to be_include(error.class) }
end
end
[ -1, 0x10000 ].each do |i|
it ":ushort call(:ushort (#{i}))" do
expect { expect(LibTest.ret_u_int16_t(i)).to eq(i) }.to raise_error
expect { expect(LibTest.ret_u16(i)).to eq(i) }.to raise_error(Exception) { |error| expect([RSpec::Expectations::ExpectationNotMetError, RangeError]).to be_include(error.class) }
end
end
[ 0x80000000, -0x80000001 ].each do |i|
it ":int call(:int (#{i}))" do
expect { expect(LibTest.ret_int32_t(i)).to eq(i) }.to raise_error
expect { expect(LibTest.ret_s32(i)).to eq(i) }.to raise_error(Exception) { |error| expect([RSpec::Expectations::ExpectationNotMetError, RangeError]).to be_include(error.class) }
end
end
[ -1, 0x100000000 ].each do |i|
it ":ushort call(:ushort (#{i}))" do
expect { expect(LibTest.ret_u_int32_t(i)).to eq(i) }.to raise_error
it ":uint call(:uint (#{i}))" do
expect { expect(LibTest.ret_u32(i)).to eq(i) }.to raise_error(Exception) { |error| expect([RSpec::Expectations::ExpectationNotMetError, RangeError]).to be_include(error.class) }
end
end
end
Expand Down

0 comments on commit e70b13d

Please sign in to comment.