Skip to content

Commit c0e7344

Browse files
BridgeARMylesBorins
authored andcommitted
test: check util.inspect circular Set and Map refs
Ref: #14775 PR-URL: #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 e97f7f3 commit c0e7344

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
@@ -790,6 +790,13 @@ if (typeof Symbol !== 'undefined') {
790790
);
791791
}
792792

793+
// Test circular Set
794+
{
795+
const set = new Set();
796+
set.add(set);
797+
assert.strictEqual(util.inspect(set), 'Set { [Circular] }');
798+
}
799+
793800
// test Map
794801
{
795802
assert.strictEqual(util.inspect(new Map()), 'Map {}');
@@ -801,6 +808,18 @@ if (typeof Symbol !== 'undefined') {
801808
'Map { \'foo\' => null, [size]: 1, bar: 42 }');
802809
}
803810

811+
// Test circular Map
812+
{
813+
const map = new Map();
814+
map.set(map, 'map');
815+
assert.strictEqual(util.inspect(map), "Map { [Circular] => 'map' }");
816+
map.set(map, map);
817+
assert.strictEqual(util.inspect(map), 'Map { [Circular] => [Circular] }');
818+
map.delete(map);
819+
map.set('map', map);
820+
assert.strictEqual(util.inspect(map), "Map { 'map' => [Circular] }");
821+
}
822+
804823
// test Promise
805824
{
806825
const resolved = Promise.resolve(3);

0 commit comments

Comments
 (0)