Skip to content

Commit 98c0a47

Browse files
BridgeARaddaleax
authored andcommitted
test: check util.inspect circular Set and Map refs
Ref: nodejs#14775 PR-URL: nodejs#14790 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Alexey Orlenko <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 0d019fa commit 98c0a47

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/parallel/test-util-inspect.js

+19
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,13 @@ if (typeof Symbol !== 'undefined') {
799799
);
800800
}
801801

802+
// Test circular Set
803+
{
804+
const set = new Set();
805+
set.add(set);
806+
assert.strictEqual(util.inspect(set), 'Set { [Circular] }');
807+
}
808+
802809
// test Map
803810
{
804811
assert.strictEqual(util.inspect(new Map()), 'Map {}');
@@ -810,6 +817,18 @@ if (typeof Symbol !== 'undefined') {
810817
'Map { \'foo\' => null, [size]: 1, bar: 42 }');
811818
}
812819

820+
// Test circular Map
821+
{
822+
const map = new Map();
823+
map.set(map, 'map');
824+
assert.strictEqual(util.inspect(map), "Map { [Circular] => 'map' }");
825+
map.set(map, map);
826+
assert.strictEqual(util.inspect(map), 'Map { [Circular] => [Circular] }');
827+
map.delete(map);
828+
map.set('map', map);
829+
assert.strictEqual(util.inspect(map), "Map { 'map' => [Circular] }");
830+
}
831+
813832
// test Promise
814833
{
815834
const resolved = Promise.resolve(3);

0 commit comments

Comments
 (0)