-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make QuantityParser public and add tests
- Loading branch information
1 parent
c81e1bb
commit 5e26a16
Showing
4 changed files
with
56 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Licensed under MIT No Attribution, see LICENSE file at the root. | ||
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. | ||
|
||
using UnitsNet.Tests.CustomQuantities; | ||
using Xunit; | ||
|
||
namespace UnitsNet.Tests | ||
{ | ||
public class QuantityParserTests | ||
{ | ||
[Fact] | ||
public void Parse_MappedCustomUnit() | ||
{ | ||
var unitAbbreviationsCache = new UnitAbbreviationsCache(); | ||
unitAbbreviationsCache.MapUnitToAbbreviation(HowMuchUnit.Some, "fooh"); | ||
var quantityParser = new QuantityParser(unitAbbreviationsCache); | ||
|
||
HowMuch q = quantityParser.Parse<HowMuch, HowMuchUnit>("1 fooh", | ||
null, | ||
(value, unit) => new HowMuch((double) value, unit)); | ||
|
||
Assert.Equal(HowMuchUnit.Some, q.Unit); | ||
Assert.Equal(1, q.Value); | ||
} | ||
|
||
[Fact] | ||
public void TryParse_MappedCustomUnit() | ||
{ | ||
var unitAbbreviationsCache = new UnitAbbreviationsCache(); | ||
unitAbbreviationsCache.MapUnitToAbbreviation(HowMuchUnit.Some, "fooh"); | ||
var quantityParser = new QuantityParser(unitAbbreviationsCache); | ||
|
||
bool success = quantityParser.TryParse<HowMuch, HowMuchUnit>("1 fooh", | ||
null, | ||
(value, unit) => new HowMuch((double) value, unit), | ||
out HowMuch q); | ||
|
||
Assert.True(success); | ||
Assert.Equal(HowMuchUnit.Some, q.Unit); | ||
Assert.Equal(1, q.Value); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters