Skip to content

Commit

Permalink
Add specs for rb_struct_s_members
Browse files Browse the repository at this point in the history
  • Loading branch information
kaorimatz authored and eregon committed Apr 1, 2017
1 parent ecc868d commit af5412d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions optional/capi/ext/rubyspec.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@
#define HAVE_RB_STRUCT_DEFINE 1
#define HAVE_RB_STRUCT_NEW 1
#define HAVE_RB_STRUCT_GETMEMBER 1
#define HAVE_RB_STRUCT_S_MEMBERS 1
#ifdef RUBY_VERSION_IS_2_4
#define HAVE_RB_STRUCT_SIZE 1
#endif
Expand Down
11 changes: 11 additions & 0 deletions optional/capi/ext/struct_spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ static VALUE struct_spec_rb_struct_getmember(VALUE self, VALUE st, VALUE key) {
}
#endif

#ifdef HAVE_RB_STRUCT_S_MEMBERS
static VALUE struct_spec_rb_struct_s_members(VALUE self, VALUE klass)
{
return rb_ary_dup(rb_struct_s_members(klass));
}
#endif

#ifdef HAVE_RB_STRUCT_ASET
static VALUE struct_spec_rb_struct_aset(VALUE self, VALUE st, VALUE key, VALUE value) {
return rb_struct_aset(st, key, value);
Expand Down Expand Up @@ -69,6 +76,10 @@ void Init_struct_spec(void) {
rb_define_method(cls, "rb_struct_getmember", struct_spec_rb_struct_getmember, 2);
#endif

#ifdef HAVE_RB_STRUCT_S_MEMBERS
rb_define_method(cls, "rb_struct_s_members", struct_spec_rb_struct_s_members, 1);
#endif

#ifdef HAVE_RB_STRUCT_ASET
rb_define_method(cls, "rb_struct_aset", struct_spec_rb_struct_aset, 3);
#endif
Expand Down
6 changes: 6 additions & 0 deletions optional/capi/struct_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@
end
end

describe "rb_struct_s_members" do
it "returns the struct members as an array of symbols" do
@s.rb_struct_s_members(@klass).should == [:a, :b, :c]
end
end

describe "rb_struct_aset" do
it "sets the value of a struct member with a symbol key" do
@s.rb_struct_aset(@struct, :a, 1)
Expand Down

0 comments on commit af5412d

Please sign in to comment.