Skip to content

Commit

Permalink
#5068 Fix inconsistency in keeping track of NuGetVersion.OriginalVers…
Browse files Browse the repository at this point in the history
…ion (#1329)
  • Loading branch information
xavierdecoster authored Apr 25, 2017
1 parent a15fd84 commit da863e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/NuGet.Core/NuGet.Versioning/NuGetVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public NuGetVersion(string version)
/// Creates a NuGetVersion from an existing NuGetVersion
/// </summary>
public NuGetVersion(NuGetVersion version)
: this(version.Version, version.ReleaseLabels, version.Metadata, version.ToString())
: this(version.Version, version.ReleaseLabels, version.Metadata, version.OriginalVersion)
{
}

Expand Down
16 changes: 15 additions & 1 deletion test/NuGet.Core.Tests/NuGet.Versioning.Test/NuGetVersionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void SemVerEqualityComparisonsWorkForNullValues()
[InlineData("1.0.0-b")]
[InlineData("3.0.1.2")]
[InlineData("2.1.4.3-pre-1")]
public void ToStringReturnsOriginalValue(string version)
public void ToStringReturnsOriginalValueForNonSemVer2(string version)
{
// Act
var semVer = NuGetVersion.Parse(version);
Expand Down Expand Up @@ -288,6 +288,20 @@ public void ToStringConstructedFromVersionAndSpecialVersionConstructor(string ve
Assert.Equal(expected, semVer.ToString());
}

[Theory]
[InlineData("01.42.0")]
[InlineData("01.0")]
[InlineData("01.42.0-alpha")]
[InlineData("01.42.0-alpha.1")]
[InlineData("01.42.0-alpha+metadata")]
[InlineData("01.42.0+metadata")]
public void NuGetVersionKeepsOriginalVersionString(string originalVersion)
{
var version = new NuGetVersion(originalVersion);

Assert.Equal(originalVersion, version.OriginalVersion);
}

[Theory]
[InlineData("1.0", null, "1.0")]
[InlineData("1.0.3.120", "", "1.0.3.120")]
Expand Down

0 comments on commit da863e0

Please sign in to comment.