summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi/bignum_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/optional/capi/bignum_spec.rb')
-rw-r--r--spec/ruby/optional/capi/bignum_spec.rb42
1 files changed, 22 insertions, 20 deletions
diff --git a/spec/ruby/optional/capi/bignum_spec.rb b/spec/ruby/optional/capi/bignum_spec.rb
index cde929af28..ae7552b3f5 100644
--- a/spec/ruby/optional/capi/bignum_spec.rb
+++ b/spec/ruby/optional/capi/bignum_spec.rb
@@ -7,21 +7,23 @@ def ensure_bignum(n)
n
end
-full_range_longs = (fixnum_max == 2**(0.size * 8 - 1) - 1)
+full_range_longs = (fixnum_max == max_long)
+max_ulong = begin
+ require 'rbconfig/sizeof'
+ RbConfig::LIMITS['ULONG_MAX']
+rescue LoadError
+ nil
+end
+# If the system doesn't offer ULONG_MAX, assume 2's complement and derive it
+# from LONG_MAX.
+max_ulong ||= 2 * (max_long + 1) - 1
describe "CApiBignumSpecs" do
before :each do
@s = CApiBignumSpecs.new
-
- if full_range_longs
- @max_long = 2**(0.size * 8 - 1) - 1
- @min_long = -@max_long - 1
- @max_ulong = ensure_bignum(2**(0.size * 8) - 1)
- else
- @max_long = ensure_bignum(2**(0.size * 8 - 1) - 1)
- @min_long = ensure_bignum(-@max_long - 1)
- @max_ulong = ensure_bignum(2**(0.size * 8) - 1)
- end
+ @max_long = max_long
+ @min_long = min_long
+ @max_ulong = ensure_bignum(max_ulong)
end
describe "rb_big2long" do
@@ -33,8 +35,8 @@ describe "CApiBignumSpecs" do
end
it "raises RangeError if passed Bignum overflow long" do
- -> { @s.rb_big2long(ensure_bignum(@max_long + 1)) }.should raise_error(RangeError)
- -> { @s.rb_big2long(ensure_bignum(@min_long - 1)) }.should raise_error(RangeError)
+ -> { @s.rb_big2long(ensure_bignum(@max_long + 1)) }.should.raise(RangeError)
+ -> { @s.rb_big2long(ensure_bignum(@min_long - 1)) }.should.raise(RangeError)
end
end
@@ -47,8 +49,8 @@ describe "CApiBignumSpecs" do
end
it "raises RangeError if passed Bignum overflow long" do
- -> { @s.rb_big2ll(ensure_bignum(@max_long << 40)) }.should raise_error(RangeError)
- -> { @s.rb_big2ll(ensure_bignum(@min_long << 40)) }.should raise_error(RangeError)
+ -> { @s.rb_big2ll(ensure_bignum(@max_long << 40)) }.should.raise(RangeError)
+ -> { @s.rb_big2ll(ensure_bignum(@min_long << 40)) }.should.raise(RangeError)
end
end
@@ -65,8 +67,8 @@ describe "CApiBignumSpecs" do
end
it "raises RangeError if passed Bignum overflow long" do
- -> { @s.rb_big2ulong(ensure_bignum(@max_ulong + 1)) }.should raise_error(RangeError)
- -> { @s.rb_big2ulong(ensure_bignum(@min_long - 1)) }.should raise_error(RangeError)
+ -> { @s.rb_big2ulong(ensure_bignum(@max_ulong + 1)) }.should.raise(RangeError)
+ -> { @s.rb_big2ulong(ensure_bignum(@min_long - 1)) }.should.raise(RangeError)
end
end
@@ -123,7 +125,7 @@ describe "CApiBignumSpecs" do
val.should == @max_ulong
end
- platform_is wordsize: 64 do
+ platform_is c_long_size: 64 do
it "packs max_ulong into 2 ulongs to allow sign bit" do
val = @s.rb_big_pack_length(@max_ulong)
val.should == 2
@@ -212,13 +214,13 @@ describe "CApiBignumSpecs" do
it "raises FloatDomainError for Infinity values" do
inf = 1.0 / 0
- -> { @s.rb_dbl2big(inf) }.should raise_error(FloatDomainError)
+ -> { @s.rb_dbl2big(inf) }.should.raise(FloatDomainError)
end
it "raises FloatDomainError for NaN values" do
nan = 0.0 / 0
- -> { @s.rb_dbl2big(nan) }.should raise_error(FloatDomainError)
+ -> { @s.rb_dbl2big(nan) }.should.raise(FloatDomainError)
end
end
end