diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-27 12:30:05 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-27 12:30:05 +0000 |
commit | 9dc121cc577ae7a010bca7efedb79088e3cf7331 (patch) | |
tree | c11a153c7eac91a1e19ed058d5c28f0f7d583622 /spec/ruby/optional/capi | |
parent | fc1f3f14d386b557281ff9a8f19da060befe182e (diff) |
Update to ruby/spec@a454137
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63768 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/optional/capi')
-rw-r--r-- | spec/ruby/optional/capi/enumerator_spec.rb | 27 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/enumerator_spec.c | 15 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/kernel_spec.c | 11 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/rubyspec.h | 3 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/string_spec.c | 12 | ||||
-rw-r--r-- | spec/ruby/optional/capi/kernel_spec.rb | 7 | ||||
-rw-r--r-- | spec/ruby/optional/capi/rake_helper.rb | 1 | ||||
-rw-r--r-- | spec/ruby/optional/capi/string_spec.rb | 19 |
8 files changed, 93 insertions, 2 deletions
diff --git a/spec/ruby/optional/capi/enumerator_spec.rb b/spec/ruby/optional/capi/enumerator_spec.rb index 42510c122d..9ed68c9063 100644 --- a/spec/ruby/optional/capi/enumerator_spec.rb +++ b/spec/ruby/optional/capi/enumerator_spec.rb @@ -36,4 +36,31 @@ describe "C-API Enumerator function" do enumerator.each {} end end + + describe "rb_enumeratorize_with_size" do + + it "enumerates the given object" do + enumerator = @s.rb_enumeratorize_with_size(@enumerable, :each) + enumerated = [] + enumerator.each { |i| enumerated << i } + enumerated.should == @enumerable + end + + it "uses the given method for enumeration" do + enumerator = @s.rb_enumeratorize_with_size(@enumerable, :awesome_each) + @enumerable.should_receive(:awesome_each) + enumerator.each {} + end + + it "passes the given arguments to the enumeration method" do + enumerator = @s.rb_enumeratorize_with_size(@enumerable, :each, :arg1, :arg2) + @enumerable.should_receive(:each).with(:arg1, :arg2) + enumerator.each {} + end + + it "uses the size function to report the size" do + enumerator = @s.rb_enumeratorize_with_size(@enumerable, :each, :arg1, :arg2) + enumerator.size.should == 7 + end + end end diff --git a/spec/ruby/optional/capi/ext/enumerator_spec.c b/spec/ruby/optional/capi/ext/enumerator_spec.c index 6b08feab52..d9e34afd96 100644 --- a/spec/ruby/optional/capi/ext/enumerator_spec.c +++ b/spec/ruby/optional/capi/ext/enumerator_spec.c @@ -13,6 +13,18 @@ VALUE enumerator_spec_rb_enumeratorize(int argc, VALUE *argv, VALUE self) { } #endif +#ifdef HAVE_RB_ENUMERATORIZE_WITH_SIZE +VALUE enumerator_spec_size_fn(VALUE obj, VALUE args, VALUE anEnum) { + return INT2NUM(7); +} + +VALUE enumerator_spec_rb_enumeratorize_with_size(int argc, VALUE *argv, VALUE self) { + VALUE obj, meth, args; + rb_scan_args(argc, argv, "2*", &obj, &meth, &args); + return rb_enumeratorize_with_size(obj, meth, (int)RARRAY_LEN(args), RARRAY_PTR(args), enumerator_spec_size_fn); +} +#endif + void Init_enumerator_spec(void) { VALUE cls; cls = rb_define_class("CApiEnumeratorSpecs", rb_cObject); @@ -20,6 +32,9 @@ void Init_enumerator_spec(void) { #ifdef HAVE_RB_ENUMERATORIZE rb_define_method(cls, "rb_enumeratorize", enumerator_spec_rb_enumeratorize, -1); #endif +#ifdef HAVE_RB_ENUMERATORIZE_WITH_SIZE + rb_define_method(cls, "rb_enumeratorize_with_size", enumerator_spec_rb_enumeratorize_with_size, -1); +#endif } #ifdef __cplusplus diff --git a/spec/ruby/optional/capi/ext/kernel_spec.c b/spec/ruby/optional/capi/ext/kernel_spec.c index 226354e18a..c87ed5e8f2 100644 --- a/spec/ruby/optional/capi/ext/kernel_spec.c +++ b/spec/ruby/optional/capi/ext/kernel_spec.c @@ -65,6 +65,12 @@ VALUE kernel_spec_rb_block_call_no_func(VALUE self, VALUE ary) { #endif +#ifdef HAVE_RB_FRAME_THIS_FUNC +VALUE kernel_spec_rb_frame_this_func(VALUE self) { + return ID2SYM(rb_frame_this_func()); +} +#endif + #ifdef HAVE_RB_ENSURE VALUE kernel_spec_rb_ensure(VALUE self, VALUE main_proc, VALUE arg, VALUE ensure_proc, VALUE arg2) { @@ -350,6 +356,11 @@ void Init_kernel_spec(void) { rb_define_method(cls, "rb_block_proc", kernel_spec_rb_block_proc, 0); #endif +#ifdef HAVE_RB_FRAME_THIS_FUNC + 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); +#endif + #ifdef HAVE_RB_ENSURE rb_define_method(cls, "rb_ensure", kernel_spec_rb_ensure, 4); #endif diff --git a/spec/ruby/optional/capi/ext/rubyspec.h b/spec/ruby/optional/capi/ext/rubyspec.h index 780c2ab20f..4f50450dfb 100644 --- a/spec/ruby/optional/capi/ext/rubyspec.h +++ b/spec/ruby/optional/capi/ext/rubyspec.h @@ -252,6 +252,7 @@ /* Enumerable */ #define HAVE_RB_ENUMERATORIZE 1 +#define HAVE_RB_ENUMERATORIZE_WITH_SIZE 1 /* Exception */ #define HAVE_RB_EXC_NEW 1 @@ -348,6 +349,7 @@ #define HAVE_RB_ENSURE 1 #define HAVE_RB_EVAL_STRING 1 #define HAVE_RB_EXEC_RECURSIVE 1 +#define HAVE_RB_FRAME_THIS_FUNC 1 #define HAVE_RB_F_SPRINTF 1 #define HAVE_RB_NEED_BLOCK 1 #define HAVE_RB_RAISE 1 @@ -563,6 +565,7 @@ #define HAVE_RB_VSPRINTF 1 #define HAVE_RB_STRING 1 #define HAVE_SAFE_STRING_VALUE 1 +#define HAVE_RB_STRING_VALUE_CSTR 1 /* Struct */ #define HAVE_RB_STRUCT_AREF 1 diff --git a/spec/ruby/optional/capi/ext/string_spec.c b/spec/ruby/optional/capi/ext/string_spec.c index 1b9c11a149..a6ce02b25c 100644 --- a/spec/ruby/optional/capi/ext/string_spec.c +++ b/spec/ruby/optional/capi/ext/string_spec.c @@ -497,6 +497,13 @@ static VALUE string_spec_rb_String(VALUE self, VALUE val) { } #endif +#ifdef HAVE_RB_STRING_VALUE_CSTR +static VALUE string_spec_rb_string_value_cstr(VALUE self, VALUE str) { + char *c_str = rb_string_value_cstr(&str); + return c_str ? Qtrue : Qfalse; +} +#endif + void Init_string_spec(void) { VALUE cls; cls = rb_define_class("CApiStringSpecs", rb_cObject); @@ -733,8 +740,11 @@ void Init_string_spec(void) { #ifdef HAVE_RB_STRING rb_define_method(cls, "rb_String", string_spec_rb_String, 1); #endif -} +#ifdef HAVE_RB_STRING_VALUE_CSTR + rb_define_method(cls, "rb_string_value_cstr", string_spec_rb_string_value_cstr, 1); +#endif +} #ifdef __cplusplus } #endif diff --git a/spec/ruby/optional/capi/kernel_spec.rb b/spec/ruby/optional/capi/kernel_spec.rb index 3aa3c388fa..e50ae9c4e4 100644 --- a/spec/ruby/optional/capi/kernel_spec.rb +++ b/spec/ruby/optional/capi/kernel_spec.rb @@ -55,6 +55,13 @@ describe "C-API Kernel function" do end end + describe "rb_frame_this_func" do + it "returns the name of the method called" do + @s.rb_frame_this_func_test.should == :rb_frame_this_func_test + @s.rb_frame_this_func_test_again.should == :rb_frame_this_func_test_again + end + end + describe "rb_raise" do it "raises an exception" do lambda { @s.rb_raise({}) }.should raise_error(TypeError) diff --git a/spec/ruby/optional/capi/rake_helper.rb b/spec/ruby/optional/capi/rake_helper.rb index 2b7a6ccbe3..c13f1189c5 100644 --- a/spec/ruby/optional/capi/rake_helper.rb +++ b/spec/ruby/optional/capi/rake_helper.rb @@ -20,4 +20,3 @@ task default: [output] file output => [input] do sh build_cmd end - diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb index cc6ac2e0cb..2344dd37d7 100644 --- a/spec/ruby/optional/capi/string_spec.rb +++ b/spec/ruby/optional/capi/string_spec.rb @@ -865,4 +865,23 @@ describe "C-API String function" do @s.rb_String({"bar" => "foo"}).should == '{"bar"=>"foo"}' end end + + describe "rb_string_value_cstr" do + it "returns a non-null pointer for a simple string" do + @s.rb_string_value_cstr("Hello").should == true + end + + it "returns a non-null pointer for a UTF-16 string" do + @s.rb_string_value_cstr("Hello".encode('UTF-16BE')).should == true + end + + it "raises an error if a string contains a null" do + lambda { @s.rb_string_value_cstr("Hello\0 with a null.") }.should raise_error(ArgumentError) + end + + it "raises an error if a UTF-16 string contains a null" do + lambda { @s.rb_string_value_cstr("Hello\0 with a null.".encode('UTF-16BE')) }.should raise_error(ArgumentError) + end + + end end |