-
Notifications
You must be signed in to change notification settings - Fork 30k
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
assert: make partialDeepStrictEqual throw when comparing [0] with [-0] #56237
base: main
Are you sure you want to change the base?
assert: make partialDeepStrictEqual throw when comparing [0] with [-0] #56237
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #56237 +/- ##
========================================
Coverage 88.54% 88.54%
========================================
Files 657 657
Lines 189899 190426 +527
Branches 36465 36565 +100
========================================
+ Hits 168140 168609 +469
- Misses 14966 15000 +34
- Partials 6793 6817 +24
|
0ce4a4a
to
7c30734
Compare
lib/assert.js
Outdated
if (ObjectIs(item, -0)) return '-0(number)'; | ||
if (item === '-0') return '-0(string)'; | ||
if (ObjectIs(item, 0)) return '0(number)'; | ||
if (item === '0') return '0(string)'; |
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.
can you please add tests that compare between [0]
and ['-0(number)']
, and every other permutation of the zeroes and these return values?
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.
I feel like using Symbol
s would be more appropriate than strings.
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.
@ljharb yeah, while I was pushing I thought about the problems my solution had. I approached the problem in a slightly different way and now we should not have those edge cases anymore.
Thanks for the review!
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.
I think using a memoized symbol for -0 would end up being a lot simpler than this implementation
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.
@ljharb would you mind showing me what you mean? The current pushed implementation does not have any hardcoded exception for the 0 case
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.
Ah I see what you mean now! And is this what you would like to see implemented or is it just something that could have been improved the previous implementation, that is no more?
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.
My suspicion is that it would likely be the simplest and fastest implementation, and that it's more similar to your previous implementation than the current one. Your call though!
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.
@ljharb MUCH cleaner implementation indeed, I never think at Symbols, thanks for the hint 😄
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.
(to give proper credit, @LiviaMedeiros suggested it initially upthread :-) )
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.
oh boi, I completely missed the comment! sorry, and thanks both then :)
65e1141
to
4fa9ec7
Compare
4fa9ec7
to
a0d1929
Compare
@ljharb yep, all valid comments. I spent so much time on this finding the best solution and it took everything out of me, making me write dumb stuff... thanks again 😄 |
8f997a5
to
71a5892
Compare
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.
LGTM with the following removal.
test/parallel/test-assert-objects.js
Outdated
{ | ||
description: 'throws when comparing [-0] with [0]', | ||
actual: [0], | ||
expected: [-0], | ||
}, |
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.
{ | |
description: 'throws when comparing [-0] with [0]', | |
actual: [0], | |
expected: [-0], | |
}, |
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.
@LiviaMedeiros how come? Why do you think I should remove this?
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.
It’s a duplicate, look two test cases up
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.
Ops, I was checking on the phone, that was tough to spot 😅 the test doesn't have to be removed, the description is right but the test case is wrong. I will fix when home 😊
71a5892
to
cd8e5cd
Compare
Fixes: #56230
assert.partialDeepStrictEqual
now throws when comparing[0]
with[-0]