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

UnitParser.TryParse doesn't try with FallbackCulture #1443

Closed
lipchev opened this issue Dec 6, 2024 · 4 comments
Closed

UnitParser.TryParse doesn't try with FallbackCulture #1443

lipchev opened this issue Dec 6, 2024 · 4 comments

Comments

@lipchev
Copy link
Collaborator

lipchev commented Dec 6, 2024

I just noticed that the behavior of UnitParser.Parse(..) is different from that of UnitParser.TryParse(..) with regards to the FallbackCulture.

Was that intentional? Should I do something about it?

@lipchev lipchev added the bug label Dec 6, 2024
@angularsen
Copy link
Owner

No that sounds like a mistake, please do 🙇

@lipchev
Copy link
Collaborator Author

lipchev commented Dec 10, 2024

By the way, I see that the FallbackCulture behavior is also not applied on the QuantityParser.. I am certainly not going to be parsing anything with ru-RU in the foreseeable future, but unless I'm missing something, anyone trying to parse a quantity that has some localizations in the json with any of the standard abbreviations, would get nothing (unless they explicitly pass an invariant culture, which would probably not work for the value format)..

@angularsen
Copy link
Owner

I thought we had some tests on this, but let's add some as part of the fix.
I'm suprised this hasn't had more bug reports, but maybe this is just not widely used.

lipchev added a commit to lipchev/UnitsNet that referenced this issue Dec 19, 2024
…ture

- UnitParser: extracting a FindMatchingUnits function (used by both Parse and TryParse for a given abbreviation and culture)
- UnitAbbreviationsCache: just a cosmetic change (flipping the order of the items in the tuple)
- UnitParserTests: added the missing tests for the FallbackCulture
angularsen added a commit that referenced this issue Dec 26, 2024
Fixes #1443

- [x] `UnitParser`: extracting a `FindMatchingUnits` function (used by
both `Parse` and `TryParse` for a given abbreviation and culture)
- [x] `UnitAbbreviationsCache`: just a cosmetic change (flipping the
order of the items in the tuple)
- [x] `UnitParserTests`: added the missing tests for the
`FallbackCulture`
- [x] `UnitTestBaseClassGenerator`: improving the code-coverage of the
`ParseUnit` and `TryParseUnit` tests (parsing without specifying a
culture, which should always work with abbreviations for the
`FallbackCulture`)
- Add some extra tests regarding CurrentCulture and explicit culture for parsing

---------

Co-authored-by: Andreas Gullberg Larsen <[email protected]>
@angularsen
Copy link
Owner

Closing this as fixed in v6, reopen if you intended to also fix for master (v5).

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

No branches or pull requests

2 participants