2021-08-11 17:22:30 +02:00
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
2021-06-09 10:46:19 +01:00
|
|
|
using System.Globalization;
|
2024-09-16 16:09:43 -04:00
|
|
|
|
2021-08-16 15:25:06 +02:00
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2021-06-09 10:46:19 +01:00
|
|
|
using Wox.Plugin;
|
|
|
|
|
|
|
|
|
|
namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
|
|
|
|
|
{
|
2021-08-16 15:25:06 +02:00
|
|
|
[TestClass]
|
2021-06-09 10:46:19 +01:00
|
|
|
public class InputInterpreterTests
|
|
|
|
|
{
|
2023-12-28 13:37:13 +03:00
|
|
|
#pragma warning disable CA1861 // Avoid constant arrays as arguments
|
2021-08-16 15:25:06 +02:00
|
|
|
[DataTestMethod]
|
2022-12-28 10:43:31 -08:00
|
|
|
[DataRow(new string[] { "1,5'" }, new string[] { "1,5", "'" })]
|
|
|
|
|
[DataRow(new string[] { "1.5'" }, new string[] { "1.5", "'" })]
|
|
|
|
|
[DataRow(new string[] { "1'" }, new string[] { "1", "'" })]
|
|
|
|
|
[DataRow(new string[] { "1'5\"" }, new string[] { "1", "'", "5", "\"" })]
|
|
|
|
|
[DataRow(new string[] { "5\"" }, new string[] { "5", "\"" })]
|
|
|
|
|
[DataRow(new string[] { "1'5" }, new string[] { "1", "'", "5" })]
|
2024-01-17 19:56:34 +09:00
|
|
|
[DataRow(new string[] { "-1,5'" }, new string[] { "-1,5", "'" })]
|
|
|
|
|
[DataRow(new string[] { "-1.5'" }, new string[] { "-1.5", "'" })]
|
|
|
|
|
[DataRow(new string[] { "-1'" }, new string[] { "-1", "'" })]
|
|
|
|
|
[DataRow(new string[] { "-1'5\"" }, new string[] { "-1", "'", "5", "\"" })]
|
|
|
|
|
[DataRow(new string[] { "-5\"" }, new string[] { "-5", "\"" })]
|
|
|
|
|
[DataRow(new string[] { "-1'5" }, new string[] { "-1", "'", "5" })]
|
2021-06-09 10:46:19 +01:00
|
|
|
public void RegexSplitsInput(string[] input, string[] expectedResult)
|
|
|
|
|
{
|
|
|
|
|
string[] shortsplit = InputInterpreter.RegexSplitter(input);
|
2021-08-16 15:25:06 +02:00
|
|
|
CollectionAssert.AreEqual(expectedResult, shortsplit);
|
2021-06-09 10:46:19 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-16 15:25:06 +02:00
|
|
|
[DataTestMethod]
|
2022-12-28 10:43:31 -08:00
|
|
|
[DataRow(new string[] { "1cm", "to", "mm" }, new string[] { "1", "cm", "to", "mm" })]
|
2024-01-17 19:56:34 +09:00
|
|
|
[DataRow(new string[] { "-1cm", "to", "mm" }, new string[] { "-1", "cm", "to", "mm" })]
|
2021-06-09 10:46:19 +01:00
|
|
|
public void InsertsSpaces(string[] input, string[] expectedResult)
|
|
|
|
|
{
|
|
|
|
|
InputInterpreter.InputSpaceInserter(ref input);
|
2021-08-16 15:25:06 +02:00
|
|
|
CollectionAssert.AreEqual(expectedResult, input);
|
2021-06-09 10:46:19 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-16 15:25:06 +02:00
|
|
|
[DataTestMethod]
|
2022-12-28 10:43:31 -08:00
|
|
|
[DataRow(new string[] { "1'", "in", "cm" }, new string[] { "1", "foot", "in", "cm" })]
|
|
|
|
|
[DataRow(new string[] { "1\"", "in", "cm" }, new string[] { "1", "inch", "in", "cm" })]
|
|
|
|
|
[DataRow(new string[] { "1'6", "in", "cm" }, new string[] { "1.5", "foot", "in", "cm" })]
|
|
|
|
|
[DataRow(new string[] { "1'6\"", "in", "cm" }, new string[] { "1.5", "foot", "in", "cm" })]
|
2024-01-17 19:56:34 +09:00
|
|
|
[DataRow(new string[] { "-1'", "in", "cm" }, new string[] { "-1", "foot", "in", "cm" })]
|
|
|
|
|
[DataRow(new string[] { "-1\"", "in", "cm" }, new string[] { "-1", "inch", "in", "cm" })]
|
|
|
|
|
[DataRow(new string[] { "-1'6", "in", "cm" }, new string[] { "-1.5", "foot", "in", "cm" })]
|
|
|
|
|
[DataRow(new string[] { "-1'6\"", "in", "cm" }, new string[] { "-1.5", "foot", "in", "cm" })]
|
2021-06-09 10:46:19 +01:00
|
|
|
public void HandlesShorthandFeetInchNotation(string[] input, string[] expectedResult)
|
|
|
|
|
{
|
|
|
|
|
InputInterpreter.ShorthandFeetInchHandler(ref input, CultureInfo.InvariantCulture);
|
2021-08-16 15:25:06 +02:00
|
|
|
CollectionAssert.AreEqual(expectedResult, input);
|
2021-06-09 10:46:19 +01:00
|
|
|
}
|
|
|
|
|
|
2022-08-24 11:50:34 +02:00
|
|
|
[DataTestMethod]
|
2022-12-28 10:43:31 -08:00
|
|
|
[DataRow(new string[] { "1", "metre", "in", "metre" }, new string[] { "1", "meter", "in", "meter" })]
|
|
|
|
|
[DataRow(new string[] { "1", "centimetre", "in", "kilometre" }, new string[] { "1", "centimeter", "in", "kilometer" })]
|
|
|
|
|
[DataRow(new string[] { "1", "metres", "in", "kilometres" }, new string[] { "1", "meters", "in", "kilometers" })]
|
2022-08-24 11:50:34 +02:00
|
|
|
public void HandlesMetreVsMeterNotation(string[] input, string[] expectedResult)
|
|
|
|
|
{
|
|
|
|
|
InputInterpreter.MetreToMeter(ref input);
|
|
|
|
|
CollectionAssert.AreEqual(expectedResult, input);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 15:25:06 +02:00
|
|
|
[DataTestMethod]
|
2022-12-28 10:43:31 -08:00
|
|
|
[DataRow(new string[] { "5", "CeLsIuS", "in", "faHrenheiT" }, new string[] { "5", "DegreeCelsius", "in", "DegreeFahrenheit" })]
|
2024-09-25 14:59:49 +02:00
|
|
|
[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" })]
|
2021-06-09 10:46:19 +01:00
|
|
|
public void PrefixesDegrees(string[] input, string[] expectedResult)
|
|
|
|
|
{
|
|
|
|
|
InputInterpreter.DegreePrefixer(ref input);
|
2021-08-16 15:25:06 +02:00
|
|
|
CollectionAssert.AreEqual(expectedResult, input);
|
2021-06-09 10:46:19 +01:00
|
|
|
}
|
|
|
|
|
|
2025-03-19 01:37:43 +01:00
|
|
|
[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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 15:25:06 +02:00
|
|
|
[DataTestMethod]
|
|
|
|
|
[DataRow("a f in c")]
|
|
|
|
|
[DataRow("12 f in")]
|
2024-01-17 19:56:34 +09:00
|
|
|
[DataRow("1-2 f in c")]
|
|
|
|
|
[DataRow("12- f in c")]
|
2021-06-09 10:46:19 +01:00
|
|
|
public void ParseInvalidQueries(string queryString)
|
|
|
|
|
{
|
|
|
|
|
Query query = new Query(queryString);
|
|
|
|
|
var result = InputInterpreter.Parse(query);
|
|
|
|
|
Assert.AreEqual(null, result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 15:25:06 +02:00
|
|
|
[DataTestMethod]
|
|
|
|
|
[DataRow("12 f in c", 12)]
|
|
|
|
|
[DataRow("10m to cm", 10)]
|
2024-01-17 19:56:34 +09:00
|
|
|
[DataRow("-12 f in c", -12)]
|
|
|
|
|
[DataRow("-10m to cm", -10)]
|
2021-06-09 10:46:19 +01:00
|
|
|
public void ParseValidQueries(string queryString, double result)
|
|
|
|
|
{
|
|
|
|
|
Query query = new Query(queryString);
|
|
|
|
|
var convertModel = InputInterpreter.Parse(query);
|
|
|
|
|
Assert.AreEqual(result, convertModel.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|