From c0e7344dbafd316ed9af8aed6bcbb8f46def036a Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Fri, 11 Aug 2017 14:30:37 -0300 Subject: [PATCH] test: check util.inspect circular Set and Map refs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ref: https://github.com/nodejs/node/pull/14775 PR-URL: https://github.com/nodejs/node/pull/14790 Reviewed-By: Refael Ackermann Reviewed-By: James M Snell Reviewed-By: Evan Lucas Reviewed-By: Timothy Gu Reviewed-By: Colin Ihrig Reviewed-By: Tobias Nießen Reviewed-By: Yuta Hiroto Reviewed-By: Alexey Orlenko Reviewed-By: Anna Henningsen --- test/parallel/test-util-inspect.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 0e19432a35e117..8cbd6a36227f0f 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -790,6 +790,13 @@ if (typeof Symbol !== 'undefined') { ); } +// Test circular Set +{ + const set = new Set(); + set.add(set); + assert.strictEqual(util.inspect(set), 'Set { [Circular] }'); +} + // test Map { assert.strictEqual(util.inspect(new Map()), 'Map {}'); @@ -801,6 +808,18 @@ if (typeof Symbol !== 'undefined') { 'Map { \'foo\' => null, [size]: 1, bar: 42 }'); } +// Test circular Map +{ + const map = new Map(); + map.set(map, 'map'); + assert.strictEqual(util.inspect(map), "Map { [Circular] => 'map' }"); + map.set(map, map); + assert.strictEqual(util.inspect(map), 'Map { [Circular] => [Circular] }'); + map.delete(map); + map.set('map', map); + assert.strictEqual(util.inspect(map), "Map { 'map' => [Circular] }"); +} + // test Promise { const resolved = Promise.resolve(3);