-
-
Notifications
You must be signed in to change notification settings - Fork 306
Description
As noted in inspect-js/node-deep-equal#28, Node’s deepEqual algorithm does not support comparing ES2015/ES6 Maps and Sets, and, as noted in nodejs/node#2309 and nodejs/node#2315, there is no intent by Node’s staff to support them. According to @domenic and @Trott, the Node standard assert module is intended for only testing Node itself, and assertions in user land should be addressed by user-land assertion libraries. For this same reason (mjackson/expect#47), along with circular references (mjackson/expect#50), the expect library has switched from node-deep-equal to is-equal (mjackson/expect@32e2169).
Given all this, it would make sense for Tape to add another recursive comparison function – alternative to t.deepEqual, t.deepLooseEqual, etc. – that would support Maps and Sets. This function too might use is-equal, which also supports comparing Dates and RegExps, and which might be called something like t.jsEquiv, since it would test whether two objects represent the same JavaScript-standard-library data.
Alternatively, it may be simpler and more generally useful to support Maps and Sets by simply comparing their iterators’ items. Shallow and deep versions might be called t.iterEquiv and t.deepIterEquiv (alternative names include t.itemsEqual, t.iterEqual, and so on). For instance, t.deepIterEquiv(new Map([ [ 3, 2 ], [ 5, 4 ] ]), [ [ 3, 2 ], [ 5, 4 ] ] would test as true, because the map and the array’s iterators both yield the same entries in the same order, and their entries’ iterators also yield the same integers in the same order.
In this case, t.iterEquiv and t.deepIterEquiv might also allow additional optional arguments that let the user customize what predicates are used to compare items. t.iterEquiv would take one optional predicate, for comparing items shallowly. t.deepIterEquiv would take two optional predicates: one for comparing leaf-node items and the other for comparing branch-node items without regard to the branches’ children.
These two options for comparing Maps and Sets – t.jsEquiv versus t.iterEquiv / t.deepIterEquiv – are not mutually exclusive, of course. Both are useful, and neither should also be difficult to implement; I might be open to doing the work myself. The question here is more about whether @substack thinks either or both of them would fit with his vision for Tape.