-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Parse and TryParse static methods on Version and Range. (#48)
- Loading branch information
1 parent
00c1ecb
commit fd0934d
Showing
3 changed files
with
146 additions
and
11 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Xunit; | ||
|
||
namespace SemVer.Tests | ||
{ | ||
public class TryParse | ||
{ | ||
[Theory] | ||
[InlineData("1.0.0", false, true)] | ||
[InlineData("v 1.2.3", true, true)] | ||
[InlineData("Not SemVer", false, false)] | ||
public void VersionTryParse(string input, bool loose, bool expectedResult) | ||
{ | ||
//Given | ||
|
||
//When | ||
var success = Version.TryParse(input, loose, out var version); | ||
|
||
//Then | ||
Assert.Equal(expectedResult, success); | ||
if (success) | ||
{ | ||
Assert.NotNull(version); | ||
} | ||
else | ||
{ | ||
Assert.Null(version); | ||
} | ||
} | ||
|
||
|
||
[Theory] | ||
[InlineData("~1.0.0", false, true)] | ||
[InlineData("< 1", true, true)] | ||
[InlineData("Not SemVer Range", false, false)] | ||
public void RangeTryParse(string rangeSpec, bool loose, bool expectedResult) | ||
{ | ||
//Given | ||
|
||
//When | ||
var success = Range.TryParse(rangeSpec, loose, out var range); | ||
|
||
//Then | ||
Assert.Equal(expectedResult, success); | ||
if (success) | ||
{ | ||
Assert.NotNull(range); | ||
} | ||
else { | ||
Assert.Null(range); | ||
} | ||
} | ||
} | ||
} |