Skip to content

Commit a0e783c

Browse files
committed
Add tests on TryParse()
1 parent 27a0ad7 commit a0e783c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

UnitsNet.Tests/CustomCode/ParseTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,17 @@ public LengthUnit ParseLengthUnitUsEnglish(string s)
104104

105105
return Length.ParseUnit(s, usEnglish);
106106
}
107+
108+
[TestCase("1 m", Result = true)]
109+
[TestCase("1 m 50 cm", Result = true)]
110+
[TestCase("2 kg", Result = false)]
111+
[TestCase(null, Result = false)]
112+
[TestCase("foo", Result = false)]
113+
public bool TryParseLengthUnitUsEnglish(string s)
114+
{
115+
CultureInfo usEnglish = CultureInfo.GetCultureInfo("en-US");
116+
Length result;
117+
return Length.TryParse(s, usEnglish, out result);
118+
}
107119
}
108120
}

0 commit comments

Comments
 (0)