diff --git a/benchmark/util/format.js b/benchmark/util/format.js index 44e950a6ca6522..976e0f4e655486 100644 --- a/benchmark/util/format.js +++ b/benchmark/util/format.js @@ -13,6 +13,8 @@ const inputs = { 'no-replace-2': ['foobar', 'yeah', 'mensch', 5], 'only-objects': [{ msg: 'This is an error' }, { msg: 'This is an error' }], 'many-%': ['replace%%%%s%%%%many%s%s%s', 'percent'], + 'object-to-string': ['foo %s bar', { toString() { return 'bla'; } }], + 'object-%s': ['foo %s bar', { a: true, b: false }], }; const bench = common.createBenchmark(main, { diff --git a/benchmark/util/inspect-proxy.js b/benchmark/util/inspect-proxy.js index dde86941ff42a3..02379cdc770f3b 100644 --- a/benchmark/util/inspect-proxy.js +++ b/benchmark/util/inspect-proxy.js @@ -3,13 +3,21 @@ const util = require('util'); const common = require('../common.js'); -const bench = common.createBenchmark(main, { n: [2e4] }); +const bench = common.createBenchmark(main, { + n: [1e5], + showProxy: [0, 1], + isProxy: [0, 1] +}); -function main({ n }) { - const proxyA = new Proxy({}, { get: () => {} }); - const proxyB = new Proxy(() => {}, {}); +function main({ n, showProxy, isProxy }) { + let proxyA = {}; + let proxyB = () => {}; + if (isProxy) { + proxyA = new Proxy(proxyA, { get: () => {} }); + proxyB = new Proxy(proxyB, {}); + } bench.start(); for (let i = 0; i < n; i += 1) - util.inspect({ a: proxyA, b: proxyB }, { showProxy: true }); + util.inspect({ a: proxyA, b: proxyB }, { showProxy }); bench.end(n); } diff --git a/doc/api/assert.md b/doc/api/assert.md index eaf5c5447da6db..277f29880d5b24 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -218,8 +218,9 @@ are also recursively evaluated by the following rules. * [`Symbol`][] properties are not compared. * [`WeakMap`][] and [`WeakSet`][] comparison does not rely on their values. -The following example does not throw an `AssertionError` because the primitives -are considered equal by the [Abstract Equality Comparison][] ( `==` ). +The following example does not throw an [`AssertionError`][] because the +primitives are considered equal by the [Abstract Equality Comparison][] +( `==` ). ```js // WARNING: This does not throw an AssertionError! @@ -264,11 +265,11 @@ assert.deepEqual(obj1, obj4); // AssertionError: { a: { b: 1 } } deepEqual {} ``` -If the values are not equal, an `AssertionError` is thrown with a `message` +If the values are not equal, an [`AssertionError`][] is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. If the `message` parameter is an instance of an [`Error`][] then it will be thrown instead of the -`AssertionError`. +[`AssertionError`][]. ## `assert.deepStrictEqual(actual, expected[, message])` + +* `string` {string} +* `regexp` {RegExp} +* `message` {string|Error} + +> Stability: 1 - Experimental + +Expects the `string` input not to match the regular expression. + +This feature is currently experimental and the name might change or it might be +completely removed again. + +```js +const assert = require('assert').strict; + +assert.doesNotMatch('I will fail', /fail/); +// AssertionError [ERR_ASSERTION]: The input was expected to not match the ... + +assert.doesNotMatch(123, /pass/); +// AssertionError [ERR_ASSERTION]: The "string" argument must be of type string. + +assert.doesNotMatch('I will pass', /different/); +// OK +``` + +If the values do match, or if the `string` argument is of another type than +`string`, an [`AssertionError`][] is thrown with a `message` property set equal +to the value of the `message` parameter. If the `message` parameter is +undefined, a default error message is assigned. If the `message` parameter is an +instance of an [`Error`][] then it will be thrown instead of the +[`AssertionError`][]. + ## `assert.doesNotReject(asyncFn[, error][, message])` @@ -534,8 +571,8 @@ assert.doesNotThrow( ); ``` -If an `AssertionError` is thrown and a value is provided for the `message` -parameter, the value of `message` will be appended to the `AssertionError` +If an [`AssertionError`][] is thrown and a value is provided for the `message` +parameter, the value of `message` will be appended to the [`AssertionError`][] message: @@ -584,7 +621,7 @@ assert.equal({ a: { b: 1 } }, { a: { b: 1 } }); // AssertionError: { a: { b: 1 } } == { a: { b: 1 } } ``` -If the values are not equal, an `AssertionError` is thrown with a `message` +If the values are not equal, an [`AssertionError`][] is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. If the `message` parameter is an instance of an [`Error`][] then it will be thrown instead of the @@ -597,9 +634,9 @@ added: v0.1.21 * `message` {string|Error} **Default:** `'Failed'` -Throws an `AssertionError` with the provided error message or a default error -message. If the `message` parameter is an instance of an [`Error`][] then it -will be thrown instead of the `AssertionError`. +Throws an [`AssertionError`][] with the provided error message or a default +error message. If the `message` parameter is an instance of an [`Error`][] then +it will be thrown instead of the [`AssertionError`][]. ```js const assert = require('assert').strict; @@ -687,7 +724,7 @@ changes: - version: v10.0.0 pr-url: https://github.com/nodejs/node/pull/18247 description: Instead of throwing the original error it is now wrapped into - an `AssertionError` that contains the full stack trace. + an [`AssertionError`][] that contains the full stack trace. - version: v10.0.0 pr-url: https://github.com/nodejs/node/pull/18247 description: Value may now only be `undefined` or `null`. Before all falsy @@ -727,6 +764,42 @@ let err; // at errorFrame ``` +## `assert.match(string, regexp[, message])` + + +* `string` {string} +* `regexp` {RegExp} +* `message` {string|Error} + +> Stability: 1 - Experimental + +Expects the `string` input to match the regular expression. + +This feature is currently experimental and the name might change or it might be +completely removed again. + +```js +const assert = require('assert').strict; + +assert.match('I will fail', /pass/); +// AssertionError [ERR_ASSERTION]: The input did not match the regular ... + +assert.match(123, /pass/); +// AssertionError [ERR_ASSERTION]: The "string" argument must be of type string. + +assert.match('I will pass', /pass/); +// OK +``` + +If the values do not match, or if the `string` argument is of another type than +`string`, an [`AssertionError`][] is thrown with a `message` property set equal +to the value of the `message` parameter. If the `message` parameter is +undefined, a default error message is assigned. If the `message` parameter is an +instance of an [`Error`][] then it will be thrown instead of the +[`AssertionError`][]. + ## `assert.notDeepEqual(actual, expected[, message])`