Show embed status of array when len is 0 in objspace dump
This commit is contained in:
parent
7790905536
commit
fb724a887a
Notes:
git
2022-03-02 00:56:13 +09:00
@ -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;
|
||||
|
||||
|
@ -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"')
|
||||
|
Loading…
x
Reference in New Issue
Block a user