diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-27 13:12:39 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-27 13:12:39 +0000 |
commit | 42921458ff7eacd1ef614c3e67596c75ccd0a1d4 (patch) | |
tree | 710c40988e51715f84a12c3295162b1c5697bf51 /spec/ruby/optional/capi | |
parent | a53ee2136ff59ebc54ae6c98a500765bc3d13d44 (diff) | |
download | ruby-42921458ff7eacd1ef614c3e67596c75ccd0a1d4.tar.gz |
Update to ruby/spec@e57f49c
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/optional/capi')
-rw-r--r-- | spec/ruby/optional/capi/bignum_spec.rb | 10 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/bignum_spec.c | 5 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/kernel_spec.c | 4 | ||||
-rw-r--r-- | spec/ruby/optional/capi/kernel_spec.rb | 26 |
4 files changed, 45 insertions, 0 deletions
diff --git a/spec/ruby/optional/capi/bignum_spec.rb b/spec/ruby/optional/capi/bignum_spec.rb index ee95550680..a5863519b6 100644 --- a/spec/ruby/optional/capi/bignum_spec.rb +++ b/spec/ruby/optional/capi/bignum_spec.rb @@ -97,6 +97,16 @@ describe "CApiBignumSpecs" do end end + describe "RBIGNUM_SIGN" do + it "returns 1 for a positive Bignum" do + @s.RBIGNUM_SIGN(bignum_value(1)).should == 1 + end + + it "returns 0 for a negative Bignum" do + @s.RBIGNUM_SIGN(-bignum_value(1)).should == 0 + end + end + describe "rb_big_cmp" do it "compares a Bignum with a Bignum" do @s.rb_big_cmp(bignum_value, bignum_value(1)).should == -1 diff --git a/spec/ruby/optional/capi/ext/bignum_spec.c b/spec/ruby/optional/capi/ext/bignum_spec.c index a773e06436..14a51f5099 100644 --- a/spec/ruby/optional/capi/ext/bignum_spec.c +++ b/spec/ruby/optional/capi/ext/bignum_spec.c @@ -31,6 +31,10 @@ static VALUE bignum_spec_rb_big2ulong(VALUE self, VALUE num) { return ULONG2NUM(rb_big2ulong(num)); } +static VALUE bignum_spec_RBIGNUM_SIGN(VALUE self, VALUE val) { + return INT2FIX(RBIGNUM_SIGN(val)); +} + static VALUE bignum_spec_rb_big_cmp(VALUE self, VALUE x, VALUE y) { return rb_big_cmp(x, y); } @@ -90,6 +94,7 @@ void Init_bignum_spec(void) { rb_define_method(cls, "rb_big2long", bignum_spec_rb_big2long, 1); rb_define_method(cls, "rb_big2str", bignum_spec_rb_big2str, 2); rb_define_method(cls, "rb_big2ulong", bignum_spec_rb_big2ulong, 1); + rb_define_method(cls, "RBIGNUM_SIGN", bignum_spec_RBIGNUM_SIGN, 1); rb_define_method(cls, "rb_big_cmp", bignum_spec_rb_big_cmp, 2); rb_define_method(cls, "rb_big_pack", bignum_spec_rb_big_pack, 1); rb_define_method(cls, "rb_big_pack_array", bignum_spec_rb_big_pack_array, 2); diff --git a/spec/ruby/optional/capi/ext/kernel_spec.c b/spec/ruby/optional/capi/ext/kernel_spec.c index a4879b0523..5ec45f542c 100644 --- a/spec/ruby/optional/capi/ext/kernel_spec.c +++ b/spec/ruby/optional/capi/ext/kernel_spec.c @@ -26,6 +26,9 @@ VALUE kernel_spec_rb_block_proc(VALUE self) { return rb_block_proc(); } +VALUE kernel_spec_rb_block_lambda(VALUE self) { + return rb_block_lambda(); +} VALUE block_call_inject(VALUE yield_value, VALUE data2) { /* yield_value yields the first block argument */ @@ -286,6 +289,7 @@ void Init_kernel_spec(void) { rb_define_method(cls, "rb_block_call_multi_arg", kernel_spec_rb_block_call_multi_arg, 1); rb_define_method(cls, "rb_block_call_no_func", kernel_spec_rb_block_call_no_func, 1); rb_define_method(cls, "rb_block_proc", kernel_spec_rb_block_proc, 0); + rb_define_method(cls, "rb_block_lambda", kernel_spec_rb_block_lambda, 0); rb_define_method(cls, "rb_frame_this_func_test", kernel_spec_rb_frame_this_func, 0); rb_define_method(cls, "rb_frame_this_func_test_again", kernel_spec_rb_frame_this_func, 0); rb_define_method(cls, "rb_ensure", kernel_spec_rb_ensure, 4); diff --git a/spec/ruby/optional/capi/kernel_spec.rb b/spec/ruby/optional/capi/kernel_spec.rb index e50ae9c4e4..627442104f 100644 --- a/spec/ruby/optional/capi/kernel_spec.rb +++ b/spec/ruby/optional/capi/kernel_spec.rb @@ -440,6 +440,32 @@ describe "C-API Kernel function" do proc = @s.rb_block_proc() { 1+1 } proc.should be_kind_of(Proc) proc.call.should == 2 + proc.lambda?.should == false + end + + it "passes through an existing lambda and does not convert to a proc" do + b = -> { 1+1 } + proc = @s.rb_block_proc(&b) + proc.should equal(b) + proc.call.should == 2 + proc.lambda?.should == true + end + end + + describe "rb_block_lambda" do + it "converts the implicit block into a Proc but does not convert it to a lambda" do + proc = @s.rb_block_proc { 1+1 } + proc.should be_kind_of(Proc) + proc.call.should == 2 + proc.lambda?.should == false + end + + it "passes through an existing Proc and does not convert to a lambda" do + b = proc { 1+1 } + proc = @s.rb_block_proc(&b) + proc.should equal(b) + proc.call.should == 2 + proc.lambda?.should == false end end |