summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2020-12-27 17:35:32 +0100
committerBenoit Daloze <eregontp@gmail.com>2020-12-27 17:35:32 +0100
commit727c97da1977544c91b9b3677811da3a44af7d53 (patch)
tree4f027117edad10789db57ff4b83242753a89e39d /spec/ruby/optional/capi
parent267bed0cd91711e2a8c79219e97431ba22137b01 (diff)
Update to ruby/spec@4ce9f41
Diffstat (limited to 'spec/ruby/optional/capi')
-rw-r--r--spec/ruby/optional/capi/bignum_spec.rb6
-rw-r--r--spec/ruby/optional/capi/binding_spec.rb19
-rw-r--r--spec/ruby/optional/capi/ext/binding_spec.c19
-rw-r--r--spec/ruby/optional/capi/hash_spec.rb2
-rw-r--r--spec/ruby/optional/capi/numeric_spec.rb21
-rw-r--r--spec/ruby/optional/capi/object_spec.rb4
-rw-r--r--spec/ruby/optional/capi/util_spec.rb2
7 files changed, 52 insertions, 21 deletions
diff --git a/spec/ruby/optional/capi/bignum_spec.rb b/spec/ruby/optional/capi/bignum_spec.rb
index b20275b8f7..cde929af28 100644
--- a/spec/ruby/optional/capi/bignum_spec.rb
+++ b/spec/ruby/optional/capi/bignum_spec.rb
@@ -187,14 +187,14 @@ describe "CApiBignumSpecs" do
it "returns a Fixnum for a Fixnum input value" do
val = @s.rb_dbl2big(2)
- val.kind_of?(Fixnum).should == true
+ val.kind_of?(Integer).should == true
val.should == 2
end
it "returns a Fixnum for a Float input value" do
val = @s.rb_dbl2big(2.5)
- val.kind_of?(Fixnum).should == true
+ val.kind_of?(Integer).should == true
val.should == 2
end
@@ -202,7 +202,7 @@ describe "CApiBignumSpecs" do
input = 219238102380912830988.5 # chosen by fair dice roll
val = @s.rb_dbl2big(input)
- val.kind_of?(Bignum).should == true
+ val.kind_of?(Integer).should == true
# This value is based on the output of a simple C extension that uses
# rb_dbl2big() to convert the above input value to a Bignum.
diff --git a/spec/ruby/optional/capi/binding_spec.rb b/spec/ruby/optional/capi/binding_spec.rb
new file mode 100644
index 0000000000..966d650c46
--- /dev/null
+++ b/spec/ruby/optional/capi/binding_spec.rb
@@ -0,0 +1,19 @@
+require_relative 'spec_helper'
+
+load_extension("binding")
+
+describe "CApiBindingSpecs" do
+ before :each do
+ @b = CApiBindingSpecs.new
+ end
+
+ describe "Kernel#binding" do
+ it "gives the top-most Ruby binding when called from C" do
+ foo = 14
+ b = @b.get_binding
+ b.local_variable_get(:foo).should == 14
+ b.local_variable_set :foo, 12
+ foo.should == 12
+ end
+ end
+end
diff --git a/spec/ruby/optional/capi/ext/binding_spec.c b/spec/ruby/optional/capi/ext/binding_spec.c
new file mode 100644
index 0000000000..b2e3c88b6d
--- /dev/null
+++ b/spec/ruby/optional/capi/ext/binding_spec.c
@@ -0,0 +1,19 @@
+#include "ruby.h"
+#include "rubyspec.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static VALUE binding_spec_get_binding(VALUE self) {
+ return rb_funcall(self, rb_intern("binding"), 0);
+}
+
+void Init_binding_spec(void) {
+ VALUE cls = rb_define_class("CApiBindingSpecs", rb_cObject);
+ rb_define_method(cls, "get_binding", binding_spec_get_binding, 0);
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/spec/ruby/optional/capi/hash_spec.rb b/spec/ruby/optional/capi/hash_spec.rb
index 75f1978585..a60467a66b 100644
--- a/spec/ruby/optional/capi/hash_spec.rb
+++ b/spec/ruby/optional/capi/hash_spec.rb
@@ -21,7 +21,7 @@ describe "C-API Hash function" do
# The actual conversion is an implementation detail.
# We only care that ultimately we get a Fixnum instance.
- @s.rb_hash(obj).should be_an_instance_of(Fixnum)
+ @s.rb_hash(obj).should.between?(fixnum_min, fixnum_max)
end
it "calls #to_int to converts a value returned by #hash to a Fixnum" do
diff --git a/spec/ruby/optional/capi/numeric_spec.rb b/spec/ruby/optional/capi/numeric_spec.rb
index d433d19274..95213d3f2b 100644
--- a/spec/ruby/optional/capi/numeric_spec.rb
+++ b/spec/ruby/optional/capi/numeric_spec.rb
@@ -264,52 +264,45 @@ describe "CApiNumericSpecs" do
describe "rb_Integer" do
it "creates an Integer from a String" do
i = @s.rb_Integer("8675309")
- i.should be_kind_of(Integer)
- i.should eql(8675309)
+ i.should == 8675309
end
end
describe "rb_ll2inum" do
it "creates a Fixnum from a small signed long long" do
i = @s.rb_ll2inum_14()
- i.should be_kind_of(Fixnum)
- i.should eql(14)
+ i.should == 14
end
end
describe "rb_ull2inum" do
it "creates a Fixnum from a small unsigned long long" do
i = @s.rb_ull2inum_14()
- i.should be_kind_of(Fixnum)
- i.should eql(14)
+ i.should == 14
end
it "creates a positive Bignum from a negative long long" do
i = @s.rb_ull2inum_n14()
- i.should be_kind_of(Bignum)
- i.should eql(2 ** (@s.size_of_long_long * 8) - 14)
+ i.should == (2 ** (@s.size_of_long_long * 8) - 14)
end
end
describe "rb_int2inum" do
it "creates a Fixnum from a long" do
i = @s.rb_int2inum_14()
- i.should be_kind_of(Fixnum)
- i.should eql(14)
+ i.should == 14
end
end
describe "rb_uint2inum" do
it "creates a Fixnum from a long" do
i = @s.rb_uint2inum_14()
- i.should be_kind_of(Fixnum)
- i.should eql(14)
+ i.should == 14
end
it "creates a positive Bignum from a negative long" do
i = @s.rb_uint2inum_n14()
- i.should be_kind_of(Bignum)
- i.should eql(2 ** (@s.size_of_VALUE * 8) - 14)
+ i.should == (2 ** (@s.size_of_VALUE * 8) - 14)
end
end
diff --git a/spec/ruby/optional/capi/object_spec.rb b/spec/ruby/optional/capi/object_spec.rb
index e8e905b237..be149898bd 100644
--- a/spec/ruby/optional/capi/object_spec.rb
+++ b/spec/ruby/optional/capi/object_spec.rb
@@ -448,7 +448,7 @@ describe "CApiObject" do
describe "rb_class_of" do
it "returns the class of an object" do
@o.rb_class_of(nil).should == NilClass
- @o.rb_class_of(0).should == Fixnum
+ @o.rb_class_of(0).should == Integer
@o.rb_class_of(0.1).should == Float
@o.rb_class_of(ObjectTest.new).should == ObjectTest
end
@@ -464,7 +464,7 @@ describe "CApiObject" do
describe "rb_obj_classname" do
it "returns the class name of an object" do
@o.rb_obj_classname(nil).should == 'NilClass'
- @o.rb_obj_classname(0).should == Fixnum.to_s
+ @o.rb_obj_classname(0).should == 'Integer'
@o.rb_obj_classname(0.1).should == 'Float'
@o.rb_obj_classname(ObjectTest.new).should == 'ObjectTest'
end
diff --git a/spec/ruby/optional/capi/util_spec.rb b/spec/ruby/optional/capi/util_spec.rb
index 0251c7c62b..a90c28a78e 100644
--- a/spec/ruby/optional/capi/util_spec.rb
+++ b/spec/ruby/optional/capi/util_spec.rb
@@ -289,7 +289,7 @@ describe "C-API Util function" do
describe "rb_sourceline" do
it "returns the current ruby file" do
- @o.rb_sourceline.should be_kind_of(Fixnum)
+ @o.rb_sourceline.should be_kind_of(Integer)
end
end