-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
harness/deepEqual.js: Improve formatting and align with base assert #4253
Conversation
3fb8c9f
to
ea656f8
Compare
I had a look at the code, but before I figure out how the template tag works, a before/after comparison of the output would be helpful, as well as a bit more explanation of the motivation 😄 By the way, is #3476 on your radar? I've been considering the use of deepEqual in new tests discouraged. |
Ah, I wonder if I should try to add some inline documentation. But basically,
Sure; added above.
It started as fixing issues like the extra closing brace in formatted map output and handling
Hmm, it really does feel like the right tool for comparing logs as above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems okay to me
harness/deepEqual.js
Outdated
return lazyStringFactory`function${value.name ? ` ${String(value.name)}` : ''}${usage}`(String, renderUsage); | ||
} else if (typeof value !== 'object') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a policy on if
/else if
after return? I personally prefer if
, but will accept house rules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed back to that style; else if
ended up too dense to be readable.
harness/deepEqual.js
Outdated
@@ -15,59 +15,76 @@ assert.deepEqual = function(actual, expected, message) { | |||
}; | |||
|
|||
assert.deepEqual.format = (function () { | |||
function lazyStringFactory(strings, ...subs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do add some docs here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, with corresponding refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in general, let's please avoid newer syntax unless it's required for the test (including spread, arrows, let/const, etc)
using tagged template literals also seems like it will permanently prevent the tests from running on an engine that doesn't have template literal support. is there a way to achieve the same goal without using backticks?
@@ -14,56 +14,117 @@ assert.deepEqual = function(actual, expected, message) { | |||
); | |||
}; | |||
|
|||
let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; | |||
let join = arr => arr.join(', '); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let join = arr => arr.join(', '); | |
function join(arr) { return arr.join(', '); } |
@@ -14,56 +14,117 @@ assert.deepEqual = function(actual, expected, message) { | |||
); | |||
}; | |||
|
|||
let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; | |
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
I very much agree with this, but deepEqual.js already uses templates, arrows, and lexical bindings: Lines 59 to 63 in 5ae7de9
A somewhat ergonomic fix printf-style fix is possible, but really seems more appropriate for a followup: var tag = Symbol.toStringTag && Symbol.toStringTag in value
? value[Symbol.toStringTag]
: Object.getPrototypeOf(value) === null ? '[Object: null prototype]' : 'Object';
let keys = Reflect.ownKeys(value).filter(function(key) {
return getOwnPropertyDescriptor(value, key).enumerable;
});
let contents = keys.map(function(key) {
// return lazyString`${escapeKey(key)}: ${format(value[key], seen)}`;
return callTag(lazyString, '%v: %v', escapeKey(key), format(value[key], seen));
});
// return lazyResult`${tag ? `${tag} ` : ''}{${contents}}`(String, join);
return callTag(lazyResult, '%v{%v}', tag ? String(tag) + ' ' : '', contents)(String, join); |
Indeed if the syntax is already in the file, my comment doesn't apply. |
… with lazy multi-use indication
8cbd681
to
5c93647
Compare
Consolidates handling of identity-bearing values via a lazy multi-use indication.
comparison
before
Note the frequently missing "as #N" and the total lack of indication for referentially-identical symbols/regular expressions/dates/etc., not to mention the inability to differentiate signed zeros from each other or numbers from bigints.
after