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

Add JsonElementEquivalencyStep #2576

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

Conversation

ivarne
Copy link

@ivarne ivarne commented Feb 4, 2024

Taking some inspiration from #2374, I improved the implementation of IEquivalencyStep to actually keep the path when recursing into a json structure and added some tests.

I'm a little puzzled about how to compare json numbers. In JS they are 64 bit floating point, so I ended up using GetDouble() so that 100 and 1e2 is equivalent, but used the string for comparing NaN, Inf and for generating the error message.

As this is part of adding proper support for System.Text.Json, I'm not sure how the release notes should be written.

IMPORTANT

  • If the PR touches the public API, the changes have been approved in a separate issue with the "api-approved" label.
  • The code complies with the Coding Guidelines for C#.
  • The changes are covered by unit tests which follow the Arrange-Act-Assert syntax and the naming conventions such as is used in these tests.
  • If the PR adds a feature or fixes a bug, please update the release notes with a functional description that explains what the change means to consumers of this library, which are published on the website.
  • If the PR changes the public API the changes needs to be included by running AcceptApiChanges.ps1 or AcceptApiChanges.sh.
  • If the PR affects the documentation, please include your changes in this pull request so the documentation will appear on the website.
    • Please also run ./build.sh --target spellcheck or .\build.ps1 --target spellcheck before pushing and check the good outcome

Copy link

github-actions bot commented Feb 4, 2024

Qodana for .NET

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

@dennisdoomen
Copy link
Member

I'm a little puzzled about how to compare json numbers. In JS they are 64 bit floating point, so I ended up using GetDouble() so that 100 and 1e2 is equivalent, but used the string for comparing NaN, Inf and for generating the error message.

According to ChatGPT:

Here's a strategy you can use to parse a JSON number without knowing in advance if it's a double or an integer:

Parse the JSON string to get a JsonDocument or directly work with a JsonElement if you have one.
Use the JsonElement.TryGetInt32, TryGetInt64, TryGetDouble, etc., methods to attempt to get the number in the desired format.
Based on the success of the TryGet methods, you can decide how to handle the value.

@ivarne
Copy link
Author

ivarne commented Feb 12, 2024

The build failures seem to be something about GitVersion. Anything I need to do?

I could first check TryGetInt64 just to make sure that 9,000,000,000,000,000,000 really is different from 9,000,000,000,000,000,999, but equal to 9,000,000,000,000,000,999.21. I think I might favour the current solution.

@ITaluone
Copy link
Contributor

The build failures seem to be something about GitVersion. Anything I need to do?

Rebase to current develop and force push afterwards

@ivarne
Copy link
Author

ivarne commented Feb 13, 2024

I tried to do the int comparison first, and it didn't look too ugly. ivarne@0902202. Any preferences whether it should be included?

@coveralls
Copy link

Pull Request Test Coverage Report for Build 7882714051

Details

  • -15 of 78 (80.77%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.07%) to 97.397%

Changes Missing Coverage Covered Lines Changed/Added Lines %
Src/FluentAssertions/Equivalency/Steps/JsonElementEquivalencyStep.cs 60 75 80.0%
Totals Coverage Status
Change from base Build 7877976607: -0.07%
Covered Lines: 12007
Relevant Lines: 12207

💛 - Coveralls

@dennisdoomen
Copy link
Member

As this is part of adding proper support for System.Text.Json, I'm not sure how the release notes should be written.

You were a bit ahead of the process. Normally we start with an API proposal before people start to implement a PR. So let's wait until the issue is approved.

@ivarne
Copy link
Author

ivarne commented Feb 14, 2024

Before participating in discussions on APIs I had to make sure I understood the possibilities and limitations of the library, and when I had something that seemed useful I decided to share.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants