mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
@@ -0,0 +1,37 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
<Platforms>x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Include="..\..\..\..\codeAnalysis\StyleCop.json" Link="StyleCop.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\..\codeAnalysis\GlobalSuppressions.cs" Link="GlobalSuppressions.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NUnit" Version="3.13.1" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Community.PowerToys.Run.Plugin.UnitConverter\Community.PowerToys.Run.Plugin.UnitConverter.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,67 @@
|
||||
using System.Globalization;
|
||||
using NUnit.Framework;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
|
||||
{
|
||||
[TestFixture]
|
||||
public class InputInterpreterTests
|
||||
{
|
||||
[TestCase(new string[] { "1,5'" }, new string[] { "1,5", "'" })]
|
||||
[TestCase(new string[] { "1.5'" }, new string[] { "1.5", "'" })]
|
||||
[TestCase(new string[] { "1'" }, new string[] { "1", "'" })]
|
||||
[TestCase(new string[] { "1'5\"" }, new string[] { "1", "'", "5", "\"" })]
|
||||
[TestCase(new string[] { "5\"" }, new string[] { "5", "\"" })]
|
||||
[TestCase(new string[] { "1'5" }, new string[] { "1", "'", "5" })]
|
||||
public void RegexSplitsInput(string[] input, string[] expectedResult)
|
||||
{
|
||||
string[] shortsplit = InputInterpreter.RegexSplitter(input);
|
||||
Assert.AreEqual(expectedResult, shortsplit);
|
||||
}
|
||||
|
||||
[TestCase(new string[] { "1cm", "to", "mm" }, new string[] { "1", "cm", "to", "mm" })]
|
||||
public void InsertsSpaces(string[] input, string[] expectedResult)
|
||||
{
|
||||
InputInterpreter.InputSpaceInserter(ref input);
|
||||
Assert.AreEqual(expectedResult, input);
|
||||
}
|
||||
|
||||
[TestCase(new string[] { "1'", "in", "cm" }, new string[] { "1", "foot", "in", "cm" })]
|
||||
[TestCase(new string[] { "1\"", "in", "cm" }, new string[] { "1", "inch", "in", "cm" })]
|
||||
[TestCase(new string[] { "1'6", "in", "cm" }, new string[] { "1.5", "foot", "in", "cm" })]
|
||||
[TestCase(new string[] { "1'6\"", "in", "cm" }, new string[] { "1.5", "foot", "in", "cm" })]
|
||||
public void HandlesShorthandFeetInchNotation(string[] input, string[] expectedResult)
|
||||
{
|
||||
InputInterpreter.ShorthandFeetInchHandler(ref input, CultureInfo.InvariantCulture);
|
||||
Assert.AreEqual(expectedResult, input);
|
||||
}
|
||||
|
||||
[TestCase(new string[] { "5", "CeLsIuS", "in", "faHrenheiT" }, new string[] { "5", "DegreeCelsius", "in", "DegreeFahrenheit" })]
|
||||
[TestCase(new string[] { "5", "f", "in", "celsius" }, new string[] { "5", "<22>f", "in", "DegreeCelsius" })]
|
||||
[TestCase(new string[] { "5", "c", "in", "f" }, new string[] { "5", "<22>c", "in", "<22>f" })]
|
||||
[TestCase(new string[] { "5", "f", "in", "c" }, new string[] { "5", "<22>f", "in", "<22>c" })]
|
||||
public void PrefixesDegrees(string[] input, string[] expectedResult)
|
||||
{
|
||||
InputInterpreter.DegreePrefixer(ref input);
|
||||
Assert.AreEqual(expectedResult, input);
|
||||
}
|
||||
|
||||
[TestCase("a f in c")]
|
||||
[TestCase("12 f in")]
|
||||
public void ParseInvalidQueries(string queryString)
|
||||
{
|
||||
Query query = new Query(queryString);
|
||||
var result = InputInterpreter.Parse(query);
|
||||
Assert.AreEqual(null, result);
|
||||
}
|
||||
|
||||
[TestCase("12 f in c", 12)]
|
||||
[TestCase("10m to cm", 10)]
|
||||
public void ParseValidQueries(string queryString, double result)
|
||||
{
|
||||
Query query = new Query(queryString);
|
||||
var convertModel = InputInterpreter.Parse(query);
|
||||
Assert.AreEqual(result, convertModel.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
|
||||
{
|
||||
[TestFixture]
|
||||
public class UnitHandlerTests
|
||||
{
|
||||
[Test]
|
||||
public void HandleTemperature()
|
||||
{
|
||||
var convertModel = new ConvertModel(1, "DegreeCelsius", "DegreeFahrenheit");
|
||||
double result = UnitHandler.ConvertInput(convertModel, UnitsNet.QuantityType.Temperature);
|
||||
Assert.AreEqual(33.79999999999999d, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HandleLength()
|
||||
{
|
||||
var convertModel = new ConvertModel(1, "meter", "centimeter");
|
||||
double result = UnitHandler.ConvertInput(convertModel, UnitsNet.QuantityType.Length);
|
||||
Assert.AreEqual(100, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HandlesByteCapitals()
|
||||
{
|
||||
var convertModel = new ConvertModel(1, "kB", "kb");
|
||||
double result = UnitHandler.ConvertInput(convertModel, UnitsNet.QuantityType.Information);
|
||||
Assert.AreEqual(8, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HandleInvalidModel()
|
||||
{
|
||||
var convertModel = new ConvertModel(1, "aa", "bb");
|
||||
var results = UnitHandler.Convert(convertModel);
|
||||
Assert.AreEqual(0, results.Count());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user