[PTRun][Calculator]Fix trailing zeroes on hexadecimal numbers (#17248)

* [PTRun][Calculator]Fix hexadecimal trailing 0s

* Add tests
This commit is contained in:
Jaime Bernardo
2022-03-24 16:59:27 +00:00
committed by GitHub
parent aba4e462a8
commit 75f2be1891
2 changed files with 17 additions and 1 deletions

View File

@@ -130,5 +130,21 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
Assert.IsNotNull(result);
Assert.AreEqual(expectedResult, result);
}
[DataTestMethod]
[DataRow("12.0004", "12.0004")]
[DataRow("0xF000", "0xF000")]
public void Translate_NoRemovalOfLeadingZeroesOnEdgeCases(string input, string expectedResult)
{
// Arrange
var translator = NumberTranslator.Create(new CultureInfo("pt-PT"), new CultureInfo("en-US"));
// Act
var result = translator.Translate(input);
// Assert
Assert.IsNotNull(result);
Assert.AreEqual(expectedResult, result);
}
}
}

View File

@@ -95,7 +95,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
// Now, even if . is not part of the culture representation, users won't hit this error since the number will
// be passed as is to the calculator engine.
// This shouldn't add any regressions into accepted strings while it will have a behavior the users expect.
var splitPattern = $"((?:\\d|\\.|{Regex.Escape(culture.NumberFormat.NumberDecimalSeparator)}";
var splitPattern = $"((?:\\d|[a-fA-F]|\\.|{Regex.Escape(culture.NumberFormat.NumberDecimalSeparator)}";
if (!string.IsNullOrEmpty(culture.NumberFormat.NumberGroupSeparator))
{
splitPattern += $"|{Regex.Escape(culture.NumberFormat.NumberGroupSeparator)}";