From f853baf5443d9e3022bde865de759623e9bdd1ca 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 c760f2ce71738e..3f782dec605137 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -799,6 +799,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 {}'); @@ -810,6 +817,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);