diff --git a/.github/actions/spell-check/allow/code.txt b/.github/actions/spell-check/allow/code.txt index c89a84e003..619a036b32 100644 --- a/.github/actions/spell-check/allow/code.txt +++ b/.github/actions/spell-check/allow/code.txt @@ -233,6 +233,9 @@ SWAPBUTTON SYSTEMDOCKED TABLETPC +# Units +nmi + # MATH artanh diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter.UnitTest/InputInterpreterTests.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter.UnitTest/InputInterpreterTests.cs index d6932f0f0c..a0792c4313 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter.UnitTest/InputInterpreterTests.cs +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter.UnitTest/InputInterpreterTests.cs @@ -71,13 +71,23 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest [DataRow(new string[] { "5", "f", "in", "celsius" }, new string[] { "5", "°F", "in", "DegreeCelsius" })] [DataRow(new string[] { "5", "c", "in", "f" }, new string[] { "5", "°C", "in", "°F" })] [DataRow(new string[] { "5", "f", "in", "c" }, new string[] { "5", "°F", "in", "°C" })] -#pragma warning restore CA1861 // Avoid constant arrays as arguments public void PrefixesDegrees(string[] input, string[] expectedResult) { InputInterpreter.DegreePrefixer(ref input); CollectionAssert.AreEqual(expectedResult, input); } + [DataTestMethod] + [DataRow(new string[] { "7", "cm/sqs", "in", "m/s^2" }, new string[] { "7", "cm/s²", "in", "m/s^2" })] + [DataRow(new string[] { "7", "sqft", "in", "sqcm" }, new string[] { "7", "ft²", "in", "cm²" })] + [DataRow(new string[] { "7", "BTU/s·sqin", "in", "cal/h·sqcm" }, new string[] { "7", "BTU/s·in²", "in", "cal/h·cm²" })] +#pragma warning restore CA1861 // Avoid constant arrays as arguments + public void HandlesSquareNotation(string[] input, string[] expectedResult) + { + InputInterpreter.SquareHandler(ref input); + CollectionAssert.AreEqual(expectedResult, input); + } + [DataTestMethod] [DataRow("a f in c")] [DataRow("12 f in")] diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/InputInterpreter.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/InputInterpreter.cs index 1af8b11ea3..dbe718e6e7 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/InputInterpreter.cs +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/InputInterpreter.cs @@ -259,6 +259,12 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter } } + public static void SquareHandler(ref string[] split) + { + split[1] = Regex.Replace(split[1], "sq(s|μm|mm|cm|dm|m|km|mil|in|ft|yd|mi|nmi)", "$1²"); + split[3] = Regex.Replace(split[3], "sq(s|μm|mm|cm|dm|m|km|mil|in|ft|yd|mi|nmi)", "$1²"); + } + public static ConvertModel Parse(Query query) { string[] split = query.Search.Split(' '); @@ -279,6 +285,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter InputInterpreter.KPHHandler(ref split); InputInterpreter.GallonHandler(ref split, CultureInfo.CurrentCulture); InputInterpreter.OunceHandler(ref split, CultureInfo.CurrentCulture); + InputInterpreter.SquareHandler(ref split); if (!double.TryParse(split[0], out double value)) { return null;