diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-06-02 16:07:08 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-06-11 13:50:55 +0200 |
commit | 26de13a15c3d20b484ac830c8f4aa38d69651b2a (patch) | |
tree | a87fb965f0907fd70623de8d966e1e86cef909cc /test | |
parent | 62ac84b5f81a747e8f7693138949d841c1b98851 (diff) | |
download | android-node-v8-26de13a15c3d20b484ac830c8f4aa38d69651b2a.tar.gz android-node-v8-26de13a15c3d20b484ac830c8f4aa38d69651b2a.tar.bz2 android-node-v8-26de13a15c3d20b484ac830c8f4aa38d69651b2a.zip |
util: refactor inspecting long lines
Using the `util.inspect` `compact` mode set to something else than
`true` resulted in breaking long lines in case the line would exceed
the `breakLength` option and if it contained whitespace and or new
lines.
It turned out that this behavior was less useful than originally
expected and it is now changed to only break on line breaks if the
`breakLength` option is exceeded for the inspected string. This should
be align better with the user expectation than the former behavior.
PR-URL: https://github.com/nodejs/node/pull/28055
Fixes: https://github.com/nodejs/node/issues/27690
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-util-inspect.js | 62 |
1 files changed, 16 insertions, 46 deletions
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 6e1aef32f5..03cbebe164 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -93,7 +93,7 @@ assert.strictEqual(util.inspect(new Date('')), (new Date('')).toString()); assert.strictEqual(util.inspect('\n\u0001'), "'\\n\\u0001'"); assert.strictEqual( util.inspect(`${Array(75).fill(1)}'\n\u001d\n\u0003`), - `"${Array(75).fill(1)}'\\n" +\n '\\u001d\\n\\u0003'` + `"${Array(75).fill(1)}'\\n" +\n '\\u001d\\n' +\n '\\u0003'` ); assert.strictEqual(util.inspect([]), '[]'); assert.strictEqual(util.inspect(Object.create([])), 'Array {}'); @@ -1509,10 +1509,9 @@ util.inspect(process); ' 2,', ' [', ' [', - " 'Lorem ipsum dolor\\nsit amet,\\tconsectetur ' +", - " 'adipiscing elit, sed do eiusmod tempor ' +", - " 'incididunt ut labore et dolore magna ' +", - " 'aliqua.',", + " 'Lorem ipsum dolor\\n' +", + " 'sit amet,\\tconsectetur adipiscing elit, sed do eiusmod " + + "tempor incididunt ut labore et dolore magna aliqua.',", " 'test',", " 'foo'", ' ]', @@ -1529,12 +1528,9 @@ util.inspect(process); out = util.inspect(o.a[2][0][0], { compact: false, breakLength: 30 }); expect = [ - "'Lorem ipsum dolor\\nsit ' +", - " 'amet,\\tconsectetur ' +", - " 'adipiscing elit, sed do ' +", - " 'eiusmod tempor incididunt ' +", - " 'ut labore et dolore magna ' +", - " 'aliqua.'" + "'Lorem ipsum dolor\\n' +", + " 'sit amet,\\tconsectetur adipiscing elit, sed do eiusmod tempor " + + "incididunt ut labore et dolore magna aliqua.'" ].join('\n'); assert.strictEqual(out, expect); @@ -1548,30 +1544,7 @@ util.inspect(process); '12 45 78 01 34 67 90 23 56 89 123456789012345678901234567890', { compact: false, breakLength: 3 }); expect = [ - "'12 45 78 01 34 ' +", - " '67 90 23 56 89 ' +", - " '123456789012345678901234567890'" - ].join('\n'); - assert.strictEqual(out, expect); - - out = util.inspect( - '12 45 78 01 34 67 90 23 56 89 1234567890123 0', - { compact: false, breakLength: 3 }); - expect = [ - "'12 45 78 01 34 ' +", - " '67 90 23 56 89 ' +", - " '1234567890123 0'" - ].join('\n'); - assert.strictEqual(out, expect); - - out = util.inspect( - '12 45 78 01 34 67 90 23 56 89 12345678901234567 0', - { compact: false, breakLength: 3 }); - expect = [ - "'12 45 78 01 34 ' +", - " '67 90 23 56 89 ' +", - " '12345678901234567 ' +", - " '0'" + "'12 45 78 01 34 67 90 23 56 89 123456789012345678901234567890'" ].join('\n'); assert.strictEqual(out, expect); @@ -1610,7 +1583,7 @@ util.inspect(process); o[util.inspect.custom] = () => ({ a: '12 45 78 01 34 67 90 23' }); out = util.inspect(o, { compact: false, breakLength: 3 }); - expect = "{\n a: '12 45 78 01 34 ' +\n '67 90 23'\n}"; + expect = "{\n a: '12 45 78 01 34 67 90 23'\n}"; assert.strictEqual(out, expect); } @@ -2214,16 +2187,13 @@ assert.strictEqual( ' b: {', ' x: 5,', ' c: {', - " x: '10000000000000000 00000000000000000 ' +", - " '10000000000000000 00000000000000000 ' +", - " '10000000000000000 00000000000000000 ' +", - " '10000000000000000 00000000000000000 ' +", - " '10000000000000000 00000000000000000 ' +", - " '10000000000000000 00000000000000000 ' +", - " '10000000000000000 00000000000000000 ' +", - " '10000000000000000 00000000000000000 ' +", - " '10000000000000000 00000000000000000 ' +", - " '10000000000000000 00000000000000000 ',", + " x: '10000000000000000 00000000000000000 10000000000000000 " + + '00000000000000000 10000000000000000 00000000000000000 ' + + '10000000000000000 00000000000000000 10000000000000000 ' + + '00000000000000000 10000000000000000 00000000000000000 ' + + '10000000000000000 00000000000000000 10000000000000000 ' + + '00000000000000000 10000000000000000 00000000000000000 ' + + "10000000000000000 00000000000000000 ',", ' d: 2,', ' e: 3', ' }', |