let SemanticVersion be constructed from a System.Version (#375)

This commit is contained in:
Jesse Plamondon-Willard 2017-10-29 23:15:18 -04:00
parent 359e1df431
commit 1bea3a9e32
4 changed files with 38 additions and 2 deletions

View File

@ -15,6 +15,7 @@
* Deprecated `e.IsClick`, which is limited and unclear. Use `IsActionButton` or `IsUseToolButton` instead.
* Fixed `e.SuppressButton()` not correctly suppressing keyboard buttons.
* Fixed `e.IsClick` (now `e.IsActionButton`) ignoring custom key bindings.
* `SemanticVersion` can now be constructed from a `System.Version`.
* Fixed custom map tilesheets not working unless they're explicitly loaded first.
* Fixed mods which implement `IAssetLoader` directly not being allowed to load files due to incorrect conflict detection.
* Fixed SMAPI blocking reflection access to vanilla members on overridden types.

View File

@ -48,6 +48,19 @@ namespace StardewModdingAPI.Common
this.Tag = this.GetNormalisedTag(tag);
}
/// <summary>Construct an instance.</summary>
/// <param name="version">The assembly version.</param>
/// <exception cref="ArgumentNullException">The <paramref name="version"/> is null.</exception>
public SemanticVersionImpl(Version version)
{
if (version == null)
throw new ArgumentNullException(nameof(version), "The input version can't be null.");
this.Major = version.Major;
this.Minor = version.Minor;
this.Patch = version.Build;
}
/// <summary>Construct an instance.</summary>
/// <param name="version">The semantic version string.</param>
/// <exception cref="ArgumentNullException">The <paramref name="version"/> is null.</exception>

View File

@ -16,7 +16,7 @@ namespace StardewModdingAPI.Tests.Utilities
/****
** Constructor
****/
[Test(Description = "Assert that the constructor sets the expected values for all valid versions.")]
[Test(Description = "Assert that the constructor sets the expected values for all valid versions when constructed from a string.")]
[TestCase("1.0", ExpectedResult = "1.0")]
[TestCase("1.0.0", ExpectedResult = "1.0")]
[TestCase("3000.4000.5000", ExpectedResult = "3000.4000.5000")]
@ -28,7 +28,7 @@ namespace StardewModdingAPI.Tests.Utilities
return new SemanticVersion(input).ToString();
}
[Test(Description = "Assert that the constructor sets the expected values for all valid versions.")]
[Test(Description = "Assert that the constructor sets the expected values for all valid versions when constructed from the individual numbers.")]
[TestCase(1, 0, 0, null, ExpectedResult = "1.0")]
[TestCase(3000, 4000, 5000, null, ExpectedResult = "3000.4000.5000")]
[TestCase(1, 2, 3, "", ExpectedResult = "1.2.3")]
@ -48,6 +48,22 @@ namespace StardewModdingAPI.Tests.Utilities
return version.ToString();
}
[Test(Description = "Assert that the constructor sets the expected values for all valid versions when constructed from an assembly version.")]
[TestCase(1, 0, 0, ExpectedResult = "1.0")]
[TestCase(1, 2, 3, ExpectedResult = "1.2.3")]
[TestCase(3000, 4000, 5000, ExpectedResult = "3000.4000.5000")]
public string Constructor_FromAssemblyVersion(int major, int minor, int patch)
{
// act
ISemanticVersion version = new SemanticVersion(new Version(major, minor, patch));
// assert
Assert.AreEqual(major, version.MajorVersion, "The major version doesn't match the given value.");
Assert.AreEqual(minor, version.MinorVersion, "The minor version doesn't match the given value.");
Assert.AreEqual(patch, version.PatchVersion, "The patch version doesn't match the given value.");
return version.ToString();
}
[Test(Description = "Assert that the constructor throws the expected exception for invalid versions.")]
[TestCase(null)]
[TestCase("")]

View File

@ -49,6 +49,12 @@ namespace StardewModdingAPI
public SemanticVersion(string version)
: this(new SemanticVersionImpl(version)) { }
/// <summary>Construct an instance.</summary>
/// <param name="version">The assembly version.</param>
/// <exception cref="ArgumentNullException">The <paramref name="version"/> is null.</exception>
public SemanticVersion(Version version)
: this(new SemanticVersionImpl(version)) { }
/// <summary>Get an integer indicating whether this version precedes (less than 0), supercedes (more than 0), or is equivalent to (0) the specified version.</summary>
/// <param name="other">The version to compare with this instance.</param>
/// <exception cref="ArgumentNullException">The <paramref name="other"/> value is null.</exception>