Skip to content

Commit a44e30c

Browse files
committed
Add spec for rb_hash_lookup2 default value of Qundef.
1 parent d562b7f commit a44e30c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ VALUE hash_spec_rb_hash_lookup2(VALUE self, VALUE hash, VALUE key, VALUE def) {
9696
return rb_hash_lookup2(hash, key, def);
9797
}
9898

99+
VALUE hash_spec_rb_hash_lookup2_default_undef(VALUE self, VALUE hash, VALUE key) {
100+
VALUE ret = rb_hash_lookup2(hash, key, Qundef);
101+
return ret == Qundef ? Qtrue : Qfalse;
102+
}
103+
99104
VALUE hash_spec_rb_hash_new(VALUE self) {
100105
return rb_hash_new();
101106
}
@@ -127,6 +132,7 @@ void Init_hash_spec(void) {
127132
rb_define_method(cls, "rb_hash_lookup_nil", hash_spec_rb_hash_lookup_nil, 2);
128133
rb_define_method(cls, "rb_hash_lookup", hash_spec_rb_hash_lookup, 2);
129134
rb_define_method(cls, "rb_hash_lookup2", hash_spec_rb_hash_lookup2, 3);
135+
rb_define_method(cls, "rb_hash_lookup2_default_undef", hash_spec_rb_hash_lookup2_default_undef, 2);
130136
rb_define_method(cls, "rb_hash_new", hash_spec_rb_hash_new, 0);
131137
rb_define_method(cls, "rb_hash_size", hash_spec_rb_hash_size, 1);
132138
rb_define_method(cls, "rb_hash_set_ifnone", hash_spec_rb_hash_set_ifnone, 2);

spec/ruby/optional/capi/hash_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@
211211

212212
@s.rb_hash_lookup2(hash, :chunky, 10).should == 10
213213
end
214+
215+
it "returns undefined if that is the default value specified" do
216+
hsh = Hash.new(0)
217+
@s.rb_hash_lookup2_default_undef(hsh, :chunky).should be_true
218+
end
214219
end
215220
end
216221

0 commit comments

Comments
 (0)