Skip to content

Commit 8618d3b

Browse files
committed
Add tests for rb_define_method with -2, -1, 2 argc
And tag them as failing
1 parent 479bd4b commit 8618d3b

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

spec/ruby/optional/capi/ext/module_spec.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ static VALUE module_specs_test_method(VALUE self) {
99
return ID2SYM(rb_intern("test_method"));
1010
}
1111

12+
static VALUE module_specs_test_method_2required(VALUE self, VALUE arg1, VALUE arg2) {
13+
return ID2SYM(rb_intern("test_method_2required"));
14+
}
15+
16+
static VALUE module_specs_test_method_c_array(int argc, VALUE *argv, VALUE self) {
17+
return ID2SYM(rb_intern("test_method_c_array"));
18+
}
19+
20+
static VALUE module_specs_test_method_ruby_array(VALUE self, VALUE args) {
21+
return ID2SYM(rb_intern("test_method_ruby_array"));
22+
}
23+
1224
static VALUE module_specs_const_defined(VALUE self, VALUE klass, VALUE id) {
1325
return rb_const_defined(klass, SYM2ID(id)) ? Qtrue : Qfalse;
1426
}
@@ -76,6 +88,21 @@ static VALUE module_specs_rb_define_method(VALUE self, VALUE cls, VALUE str_name
7688
return Qnil;
7789
}
7890

91+
static VALUE module_specs_rb_define_method_2required(VALUE self, VALUE cls, VALUE str_name) {
92+
rb_define_method(cls, RSTRING_PTR(str_name), module_specs_test_method_2required, 2);
93+
return Qnil;
94+
}
95+
96+
static VALUE module_specs_rb_define_method_c_array(VALUE self, VALUE cls, VALUE str_name) {
97+
rb_define_method(cls, RSTRING_PTR(str_name), module_specs_test_method_c_array, -1);
98+
return Qnil;
99+
}
100+
101+
static VALUE module_specs_rb_define_method_ruby_array(VALUE self, VALUE cls, VALUE str_name) {
102+
rb_define_method(cls, RSTRING_PTR(str_name), module_specs_test_method_ruby_array, -2);
103+
return Qnil;
104+
}
105+
79106
static VALUE module_specs_rb_define_module_function(VALUE self, VALUE cls, VALUE str_name) {
80107
rb_define_module_function(cls, RSTRING_PTR(str_name), module_specs_test_method, 0);
81108
return Qnil;
@@ -132,6 +159,10 @@ void Init_module_spec(void) {
132159
module_specs_rb_define_global_function, 1);
133160

134161
rb_define_method(cls, "rb_define_method", module_specs_rb_define_method, 2);
162+
rb_define_method(cls, "rb_define_method_2required", module_specs_rb_define_method_2required, 2);
163+
rb_define_method(cls, "rb_define_method_c_array", module_specs_rb_define_method_c_array, 2);
164+
rb_define_method(cls, "rb_define_method_ruby_array", module_specs_rb_define_method_ruby_array, 2);
165+
135166
rb_define_method(cls, "rb_define_module_function",
136167
module_specs_rb_define_module_function, 2);
137168

spec/ruby/optional/capi/module_spec.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,30 @@ def method_to_be_aliased
246246
cls.new.test_method.should == :test_method
247247
end
248248

249-
it "returns the correct arity of the method in class" do
249+
it "returns the correct arity when argc of the method in class is 0" do
250250
cls = Class.new
251251
@m.rb_define_method(cls, "test_method")
252252
cls.new.method(:test_method).arity.should == 0
253253
end
254254

255+
it "returns the correct arity when argc of the method in class is -1" do
256+
cls = Class.new
257+
@m.rb_define_method_c_array(cls, "test_method_c_array")
258+
cls.new.method(:test_method_c_array).arity.should == -1
259+
end
260+
261+
it "returns the correct arity when argc of the method in class is -2" do
262+
cls = Class.new
263+
@m.rb_define_method_ruby_array(cls, "test_method_ruby_array")
264+
cls.new.method(:test_method_ruby_array).arity.should == -1
265+
end
266+
267+
it "returns the correct arity when argc of the method in class is 2" do
268+
cls = Class.new
269+
@m.rb_define_method_2required(cls, "test_method_2required")
270+
cls.new.method(:test_method_2required).arity.should == 2
271+
end
272+
255273
it "defines a method on a module" do
256274
mod = Module.new
257275
@m.rb_define_method(mod, "test_method")
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
fails:CApiModule rb_define_method returns the correct arity of the method in class
21
fails:CApiModule rb_define_method returns the correct arity of the method in module
32
fails:CApiModule rb_define_module_function returns the correct arity of the module function
43
fails:CApiModule rb_define_module_function returns the correct arity for private instance method
4+
fails:CApiModule rb_define_method returns the correct arity when argc of the method in class is 0
5+
fails:CApiModule rb_define_method returns the correct arity when argc of the method in class is -2
6+
fails:CApiModule rb_define_method returns the correct arity when argc of the method in class is 2

0 commit comments

Comments
 (0)