1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-12-27 16:12:47 +00:00
parent 0f989b87a0
commit a34db218ad
162 changed files with 1267 additions and 621 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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