1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

gc.c: fix WeakMap#inspect

* gc.c (wmap_inspect_i): fix key/value order.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-12-10 05:02:17 +00:00
parent 332decb490
commit 9bd802f556
2 changed files with 10 additions and 2 deletions

4
gc.c
View file

@ -6346,8 +6346,8 @@ wmap_inspect(VALUE self)
TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w);
str = rb_sprintf("-<%"PRIsVALUE":%p", c, (void *)self); str = rb_sprintf("-<%"PRIsVALUE":%p", c, (void *)self);
if (w->obj2wmap) { if (w->wmap2obj) {
st_foreach(w->obj2wmap, wmap_inspect_i, str); st_foreach(w->wmap2obj, wmap_inspect_i, str);
} }
RSTRING_PTR(str)[0] = '#'; RSTRING_PTR(str)[0] = '#';
rb_str_cat2(str, ">"); rb_str_cat2(str, ">");

View file

@ -28,6 +28,14 @@ class TestWeakMap < Test::Unit::TestCase
alias test_member? test_include? alias test_member? test_include?
alias test_key? test_include? alias test_key? test_include?
def test_inspect
x = Object.new
k = BasicObject.new
@wm[k] = x
assert_match(/\A\#<#{@wm.class.name}:[^:]+:\s\#<BasicObject:[^:]*>\s=>\s\#<Object:[^:]*>>\z/,
@wm.inspect)
end
def test_each def test_each
m = __callee__[/test_(.*)/, 1] m = __callee__[/test_(.*)/, 1]
x1 = Object.new x1 = Object.new