The appropriate [SemanticVersion] constructor now accepts a [version] instance that has only major and minor components specified, in which case the patch component now defaults to 0.
This commit is contained in:
Michael Klement 2017-05-16 20:10:03 -04:00 committed by Mike Richmond
parent 96506f4cc1
commit 30b97a5d7c
2 changed files with 5 additions and 2 deletions

View file

@ -493,11 +493,11 @@ namespace System.Management.Automation
/// <param name="version">The version.</param>
public SemanticVersion(Version version)
{
if (version.Revision > 0 || version.Build < 0) throw PSTraceSource.NewArgumentException(nameof(version));
if (version.Revision > 0) throw PSTraceSource.NewArgumentException(nameof(version));
Major = version.Major;
Minor = version.Minor;
Patch = version.Build;
Patch = version.Build == -1 ? 0 : version.Build;
var psobj = new PSObject(version);
var labelNote = psobj.Properties[LabelPropertyName];
if (labelNote != null)

View file

@ -50,6 +50,9 @@ Describe "SemanticVersion api tests" -Tags 'CI' {
}
It "version arg constructor" {
$v = [SemanticVersion]::new([Version]::new(1, 2))
$v.ToString() | Should Be '1.2.0'
$v = [SemanticVersion]::new([Version]::new(1, 2, 3))
$v.ToString() | Should Be '1.2.3'
}