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;
|
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
|
|
|
|
|
|
{
|
2021-08-16 15:25:06 +02:00
|
|
|
|
[DataTestMethod]
|
|
|
|
|
|
[DataRow(new string[] { "1,5'" }, new object[] { new string[] { "1,5", "'" } })]
|
|
|
|
|
|
[DataRow(new string[] { "1.5'" }, new object[] { new string[] { "1.5", "'" } })]
|
|
|
|
|
|
[DataRow(new string[] { "1'" }, new object[] { new string[] { "1", "'" } })]
|
|
|
|
|
|
[DataRow(new string[] { "1'5\"" }, new object[] { new string[] { "1", "'", "5", "\"" } })]
|
|
|
|
|
|
[DataRow(new string[] { "5\"" }, new object[] { new string[] { "5", "\"" } })]
|
|
|
|
|
|
[DataRow(new string[] { "1'5" }, new object[] { 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]
|
|
|
|
|
|
[DataRow(new string[] { "1cm", "to", "mm" }, new object[] { 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]
|
|
|
|
|
|
[DataRow(new string[] { "1'", "in", "cm" }, new object[] { new string[] { "1", "foot", "in", "cm" } })]
|
|
|
|
|
|
[DataRow(new string[] { "1\"", "in", "cm" }, new object[] { new string[] { "1", "inch", "in", "cm" } })]
|
|
|
|
|
|
[DataRow(new string[] { "1'6", "in", "cm" }, new object[] { new string[] { "1.5", "foot", "in", "cm" } })]
|
|
|
|
|
|
[DataRow(new string[] { "1'6\"", "in", "cm" }, new object[] { 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
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-16 15:25:06 +02:00
|
|
|
|
[DataTestMethod]
|
|
|
|
|
|
[DataRow(new string[] { "5", "CeLsIuS", "in", "faHrenheiT" }, new object[] { new string[] { "5", "DegreeCelsius", "in", "DegreeFahrenheit" } })]
|
|
|
|
|
|
[DataRow(new string[] { "5", "f", "in", "celsius" }, new object[] { new string[] { "5", "<22>f", "in", "DegreeCelsius" } })]
|
|
|
|
|
|
[DataRow(new string[] { "5", "c", "in", "f" }, new object[] { new string[] { "5", "<22>c", "in", "<22>f" } })]
|
|
|
|
|
|
[DataRow(new string[] { "5", "f", "in", "c" }, new object[] { new string[] { "5", "<22>f", "in", "<22>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
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-16 15:25:06 +02:00
|
|
|
|
[DataTestMethod]
|
|
|
|
|
|
[DataRow("a f in c")]
|
|
|
|
|
|
[DataRow("12 f in")]
|
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)]
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|