Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Make
JSONEqreject different numbers that round to the samefloat64value.Changes
When the existing comparison would pass, compare the original JSON numbers before accepting the result. Normalize decimal and exponent spellings so values such as
1,1.0, and1e0still compare equal. This also distinguishes very small nonzero numbers from zero.The existing input validation and diagnostics remain in place. Identical input strings keep their fast path; other apparently equal inputs need an additional decode to avoid losing numeric information.
Tests cover large integers, decimal rounding, underflow, nested values, equivalent number spellings, and invalid inputs. On Windows, the full suite passes with Go 1.17.13. The assert, require, and mock tests, plus
go vet ./...andgo build ./..., pass with Go 1.17.13 and 1.27.1. With Go 1.27.1, the full suite still hits the existingTestFailfastSuiteFailFastOnfailure because its subprocess needs the unavailable race/CGO support; the same failure occurs at the base revision.Motivation
JSONEqcurrently accepts{"id":9007199254740992}and{"id":9007199254740993}as equal. Both numbers become the samefloat64during decoding, so a test can pass even when an ID has changed. The comparison now keeps enough information to catch that difference without treating equivalent numeric spellings as different values.Related issues
Related to the numeric-value comparison discussed in #360; equivalent spellings remain equal.