-
Notifications
You must be signed in to change notification settings - Fork 394
Parsing fails when mapped abbreviations contain numbers #264
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
Comments
So I am a bit confused now... I wrote a test for the above conditions and it is passing in xunit. However, it fails with symbols (like ^). Will get a sample repo up tomorrow to compare to test results. |
Huh, that is odd. Only thing I noticed was in your example you wrote Also, UnitSystem is static and can cause problems if tests are run in parallel. I don't know how xunit is setup as I just recently switched to it. Look forward to see what you find. |
Yes, I removed the "^" while trying to troubleshoot and find the root cause. In my tests, I removed the Also, I found the issue is with this line in the regex parser: |
Thanks for the follow up on the PR. This is a very useful project! |
Great! I'm glad you enjoy it. |
Setting up by mapping an abbreviation to an unit:
UnitSystem unitSystem = UnitSystem.GetCached("en-US"); unitSystem.MapUnitToAbbreviation(UnitsNet.Units.AccelerationUnit.MeterPerSecondSquared, "m2");
The then following works as expected, printing "MeterPerSecondSquared":
Console.WriteLine(unitSystem.Parse<UnitsNet.Units.AccelerationUnit>("m2").ToString());
But parsing from Acceleration , I expect "12 m/s²" but it throws exception
Console.WriteLine(Acceleration.Parse("12 m2").ToString());
It likely lies with the regular expression pattern in UnitParser.ParseUnit.
This is important for me because I am expecting to parse user-typed input. It is not reasonable for the user to enter the pretty input of m/s², but rather m/s^2 which has the same meaning.
I will fork and try to work it out.
The text was updated successfully, but these errors were encountered: