diff options
Diffstat (limited to 'spec/ruby/optional')
-rw-r--r-- | spec/ruby/optional/capi/ext/numeric_spec.c | 20 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/rubyspec.h | 1 | ||||
-rw-r--r-- | spec/ruby/optional/capi/hash_spec.rb | 7 | ||||
-rw-r--r-- | spec/ruby/optional/capi/numeric_spec.rb | 24 | ||||
-rw-r--r-- | spec/ruby/optional/capi/string_spec.rb | 18 |
5 files changed, 57 insertions, 13 deletions
diff --git a/spec/ruby/optional/capi/ext/numeric_spec.c b/spec/ruby/optional/capi/ext/numeric_spec.c index 0b7fbabd1c..2f66c7bac7 100644 --- a/spec/ruby/optional/capi/ext/numeric_spec.c +++ b/spec/ruby/optional/capi/ext/numeric_spec.c @@ -9,6 +9,10 @@ static VALUE numeric_spec_size_of_VALUE(VALUE self) { return INT2FIX(sizeof(VALUE)); } +static VALUE numeric_spec_size_of_long_long(VALUE self) { + return INT2FIX(sizeof(LONG_LONG)); +} + #ifdef HAVE_NUM2CHR static VALUE numeric_spec_NUM2CHR(VALUE self, VALUE value) { return INT2FIX(NUM2CHR(value)); @@ -43,6 +47,16 @@ static VALUE numeric_spec_rb_ll2inum_14(VALUE self) { } #endif +#ifdef HAVE_RB_ULL2INUM +static VALUE numeric_spec_rb_ull2inum_14(VALUE self) { + return rb_ull2inum(14); +} + +static VALUE numeric_spec_rb_ull2inum_n14(VALUE self) { + return rb_ull2inum(-14); +} +#endif + #ifdef HAVE_RB_NUM2DBL static VALUE numeric_spec_rb_num2dbl(VALUE self, VALUE num) { return rb_float_new(rb_num2dbl(num)); @@ -121,6 +135,7 @@ void Init_numeric_spec(void) { cls = rb_define_class("CApiNumericSpecs", rb_cObject); rb_define_method(cls, "size_of_VALUE", numeric_spec_size_of_VALUE, 0); + rb_define_method(cls, "size_of_long_long", numeric_spec_size_of_long_long, 0); #ifdef HAVE_NUM2CHR rb_define_method(cls, "NUM2CHR", numeric_spec_NUM2CHR, 1); @@ -143,6 +158,11 @@ void Init_numeric_spec(void) { rb_define_method(cls, "rb_ll2inum_14", numeric_spec_rb_ll2inum_14, 0); #endif +#ifdef HAVE_RB_ULL2INUM + rb_define_method(cls, "rb_ull2inum_14", numeric_spec_rb_ull2inum_14, 0); + rb_define_method(cls, "rb_ull2inum_n14", numeric_spec_rb_ull2inum_n14, 0); +#endif + #ifdef HAVE_RB_NUM2DBL rb_define_method(cls, "rb_num2dbl", numeric_spec_rb_num2dbl, 1); #endif diff --git a/spec/ruby/optional/capi/ext/rubyspec.h b/spec/ruby/optional/capi/ext/rubyspec.h index 50bc9033f0..780c2ab20f 100644 --- a/spec/ruby/optional/capi/ext/rubyspec.h +++ b/spec/ruby/optional/capi/ext/rubyspec.h @@ -412,6 +412,7 @@ #define HAVE_RB_UINT2INUM 1 #define HAVE_RB_INTEGER 1 #define HAVE_RB_LL2INUM 1 +#define HAVE_RB_ULL2INUM 1 #define HAVE_RB_NUM2DBL 1 #if SIZEOF_INT < SIZEOF_LONG #define HAVE_RB_NUM2INT 1 diff --git a/spec/ruby/optional/capi/hash_spec.rb b/spec/ruby/optional/capi/hash_spec.rb index 1c406f0394..1a117bfbf8 100644 --- a/spec/ruby/optional/capi/hash_spec.rb +++ b/spec/ruby/optional/capi/hash_spec.rb @@ -1,4 +1,5 @@ require File.expand_path('../spec_helper', __FILE__) +require File.expand_path('../../../shared/hash/key_error', __FILE__) load_extension("hash") @@ -136,6 +137,12 @@ describe "C-API Hash function" do it "raises a KeyError if the key is not found and no default is set" do lambda { @s.rb_hash_fetch(@hsh, :c) }.should raise_error(KeyError) end + + context "when key is not found" do + it_behaves_like :key_error, -> (obj, key) { + @s.rb_hash_fetch(obj, key) + }, { a: 1 } + end end describe "rb_hash_foreach" do diff --git a/spec/ruby/optional/capi/numeric_spec.rb b/spec/ruby/optional/capi/numeric_spec.rb index ff7880a986..b2f629c1ab 100644 --- a/spec/ruby/optional/capi/numeric_spec.rb +++ b/spec/ruby/optional/capi/numeric_spec.rb @@ -238,7 +238,7 @@ describe "CApiNumericSpecs" do end describe "rb_Integer" do - it "creates a new Integer from a String" do + it "creates an Integer from a String" do i = @s.rb_Integer("8675309") i.should be_kind_of(Integer) i.should eql(8675309) @@ -246,15 +246,29 @@ describe "CApiNumericSpecs" do end describe "rb_ll2inum" do - it "creates a new Fixnum from a small signed long long" 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) 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) + 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) + end + end + describe "rb_int2inum" do - it "creates a new Fixnum from a long" do + it "creates a Fixnum from a long" do i = @s.rb_int2inum_14() i.should be_kind_of(Fixnum) i.should eql(14) @@ -262,13 +276,13 @@ describe "CApiNumericSpecs" do end describe "rb_uint2inum" do - it "creates a new Fixnum from a long" do + it "creates a 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 + 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) diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb index 5f2309d1cd..024a153b1a 100644 --- a/spec/ruby/optional/capi/string_spec.rb +++ b/spec/ruby/optional/capi/string_spec.rb @@ -479,14 +479,16 @@ describe "C-API String function" do describe "SafeStringValue" do it "raises for tained string when $SAFE is 1" do - Thread.new { - $SAFE = 1 - lambda { - @s.SafeStringValue("str".taint) - }.should raise_error(SecurityError) - }.join - ensure - $SAFE = 0 + begin + Thread.new { + $SAFE = 1 + lambda { + @s.SafeStringValue("str".taint) + }.should raise_error(SecurityError) + }.join + ensure + $SAFE = 0 + end end it_behaves_like :string_value_macro, :SafeStringValue |