mirror of
https://github.com/microsoft/PowerToys
synced 2025-08-22 10:07:37 +00:00
[PTRun][UnitConverter]Add support for sq
prefix for square units (#37862)
* [PTRun][UnitConverter]Add support for `sq` prefix for square quantities
This commit is contained in:
parent
648c3eb0bf
commit
a62acf7a71
3
.github/actions/spell-check/allow/code.txt
vendored
3
.github/actions/spell-check/allow/code.txt
vendored
@ -233,6 +233,9 @@ SWAPBUTTON
|
|||||||
SYSTEMDOCKED
|
SYSTEMDOCKED
|
||||||
TABLETPC
|
TABLETPC
|
||||||
|
|
||||||
|
# Units
|
||||||
|
nmi
|
||||||
|
|
||||||
# MATH
|
# MATH
|
||||||
|
|
||||||
artanh
|
artanh
|
||||||
|
@ -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", "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", "c", "in", "f" }, new string[] { "5", "°C", "in", "°F" })]
|
||||||
[DataRow(new string[] { "5", "f", "in", "c" }, new string[] { "5", "°F", "in", "°C" })]
|
[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)
|
public void PrefixesDegrees(string[] input, string[] expectedResult)
|
||||||
{
|
{
|
||||||
InputInterpreter.DegreePrefixer(ref input);
|
InputInterpreter.DegreePrefixer(ref input);
|
||||||
CollectionAssert.AreEqual(expectedResult, 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]
|
[DataTestMethod]
|
||||||
[DataRow("a f in c")]
|
[DataRow("a f in c")]
|
||||||
[DataRow("12 f in")]
|
[DataRow("12 f in")]
|
||||||
|
@ -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)
|
public static ConvertModel Parse(Query query)
|
||||||
{
|
{
|
||||||
string[] split = query.Search.Split(' ');
|
string[] split = query.Search.Split(' ');
|
||||||
@ -279,6 +285,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
|
|||||||
InputInterpreter.KPHHandler(ref split);
|
InputInterpreter.KPHHandler(ref split);
|
||||||
InputInterpreter.GallonHandler(ref split, CultureInfo.CurrentCulture);
|
InputInterpreter.GallonHandler(ref split, CultureInfo.CurrentCulture);
|
||||||
InputInterpreter.OunceHandler(ref split, CultureInfo.CurrentCulture);
|
InputInterpreter.OunceHandler(ref split, CultureInfo.CurrentCulture);
|
||||||
|
InputInterpreter.SquareHandler(ref split);
|
||||||
if (!double.TryParse(split[0], out double value))
|
if (!double.TryParse(split[0], out double value))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user