Skip to content

Commit b215ac5

Browse files
committed
UnitSystemTests: Add tests on parsing custom units
1 parent 165b5ff commit b215ac5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

UnitsNet.Tests/UnitSystemTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,27 @@ public void DecimalPointDigitGroupingCultureFormatting(string culture)
305305

306306
#region Significant Digits After Radix Formatting
307307

308+
[Test]
309+
public void MapUnitToAbbreviation_AddCustomUnit_DoesNotOverrideDefaultAbbreviationForAlreadyMappedUnits()
310+
{
311+
CultureInfo cultureInfo = CultureInfo.GetCultureInfo("en-US");
312+
UnitSystem unitSystem = UnitSystem.GetCached(cultureInfo);
313+
unitSystem.MapUnitToAbbreviation(AreaUnit.SquareMeter, "m^2");
314+
315+
Assert.AreEqual("m²", unitSystem.GetDefaultAbbreviation(AreaUnit.SquareMeter));
316+
}
317+
318+
[TestCase("m^2", Result = AreaUnit.SquareMeter)]
319+
[TestCase("cm^2", Result = AreaUnit.Undefined)]
320+
public AreaUnit Parse_ReturnsUnitMappedByCustomAbbreviationOrUndefined(string unitAbbreviationToParse)
321+
{
322+
CultureInfo cultureInfo = CultureInfo.GetCultureInfo("en-US");
323+
UnitSystem unitSystem = UnitSystem.GetCached(cultureInfo);
324+
unitSystem.MapUnitToAbbreviation(AreaUnit.SquareMeter, "m^2");
325+
326+
return unitSystem.Parse<AreaUnit>(unitAbbreviationToParse);
327+
}
328+
308329
[TestCase(1, Result = "1.1 m")]
309330
[TestCase(2, Result = "1.12 m")]
310331
[TestCase(3, Result = "1.123 m")]

0 commit comments

Comments
 (0)