diff options
author | Roman Reiss <me@silverwind.io> | 2018-09-29 14:41:36 +0200 |
---|---|---|
committer | Roman Reiss <me@silverwind.io> | 2018-10-17 19:56:43 +0200 |
commit | c1b9be53c89a7ac11c01905a4477785a6154512b (patch) | |
tree | 5f6042afc9b149d28def319fd78b776fdeb889f2 /test | |
parent | c979fad9bb33bb0ad4c13a7f44e16719343dc96f (diff) | |
download | android-node-v8-c1b9be53c89a7ac11c01905a4477785a6154512b.tar.gz android-node-v8-c1b9be53c89a7ac11c01905a4477785a6154512b.tar.bz2 android-node-v8-c1b9be53c89a7ac11c01905a4477785a6154512b.zip |
util: treat format arguments equally
Two changes here which bring us closer to the console standard:
- Arguments to `util.format` are no longer formatted differently
depending on their order, with format strings being an exception.
- Format specifier formatting is now only triggered if the string
actually contains a format string.
Under the hood, we now use a single shared function to format the given
arguments which will make the code easier to read and modify.
PR-URL: https://github.com/nodejs/node/pull/23162
Fixes: https://github.com/nodejs/node/issues/23137
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-util-format.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/parallel/test-util-format.js b/test/parallel/test-util-format.js index 0c4ba82fec..2ca8e0857f 100644 --- a/test/parallel/test-util-format.js +++ b/test/parallel/test-util-format.js @@ -273,6 +273,10 @@ assert.strictEqual(util.format('percent: %d%, fraction: %d', 10, 0.1), 'percent: 10%, fraction: 0.1'); assert.strictEqual(util.format('abc%', 1), 'abc% 1'); +// Additional arguments after format specifiers +assert.strictEqual(util.format('%i', 1, 'number'), '1 number'); +assert.strictEqual(util.format('%i', 1, () => {}), '1 [Function]'); + { const o = {}; o.o = o; @@ -315,3 +319,15 @@ function BadCustomError(msg) { util.inherits(BadCustomError, Error); assert.strictEqual(util.format(new BadCustomError('foo')), '[BadCustomError: foo]'); + +// The format of arguments should not depend on type of the first argument +assert.strictEqual(util.format('1', '1'), '1 1'); +assert.strictEqual(util.format(1, '1'), '1 1'); +assert.strictEqual(util.format('1', 1), '1 1'); +assert.strictEqual(util.format(1, 1), '1 1'); +assert.strictEqual(util.format('1', () => {}), '1 [Function]'); +assert.strictEqual(util.format(1, () => {}), '1 [Function]'); +assert.strictEqual(util.format('1', "'"), "1 '"); +assert.strictEqual(util.format(1, "'"), "1 '"); +assert.strictEqual(util.format('1', 'number'), '1 number'); +assert.strictEqual(util.format(1, 'number'), '1 number'); |