Skip to content

Commit 46c0a90

Browse files
committed
Add specs for rb_copy_generic_ivar and rb_free_generic_ivar.
1 parent 640d915 commit 46c0a90

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,16 @@ static VALUE object_spec_rb_ivar_defined(VALUE self, VALUE obj, VALUE sym_name)
327327
return rb_ivar_defined(obj, SYM2ID(sym_name));
328328
}
329329

330+
static VALUE object_spec_rb_copy_generic_ivar(VALUE self, VALUE obj) {
331+
rb_copy_generic_ivar(self, obj);
332+
return self;
333+
}
334+
335+
static VALUE object_spec_rb_free_generic_ivar(VALUE self) {
336+
rb_free_generic_ivar(self);
337+
return self;
338+
}
339+
330340
static VALUE object_spec_rb_equal(VALUE self, VALUE a, VALUE b) {
331341
return rb_equal(a, b);
332342
}
@@ -400,6 +410,8 @@ void Init_object_spec(void) {
400410
rb_define_method(cls, "rb_ivar_get", object_spec_rb_ivar_get, 2);
401411
rb_define_method(cls, "rb_ivar_set", object_spec_rb_ivar_set, 3);
402412
rb_define_method(cls, "rb_ivar_defined", object_spec_rb_ivar_defined, 2);
413+
rb_define_method(cls, "rb_copy_generic_ivar", object_spec_rb_copy_generic_ivar, 1);
414+
rb_define_method(cls, "rb_free_generic_ivar", object_spec_rb_free_generic_ivar, 0);
403415
}
404416

405417
#ifdef __cplusplus

spec/ruby/optional/capi/object_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,5 +853,22 @@ def reach
853853
@o.rb_ivar_defined(@test, :bar).should == false
854854
end
855855
end
856+
857+
describe "rb_copy_generic_ivar" do
858+
it "copies the instance variables from one object to another" do
859+
original = Object.new
860+
original.instance_variable_set(:@foo, :bar)
861+
@o.rb_copy_generic_ivar(original)
862+
@o.instance_variable_get(:@foo).should == :bar
863+
end
864+
end
865+
866+
describe "rb_free_generic_ivar" do
867+
it "removes the instance variables from an object" do
868+
@o.instance_variable_set(:@foo, :bar)
869+
@o.rb_free_generic_ivar
870+
@o.instance_variables.should == []
871+
end
872+
end
856873
end
857874
end

0 commit comments

Comments
 (0)