Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistency in keeping track of NuGetVersion.OriginalVersion #1329

Merged
merged 1 commit into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the culprit.

{
}

Expand Down
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")]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the above fix, these three SemVer2 versions would fail the test.

[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