summaryrefslogtreecommitdiff
path: root/spec/ruby/optional
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-27 16:12:47 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-27 16:12:47 +0000
commita34db218ade33b79e7404488db5a15bad2841c25 (patch)
tree2ed22ad149cd75e36d9aabbe29b32e96c27fa3a6 /spec/ruby/optional
parent0f989b87a06563add3fdeb9cda983492e8a420af (diff)
Update to ruby/spec@0fe33ac
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/optional')
-rw-r--r--spec/ruby/optional/capi/array_spec.rb12
-rw-r--r--spec/ruby/optional/capi/ext/numeric_spec.c21
-rw-r--r--spec/ruby/optional/capi/ext/rubyspec.h1
-rw-r--r--spec/ruby/optional/capi/module_spec.rb8
-rw-r--r--spec/ruby/optional/capi/numeric_spec.rb28
-rw-r--r--spec/ruby/optional/capi/object_spec.rb12
-rw-r--r--spec/ruby/optional/capi/struct_spec.rb4
7 files changed, 68 insertions, 18 deletions
diff --git a/spec/ruby/optional/capi/array_spec.rb b/spec/ruby/optional/capi/array_spec.rb
index 2fd898ad94..d0f9c0b814 100644
--- a/spec/ruby/optional/capi/array_spec.rb
+++ b/spec/ruby/optional/capi/array_spec.rb
@@ -83,8 +83,8 @@ describe "C-API Array function" do
@s.rb_ary_cat([1, 2], 3, 4).should == [1, 2, 3, 4]
end
- it "raises a RuntimeError if the array is frozen" do
- lambda { @s.rb_ary_cat([].freeze, 1) }.should raise_error(RuntimeError)
+ it "raises a #{frozen_error_class} if the array is frozen" do
+ lambda { @s.rb_ary_cat([].freeze, 1) }.should raise_error(frozen_error_class)
end
end
@@ -130,8 +130,8 @@ describe "C-API Array function" do
@s.rb_ary_rotate([1, 2, 3, 4], -3).should == [2, 3, 4, 1]
end
- it "raises a RuntimeError if the array is frozen" do
- lambda { @s.rb_ary_rotate([].freeze, 1) }.should raise_error(RuntimeError)
+ it "raises a #{frozen_error_class} if the array is frozen" do
+ lambda { @s.rb_ary_rotate([].freeze, 1) }.should raise_error(frozen_error_class)
end
end
@@ -214,9 +214,9 @@ describe "C-API Array function" do
a.should == [nil, nil, 7]
end
- it "raises a RuntimeError if the array is frozen" do
+ it "raises a #{frozen_error_class} if the array is frozen" do
a = [1, 2, 3].freeze
- lambda { @s.rb_ary_store(a, 1, 5) }.should raise_error(RuntimeError)
+ lambda { @s.rb_ary_store(a, 1, 5) }.should raise_error(frozen_error_class)
end
end
diff --git a/spec/ruby/optional/capi/ext/numeric_spec.c b/spec/ruby/optional/capi/ext/numeric_spec.c
index 2f0f504549..0b7fbabd1c 100644
--- a/spec/ruby/optional/capi/ext/numeric_spec.c
+++ b/spec/ruby/optional/capi/ext/numeric_spec.c
@@ -5,6 +5,10 @@
extern "C" {
#endif
+static VALUE numeric_spec_size_of_VALUE(VALUE self) {
+ return INT2FIX(sizeof(VALUE));
+}
+
#ifdef HAVE_NUM2CHR
static VALUE numeric_spec_NUM2CHR(VALUE self, VALUE value) {
return INT2FIX(NUM2CHR(value));
@@ -17,6 +21,16 @@ static VALUE numeric_spec_rb_int2inum_14(VALUE self) {
}
#endif
+#ifdef HAVE_RB_UINT2INUM
+static VALUE numeric_spec_rb_uint2inum_14(VALUE self) {
+ return rb_uint2inum(14);
+}
+
+static VALUE numeric_spec_rb_uint2inum_n14(VALUE self) {
+ return rb_uint2inum(-14);
+}
+#endif
+
#ifdef HAVE_RB_INTEGER
static VALUE numeric_spec_rb_Integer(VALUE self, VALUE str) {
return rb_Integer(str);
@@ -106,6 +120,8 @@ void Init_numeric_spec(void) {
VALUE cls;
cls = rb_define_class("CApiNumericSpecs", rb_cObject);
+ rb_define_method(cls, "size_of_VALUE", numeric_spec_size_of_VALUE, 0);
+
#ifdef HAVE_NUM2CHR
rb_define_method(cls, "NUM2CHR", numeric_spec_NUM2CHR, 1);
#endif
@@ -114,6 +130,11 @@ void Init_numeric_spec(void) {
rb_define_method(cls, "rb_int2inum_14", numeric_spec_rb_int2inum_14, 0);
#endif
+#ifdef HAVE_RB_UINT2INUM
+ rb_define_method(cls, "rb_uint2inum_14", numeric_spec_rb_uint2inum_14, 0);
+ rb_define_method(cls, "rb_uint2inum_n14", numeric_spec_rb_uint2inum_n14, 0);
+#endif
+
#ifdef HAVE_RB_INTEGER
rb_define_method(cls, "rb_Integer", numeric_spec_rb_Integer, 1);
#endif
diff --git a/spec/ruby/optional/capi/ext/rubyspec.h b/spec/ruby/optional/capi/ext/rubyspec.h
index 341cff0428..50bc9033f0 100644
--- a/spec/ruby/optional/capi/ext/rubyspec.h
+++ b/spec/ruby/optional/capi/ext/rubyspec.h
@@ -409,6 +409,7 @@
#define HAVE_NUM2CHR 1
#define HAVE_RB_CMPINT 1
#define HAVE_RB_INT2INUM 1
+#define HAVE_RB_UINT2INUM 1
#define HAVE_RB_INTEGER 1
#define HAVE_RB_LL2INUM 1
#define HAVE_RB_NUM2DBL 1
diff --git a/spec/ruby/optional/capi/module_spec.rb b/spec/ruby/optional/capi/module_spec.rb
index fbb5bd690d..909fa62b89 100644
--- a/spec/ruby/optional/capi/module_spec.rb
+++ b/spec/ruby/optional/capi/module_spec.rb
@@ -307,12 +307,12 @@ describe "CApiModule" do
@frozen = @class.dup.freeze
end
- it "raises a RuntimeError when passed a name" do
- lambda { @m.rb_undef_method @frozen, "ruby_test_method" }.should raise_error(RuntimeError)
+ it "raises a #{frozen_error_class} when passed a name" do
+ lambda { @m.rb_undef_method @frozen, "ruby_test_method" }.should raise_error(frozen_error_class)
end
- it "raises a RuntimeError when passed a missing name" do
- lambda { @m.rb_undef_method @frozen, "not_exist" }.should raise_error(RuntimeError)
+ it "raises a #{frozen_error_class} when passed a missing name" do
+ lambda { @m.rb_undef_method @frozen, "not_exist" }.should raise_error(frozen_error_class)
end
end
end
diff --git a/spec/ruby/optional/capi/numeric_spec.rb b/spec/ruby/optional/capi/numeric_spec.rb
index 1d4a44d7a2..ff7880a986 100644
--- a/spec/ruby/optional/capi/numeric_spec.rb
+++ b/spec/ruby/optional/capi/numeric_spec.rb
@@ -195,6 +195,13 @@ describe "CApiNumericSpecs" do
@s.rb_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
+ end
+
it "raises a RangeError if the value is more than 32bits" do
lambda { @s.rb_num2ulong(0xffff_ffff+1) }.should raise_error(RangeError)
end
@@ -209,6 +216,13 @@ describe "CApiNumericSpecs" do
@s.rb_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
+ end
+
it "raises a RangeError if the value is more than 64bits" do
lambda do
@s.rb_num2ulong(0xffff_ffff_ffff_ffff+1)
@@ -247,6 +261,20 @@ describe "CApiNumericSpecs" do
end
end
+ describe "rb_uint2inum" do
+ it "creates a new Fixnum from a long" do
+ i = @s.rb_uint2inum_14()
+ i.should be_kind_of(Fixnum)
+ i.should eql(14)
+ end
+
+ it "creates a new 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)
+ end
+ end
+
describe "rb_num2dbl" do
it "raises a TypeError if passed nil" do
lambda { @s.rb_num2dbl(nil) }.should raise_error(TypeError)
diff --git a/spec/ruby/optional/capi/object_spec.rb b/spec/ruby/optional/capi/object_spec.rb
index 97bff38ec0..55faa27af5 100644
--- a/spec/ruby/optional/capi/object_spec.rb
+++ b/spec/ruby/optional/capi/object_spec.rb
@@ -313,8 +313,8 @@ describe "CApiObject" do
it "does not rescue exceptions raised by #to_ary" do
obj = mock("to_ary")
- obj.should_receive(:to_ary).and_raise(RuntimeError)
- lambda { @o.rb_check_array_type obj }.should raise_error(RuntimeError)
+ obj.should_receive(:to_ary).and_raise(frozen_error_class)
+ lambda { @o.rb_check_array_type obj }.should raise_error(frozen_error_class)
end
end
@@ -666,14 +666,14 @@ describe "CApiObject" do
obj.tainted?.should == true
end
- it "raises a RuntimeError if the object passed is frozen" do
- lambda { @o.rb_obj_taint("".freeze) }.should raise_error(RuntimeError)
+ it "raises a #{frozen_error_class} if the object passed is frozen" do
+ lambda { @o.rb_obj_taint("".freeze) }.should raise_error(frozen_error_class)
end
end
describe "rb_check_frozen" do
- it "raises a RuntimeError if the obj is frozen" do
- lambda { @o.rb_check_frozen("".freeze) }.should raise_error(RuntimeError)
+ it "raises a #{frozen_error_class} if the obj is frozen" do
+ lambda { @o.rb_check_frozen("".freeze) }.should raise_error(frozen_error_class)
end
it "does nothing when object isn't frozen" do
diff --git a/spec/ruby/optional/capi/struct_spec.rb b/spec/ruby/optional/capi/struct_spec.rb
index 9a0eafeb7b..e779312bef 100644
--- a/spec/ruby/optional/capi/struct_spec.rb
+++ b/spec/ruby/optional/capi/struct_spec.rb
@@ -184,9 +184,9 @@ describe "C-API Struct function" do
lambda { @s.rb_struct_aset(@struct, 3, 1) }.should raise_error(IndexError)
end
- it "raises a RuntimeError if the struct is frozen" do
+ it "raises a #{frozen_error_class} if the struct is frozen" do
@struct.freeze
- lambda { @s.rb_struct_aset(@struct, :a, 1) }.should raise_error(RuntimeError)
+ lambda { @s.rb_struct_aset(@struct, :a, 1) }.should raise_error(frozen_error_class)
end
end