summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorJoseph Gentle <me@josephg.com>2017-03-31 14:46:07 +1100
committerAnna Henningsen <anna@addaleax.net>2017-04-03 10:15:53 +0200
commit6481c93aefdc9072edfb2db9cee8fa7c42ec2f43 (patch)
treeb30388f1e98d28fd4195bac1686a9b2a61f2236d /doc
parent3cc3e099be79274a188b2ce32f9cabddfc58ea8d (diff)
downloadandroid-node-v8-6481c93aefdc9072edfb2db9cee8fa7c42ec2f43.tar.gz
android-node-v8-6481c93aefdc9072edfb2db9cee8fa7c42ec2f43.tar.bz2
android-node-v8-6481c93aefdc9072edfb2db9cee8fa7c42ec2f43.zip
assert: add support for Map and Set in deepEqual
assert.deepEqual and assert.deepStrictEqual currently return true for any pair of Maps and Sets regardless of content. This patch adds support in deepEqual and deepStrictEqual to verify the contents of Maps and Sets. Deeo equivalence checking is currently an O(n^2) operation, and worse, it gets slower exponentially if maps and sets were nested. Note that this change breaks compatibility with previous versions of deepEqual and deepStrictEqual if consumers were depending on all maps and sets to be seen as equivalent. The old behaviour was never documented, but nevertheless there are certainly some tests out there which depend on it. Support has stalled because the assert API was frozen, but was recently unfrozen in CTC#63. --- Later squashed in: This change updates the checks for deep equality checking on Map and Set to check all set values / all map keys to see if any of them match the expected result. This change is much slower, but based on the conversation in the pull request its probably the right approach. Fixes: https://github.com/nodejs/node/issues/2309 Refs: https://github.com/substack/tape/issues/342 Refs: https://github.com/nodejs/node/pull/2315 Refs: https://github.com/nodejs/CTC/issues/63 PR-URL: https://github.com/nodejs/node/pull/12142 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/assert.md17
1 files changed, 15 insertions, 2 deletions
diff --git a/doc/api/assert.md b/doc/api/assert.md
index 868b904450..925108b8fc 100644
--- a/doc/api/assert.md
+++ b/doc/api/assert.md
@@ -18,6 +18,9 @@ An alias of [`assert.ok()`][].
<!-- YAML
added: v0.1.21
changes:
+ - version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/12142
+ description: Set and Map content is also compared
- version: v6.4.0, v4.7.1
pr-url: https://github.com/nodejs/node/pull/8002
description: Typed array slices are handled correctly now.
@@ -40,7 +43,7 @@ Only [enumerable "own" properties][] are considered. The
[`assert.deepEqual()`][] implementation does not test the
[`[[Prototype]]`][prototype-spec] of objects, attached symbols, or
non-enumerable properties — for such checks, consider using
-[assert.deepStrictEqual()][] instead. This can lead to some
+[`assert.deepStrictEqual()`][] instead. This can lead to some
potentially surprising results. For example, the following example does not
throw an `AssertionError` because the properties on the [`Error`][] object are
not enumerable:
@@ -50,6 +53,9 @@ not enumerable:
assert.deepEqual(Error('a'), Error('b'));
```
+An exception is made for [`Map`][] and [`Set`][]. Maps and Sets have their
+contained items compared too, as expected.
+
"Deep" equality means that the enumerable "own" properties of child objects
are evaluated also:
@@ -96,6 +102,9 @@ parameter is undefined, a default error message is assigned.
<!-- YAML
added: v1.2.0
changes:
+ - version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/12142
+ description: Set and Map content is also compared
- version: v6.4.0, v4.7.1
pr-url: https://github.com/nodejs/node/pull/8002
description: Typed array slices are handled correctly now.
@@ -113,7 +122,8 @@ changes:
Generally identical to `assert.deepEqual()` with three exceptions:
1. Primitive values are compared using the [Strict Equality Comparison][]
- ( `===` ).
+ ( `===` ). Set values and Map keys are compared using the [SameValueZero][]
+ comparison. (Which means they are free of the [caveats][]).
2. [`[[Prototype]]`][prototype-spec] of objects are compared using
the [Strict Equality Comparison][] too.
3. [Type tags][Object.prototype.toString()] of objects should be the same.
@@ -576,10 +586,13 @@ For more information, see
[`assert.ok()`]: #assert_assert_ok_value_message
[`assert.throws()`]: #assert_assert_throws_block_error_message
[`Error`]: errors.html#errors_class_error
+[caveats]: #assert_caveats
[`RegExp`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
[`TypeError`]: errors.html#errors_class_typeerror
[Abstract Equality Comparison]: https://tc39.github.io/ecma262/#sec-abstract-equality-comparison
[Strict Equality Comparison]: https://tc39.github.io/ecma262/#sec-strict-equality-comparison
+[`Map`]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map
+[`Set`]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Set
[`Object.is()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
[SameValueZero]: https://tc39.github.io/ecma262/#sec-samevaluezero
[prototype-spec]: https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots