diff options
author | Peter Zhu <peter@peterzhu.ca> | 2022-02-28 09:39:16 -0500 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2022-03-01 10:55:53 -0500 |
commit | fb724a887aa239de2fb1920f769ea097bee37b01 (patch) | |
tree | 47985a2dbf1515f09874d4d31f6d87f894618195 | |
parent | 779090553680905b036abff550287d014b588f83 (diff) |
Show embed status of array when len is 0 in objspace dump
-rw-r--r-- | ext/objspace/objspace_dump.c | 2 | ||||
-rw-r--r-- | test/objspace/test_objspace.rb | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c index e958a831c5..b570acbd95 100644 --- a/ext/objspace/objspace_dump.c +++ b/ext/objspace/objspace_dump.c @@ -419,7 +419,7 @@ dump_object(VALUE obj, struct dump_config *dc) dump_append_ld(dc, RARRAY_LEN(obj)); if (RARRAY_LEN(obj) > 0 && FL_TEST(obj, ELTS_SHARED)) dump_append(dc, ", \"shared\":true"); - if (RARRAY_LEN(obj) > 0 && FL_TEST(obj, RARRAY_EMBED_FLAG)) + if (FL_TEST(obj, RARRAY_EMBED_FLAG)) dump_append(dc, ", \"embedded\":true"); break; diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index 781fb5b3c2..c9ed62f6f6 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -307,6 +307,28 @@ class TestObjSpace < Test::Unit::TestCase JSON.parse(info) if defined?(JSON) end + def test_dump_array + # Empty array + info = ObjectSpace.dump([]) + assert_include(info, '"length":0, "embedded":true') + assert_not_include(info, '"shared":true') + + # Non-embed array + arr = (1..10).to_a + info = ObjectSpace.dump(arr) + assert_include(info, '"length":10') + assert_not_include(info, '"embedded":true') + assert_not_include(info, '"shared":true') + + # Shared array + arr1 = (1..10).to_a + arr = [] + arr.replace(arr1) + info = ObjectSpace.dump(arr) + assert_include(info, '"length":10, "shared":true') + assert_not_include(info, '"embedded":true') + end + def test_dump_control_char assert_include(ObjectSpace.dump("\x0f"), '"value":"\u000f"') assert_include(ObjectSpace.dump("\C-?"), '"value":"\u007f"') |