Skip to content

Commit b0b32da

Browse files
committed
Add specs for RBIGNUM_SIGN
1 parent b3dffba commit b0b32da

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

spec/ruby/optional/capi/bignum_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ def ensure_bignum(n)
9797
end
9898
end
9999

100+
describe "RBIGNUM_SIGN" do
101+
it "returns 1 for a positive Bignum" do
102+
@s.RBIGNUM_SIGN(bignum_value(1)).should == 1
103+
end
104+
105+
it "returns 0 for a negative Bignum" do
106+
@s.RBIGNUM_SIGN(-bignum_value(1)).should == 0
107+
end
108+
end
109+
100110
describe "rb_big_cmp" do
101111
it "compares a Bignum with a Bignum" do
102112
@s.rb_big_cmp(bignum_value, bignum_value(1)).should == -1

spec/ruby/optional/capi/ext/bignum_spec.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ static VALUE bignum_spec_rb_big2ulong(VALUE self, VALUE num) {
3131
return ULONG2NUM(rb_big2ulong(num));
3232
}
3333

34+
static VALUE bignum_spec_RBIGNUM_SIGN(VALUE self, VALUE val) {
35+
return INT2FIX(RBIGNUM_SIGN(val));
36+
}
37+
3438
static VALUE bignum_spec_rb_big_cmp(VALUE self, VALUE x, VALUE y) {
3539
return rb_big_cmp(x, y);
3640
}
@@ -90,6 +94,7 @@ void Init_bignum_spec(void) {
9094
rb_define_method(cls, "rb_big2long", bignum_spec_rb_big2long, 1);
9195
rb_define_method(cls, "rb_big2str", bignum_spec_rb_big2str, 2);
9296
rb_define_method(cls, "rb_big2ulong", bignum_spec_rb_big2ulong, 1);
97+
rb_define_method(cls, "RBIGNUM_SIGN", bignum_spec_RBIGNUM_SIGN, 1);
9398
rb_define_method(cls, "rb_big_cmp", bignum_spec_rb_big_cmp, 2);
9499
rb_define_method(cls, "rb_big_pack", bignum_spec_rb_big_pack, 1);
95100
rb_define_method(cls, "rb_big_pack_array", bignum_spec_rb_big_pack_array, 2);

0 commit comments

Comments
 (0)