test/-ext-/hash/test_delete.rb: assert deleted values

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-10-23 14:18:32 +00:00
parent ca7835bec6
commit d4c22161f3
2 changed files with 4 additions and 4 deletions

View File

@ -4,11 +4,11 @@ static VALUE
hash_delete(VALUE hash, VALUE key) hash_delete(VALUE hash, VALUE key)
{ {
VALUE ret = rb_hash_delete(hash, key); VALUE ret = rb_hash_delete(hash, key);
return ret == Qundef ? Qfalse : Qtrue; return ret == Qundef ? Qnil : rb_ary_new_from_values(1, &ret);
} }
void void
Init_delete(VALUE klass) Init_delete(VALUE klass)
{ {
rb_define_method(klass, "delete", hash_delete, 1); rb_define_method(klass, "delete!", hash_delete, 1);
} }

View File

@ -8,10 +8,10 @@ class TestHash < Test::Unit::TestCase
hash[1] = 2 hash[1] = 2
called = false called = false
assert_equal 1, hash.size assert_equal 1, hash.size
assert_equal true, hash.delete(1) {called = true} assert_equal [2], hash.delete!(1) {called = true}
assert_equal false, called, "block called" assert_equal false, called, "block called"
assert_equal 0, hash.size assert_equal 0, hash.size
assert_equal false, hash.delete(1) {called = true} assert_equal nil, hash.delete!(1) {called = true}
assert_equal false, called, "block called" assert_equal false, called, "block called"
assert_equal 0, hash.size assert_equal 0, hash.size
end end