summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi/numeric_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/optional/capi/numeric_spec.rb')
-rw-r--r--spec/ruby/optional/capi/numeric_spec.rb214
1 files changed, 105 insertions, 109 deletions
diff --git a/spec/ruby/optional/capi/numeric_spec.rb b/spec/ruby/optional/capi/numeric_spec.rb
index 5301cbcf10..62921f2467 100644
--- a/spec/ruby/optional/capi/numeric_spec.rb
+++ b/spec/ruby/optional/capi/numeric_spec.rb
@@ -7,135 +7,131 @@ describe "CApiNumericSpecs" do
@s = CApiNumericSpecs.new
end
- platform_is wordsize: 64 do
- describe "rb_num2int" do
- it "raises a TypeError if passed nil" do
- lambda { @s.rb_num2int(nil) }.should raise_error(TypeError)
- end
+ describe "NUM2INT" do
+ it "raises a TypeError if passed nil" do
+ lambda { @s.NUM2INT(nil) }.should raise_error(TypeError)
+ end
- it "converts a Float" do
- @s.rb_num2int(4.2).should == 4
- end
+ it "converts a Float" do
+ @s.NUM2INT(4.2).should == 4
+ end
- it "converts a Bignum" do
- @s.rb_num2int(0x7fff_ffff).should == 0x7fff_ffff
- end
+ it "converts a Bignum" do
+ @s.NUM2INT(0x7fff_ffff).should == 0x7fff_ffff
+ end
- it "converts a Fixnum" do
- @s.rb_num2int(5).should == 5
- end
+ it "converts a Fixnum" do
+ @s.NUM2INT(5).should == 5
+ end
- it "converts -1 to an signed number" do
- @s.rb_num2int(-1).should == -1
- end
+ it "converts -1 to an signed number" do
+ @s.NUM2INT(-1).should == -1
+ end
- it "converts a negative Bignum into an signed number" do
- @s.rb_num2int(-2147442171).should == -2147442171
- end
+ it "converts a negative Bignum into an signed number" do
+ @s.NUM2INT(-2147442171).should == -2147442171
+ end
- it "raises a RangeError if the value is more than 32bits" do
- lambda { @s.rb_num2int(0xffff_ffff+1) }.should raise_error(RangeError)
- end
+ it "raises a RangeError if the value is more than 32bits" do
+ lambda { @s.NUM2INT(0xffff_ffff+1) }.should raise_error(RangeError)
+ end
- it "calls #to_int to coerce the value" do
- obj = mock("number")
- obj.should_receive(:to_int).and_return(2)
- @s.rb_num2long(obj).should == 2
- end
+ it "calls #to_int to coerce the value" do
+ obj = mock("number")
+ obj.should_receive(:to_int).and_return(2)
+ @s.NUM2INT(obj).should == 2
end
end
- platform_is wordsize: 64 do
- describe "rb_num2uint" do
- it "raises a TypeError if passed nil" do
- lambda { @s.rb_num2uint(nil) }.should raise_error(TypeError)
- end
+ describe "NUM2UINT" do
+ it "raises a TypeError if passed nil" do
+ lambda { @s.NUM2UINT(nil) }.should raise_error(TypeError)
+ end
- it "converts a Float" do
- @s.rb_num2uint(4.2).should == 4
- end
+ it "converts a Float" do
+ @s.NUM2UINT(4.2).should == 4
+ end
- it "converts a Bignum" do
- @s.rb_num2uint(0xffff_ffff).should == 0xffff_ffff
- end
+ it "converts a Bignum" do
+ @s.NUM2UINT(0xffff_ffff).should == 0xffff_ffff
+ end
- it "converts a Fixnum" do
- @s.rb_num2uint(5).should == 5
- end
+ it "converts a Fixnum" do
+ @s.NUM2UINT(5).should == 5
+ end
- it "converts a negative number to the complement" do
- @s.rb_num2uint(-1).should == 18446744073709551615
- end
+ it "converts a negative number to the complement" do
+ @s.NUM2UINT(-1).should == 4294967295
+ end
- it "converts a signed int value to the complement" do
- @s.rb_num2uint(-0x8000_0000).should == 18446744071562067968
- end
+ it "converts a signed int value to the complement" do
+ @s.NUM2UINT(-0x8000_0000).should == 2147483648
+ end
- it "raises a RangeError if the value is more than 32bits" do
- lambda { @s.rb_num2uint(0xffff_ffff+1) }.should raise_error(RangeError)
- end
+ it "raises a RangeError if the value is more than 32bits" do
+ lambda { @s.NUM2UINT(0xffff_ffff+1) }.should raise_error(RangeError)
+ end
- it "raises a RangeError if the value is less than 32bits negative" do
- lambda { @s.rb_num2uint(-0x8000_0000-1) }.should raise_error(RangeError)
- end
+ it "raises a RangeError if the value is less than 32bits negative" do
+ lambda { @s.NUM2UINT(-0x8000_0000-1) }.should raise_error(RangeError)
+ end
- it "raises a RangeError if the value is more than 64bits" do
- lambda do
- @s.rb_num2uint(0xffff_ffff_ffff_ffff+1)
- end.should raise_error(RangeError)
- end
+ it "raises a RangeError if the value is more than 64bits" do
+ lambda do
+ @s.NUM2UINT(0xffff_ffff_ffff_ffff+1)
+ end.should raise_error(RangeError)
+ end
- it "calls #to_int to coerce the value" do
- obj = mock("number")
- obj.should_receive(:to_int).and_return(2)
- @s.rb_num2uint(obj).should == 2
- end
+ it "calls #to_int to coerce the value" do
+ obj = mock("number")
+ obj.should_receive(:to_int).and_return(2)
+ @s.NUM2UINT(obj).should == 2
end
end
- describe "rb_num2long" do
+ describe "NUM2LONG" do
it "raises a TypeError if passed nil" do
- lambda { @s.rb_num2long(nil) }.should raise_error(TypeError)
+ lambda { @s.NUM2LONG(nil) }.should raise_error(TypeError)
end
it "converts a Float" do
- @s.rb_num2long(4.2).should == 4
+ @s.NUM2LONG(4.2).should == 4
end
it "converts a Bignum" do
- @s.rb_num2long(0x7fff_ffff).should == 0x7fff_ffff
+ @s.NUM2LONG(0x7fff_ffff).should == 0x7fff_ffff
end
it "converts a Fixnum" do
- @s.rb_num2long(5).should == 5
+ @s.NUM2LONG(5).should == 5
end
platform_is wordsize: 32 do
it "converts -1 to an signed number" do
- @s.rb_num2long(-1).should == -1
+ @s.NUM2LONG(-1).should == -1
end
it "converts a negative Bignum into an signed number" do
- @s.rb_num2long(-2147442171).should == -2147442171
+ @s.NUM2LONG(-2147442171).should == -2147442171
end
it "raises a RangeError if the value is more than 32bits" do
- lambda { @s.rb_num2long(0xffff_ffff+1) }.should raise_error(RangeError)
+ lambda { @s.NUM2LONG(0xffff_ffff+1) }.should raise_error(RangeError)
end
end
platform_is wordsize: 64 do
it "converts -1 to an signed number" do
- @s.rb_num2long(-1).should == -1
+ @s.NUM2LONG(-1).should == -1
end
it "converts a negative Bignum into an signed number" do
- @s.rb_num2long(-9223372036854734331).should == -9223372036854734331
+ @s.NUM2LONG(-9223372036854734331).should == -9223372036854734331
end
it "raises a RangeError if the value is more than 64bits" do
lambda do
- @s.rb_num2long(0xffff_ffff_ffff_ffff+1)
+ @s.NUM2LONG(0xffff_ffff_ffff_ffff+1)
end.should raise_error(RangeError)
end
end
@@ -143,89 +139,89 @@ describe "CApiNumericSpecs" do
it "calls #to_int to coerce the value" do
obj = mock("number")
obj.should_receive(:to_int).and_return(2)
- @s.rb_num2long(obj).should == 2
+ @s.NUM2LONG(obj).should == 2
end
end
- describe "rb_int2num" do
+ describe "INT2NUM" do
it "raises a TypeError if passed nil" do
- lambda { @s.rb_int2num(nil) }.should raise_error(TypeError)
+ lambda { @s.INT2NUM(nil) }.should raise_error(TypeError)
end
it "converts a Float" do
- @s.rb_int2num(4.2).should == 4
+ @s.INT2NUM(4.2).should == 4
end
it "raises a RangeError when passed a Bignum" do
- lambda { @s.rb_int2num(bignum_value) }.should raise_error(RangeError)
+ lambda { @s.INT2NUM(bignum_value) }.should raise_error(RangeError)
end
it "converts a Fixnum" do
- @s.rb_int2num(5).should == 5
+ @s.INT2NUM(5).should == 5
end
it "converts a negative Fixnum" do
- @s.rb_int2num(-11).should == -11
+ @s.INT2NUM(-11).should == -11
end
end
- describe "rb_num2ulong" do
+ describe "NUM2ULONG" do
it "raises a TypeError if passed nil" do
- lambda { @s.rb_num2ulong(nil) }.should raise_error(TypeError)
+ lambda { @s.NUM2ULONG(nil) }.should raise_error(TypeError)
end
it "converts a Float" do
- @s.rb_num2ulong(4.2).should == 4
+ @s.NUM2ULONG(4.2).should == 4
end
it "converts a Bignum" do
- @s.rb_num2ulong(0xffff_ffff).should == 0xffff_ffff
+ @s.NUM2ULONG(0xffff_ffff).should == 0xffff_ffff
end
it "converts a Fixnum" do
- @s.rb_num2ulong(5).should == 5
+ @s.NUM2ULONG(5).should == 5
end
platform_is wordsize: 32 do
it "converts -1 to an unsigned number" do
- @s.rb_num2ulong(-1).should == 4294967295
+ @s.NUM2ULONG(-1).should == 4294967295
end
it "converts a negative Bignum into an unsigned number" do
- @s.rb_num2ulong(-2147442171).should == 2147525125
+ @s.NUM2ULONG(-2147442171).should == 2147525125
end
it "converts positive Bignums if the values is less than 64bits" do
- @s.rb_num2ulong(0xffff_ffff).should == 0xffff_ffff
- @s.rb_num2ulong(2**30).should == 2**30
- @s.rb_num2ulong(fixnum_max+1).should == fixnum_max+1
- @s.rb_num2ulong(fixnum_max).should == fixnum_max
+ @s.NUM2ULONG(0xffff_ffff).should == 0xffff_ffff
+ @s.NUM2ULONG(2**30).should == 2**30
+ @s.NUM2ULONG(fixnum_max+1).should == fixnum_max+1
+ @s.NUM2ULONG(fixnum_max).should == fixnum_max
end
it "raises a RangeError if the value is more than 32bits" do
- lambda { @s.rb_num2ulong(0xffff_ffff+1) }.should raise_error(RangeError)
+ lambda { @s.NUM2ULONG(0xffff_ffff+1) }.should raise_error(RangeError)
end
end
platform_is wordsize: 64 do
it "converts -1 to an unsigned number" do
- @s.rb_num2ulong(-1).should == 18446744073709551615
+ @s.NUM2ULONG(-1).should == 18446744073709551615
end
it "converts a negative Bignum into an unsigned number" do
- @s.rb_num2ulong(-9223372036854734331).should == 9223372036854817285
+ @s.NUM2ULONG(-9223372036854734331).should == 9223372036854817285
end
it "converts positive Bignums if the values is less than 64bits" do
- @s.rb_num2ulong(0xffff_ffff_ffff_ffff).should == 0xffff_ffff_ffff_ffff
- @s.rb_num2ulong(2**62).should == 2**62
- @s.rb_num2ulong(fixnum_max+1).should == fixnum_max+1
- @s.rb_num2ulong(fixnum_max).should == fixnum_max
+ @s.NUM2ULONG(0xffff_ffff_ffff_ffff).should == 0xffff_ffff_ffff_ffff
+ @s.NUM2ULONG(2**62).should == 2**62
+ @s.NUM2ULONG(fixnum_max+1).should == fixnum_max+1
+ @s.NUM2ULONG(fixnum_max).should == fixnum_max
end
it "raises a RangeError if the value is more than 64bits" do
lambda do
- @s.rb_num2ulong(0xffff_ffff_ffff_ffff+1)
+ @s.NUM2ULONG(0xffff_ffff_ffff_ffff+1)
end.should raise_error(RangeError)
end
end
@@ -233,7 +229,7 @@ describe "CApiNumericSpecs" do
it "calls #to_int to coerce the value" do
obj = mock("number")
obj.should_receive(:to_int).and_return(2)
- @s.rb_num2ulong(obj).should == 2
+ @s.NUM2ULONG(obj).should == 2
end
end
@@ -289,31 +285,31 @@ describe "CApiNumericSpecs" do
end
end
- describe "rb_num2dbl" do
+ describe "NUM2DBL" do
it "raises a TypeError if passed nil" do
- lambda { @s.rb_num2dbl(nil) }.should raise_error(TypeError)
+ lambda { @s.NUM2DBL(nil) }.should raise_error(TypeError)
end
it "raises a TypeError if passed a String" do
- lambda { @s.rb_num2dbl("1.2") }.should raise_error(TypeError)
+ lambda { @s.NUM2DBL("1.2") }.should raise_error(TypeError)
end
it "converts a Float" do
- @s.rb_num2dbl(4.2).should == 4.2
+ @s.NUM2DBL(4.2).should == 4.2
end
it "converts a Bignum" do
- @s.rb_num2dbl(2**70).should == (2**70).to_f
+ @s.NUM2DBL(2**70).should == (2**70).to_f
end
it "converts a Fixnum" do
- @s.rb_num2dbl(5).should == 5.0
+ @s.NUM2DBL(5).should == 5.0
end
it "calls #to_f to coerce the value" do
obj = mock("number")
obj.should_receive(:to_f).and_return(2.0)
- @s.rb_num2dbl(obj).should == 2.0
+ @s.NUM2DBL(obj).should == 2.0
end
end