Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

puskin94
Copy link
Contributor

Fixes: #56230

assert.partialDeepStrictEqual now throws when comparing [0] with [-0]

@nodejs-github-bot nodejs-github-bot added assert Issues and PRs related to the assert subsystem. needs-ci PRs that need a full CI run. labels Dec 12, 2024
Copy link

codecov bot commented Dec 12, 2024

Codecov Report

Attention: Patch coverage is 94.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 88.54%. Comparing base (9ec8b9e) to head (cd8e5cd).
Report is 72 commits behind head on main.

Files with missing lines Patch % Lines
lib/assert.js 94.00% 3 Missing ⚠️
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     
Files with missing lines Coverage Δ
lib/assert.js 99.04% <94.00%> (-0.34%) ⬇️

... and 57 files with indirect coverage changes

@puskin94 puskin94 marked this pull request as draft December 12, 2024 15:03
@puskin94 puskin94 force-pushed the partial-deep-strict-equal-minus-plus-zero branch from 0ce4a4a to 7c30734 Compare December 12, 2024 15:54
@puskin94 puskin94 marked this pull request as ready for review December 12, 2024 15:55
lib/assert.js Outdated
Comment on lines 507 to 510
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)';
Copy link
Member

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like using Symbols would be more appropriate than strings.

Copy link
Contributor Author

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!

Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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?

Copy link
Member

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!

Copy link
Contributor Author

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 😄

Copy link
Member

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 :-) )

Copy link
Contributor Author

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 :)

@puskin94 puskin94 force-pushed the partial-deep-strict-equal-minus-plus-zero branch 2 times, most recently from 65e1141 to 4fa9ec7 Compare December 12, 2024 19:06
lib/assert.js Outdated Show resolved Hide resolved
lib/assert.js Outdated Show resolved Hide resolved
lib/assert.js Outdated Show resolved Hide resolved
lib/assert.js Outdated Show resolved Hide resolved
lib/assert.js Outdated Show resolved Hide resolved
@puskin94 puskin94 force-pushed the partial-deep-strict-equal-minus-plus-zero branch from 4fa9ec7 to a0d1929 Compare December 12, 2024 19:40
@puskin94
Copy link
Contributor Author

puskin94 commented Dec 12, 2024

@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 😄

@puskin94 puskin94 force-pushed the partial-deep-strict-equal-minus-plus-zero branch 2 times, most recently from 8f997a5 to 71a5892 Compare December 15, 2024 20:04
@jakecastelli jakecastelli added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Dec 19, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 19, 2024
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@LiviaMedeiros LiviaMedeiros removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 21, 2024
Copy link
Contributor

@LiviaMedeiros LiviaMedeiros left a 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.

Comment on lines 110 to 114
{
description: 'throws when comparing [-0] with [0]',
actual: [0],
expected: [-0],
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{
description: 'throws when comparing [-0] with [0]',
actual: [0],
expected: [-0],
},

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Contributor Author

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 😊

@puskin94 puskin94 force-pushed the partial-deep-strict-equal-minus-plus-zero branch from 71a5892 to cd8e5cd Compare December 21, 2024 20:52
@LiviaMedeiros LiviaMedeiros added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Dec 22, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 22, 2024
@nodejs-github-bot
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assert Issues and PRs related to the assert subsystem. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

assert.partialDeepStrictEqual not working when comparing [0] and [-0]
6 participants