summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/release-notes.md1
-rw-r--r--src/SMAPI.Common/SemanticVersionImpl.cs13
-rw-r--r--src/SMAPI.Tests/Utilities/SemanticVersionTests.cs20
-rw-r--r--src/SMAPI/SemanticVersion.cs6
4 files changed, 38 insertions, 2 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index c810334b..dc88bfa4 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -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.
diff --git a/src/SMAPI.Common/SemanticVersionImpl.cs b/src/SMAPI.Common/SemanticVersionImpl.cs
index 193d23f9..53cf5a21 100644
--- a/src/SMAPI.Common/SemanticVersionImpl.cs
+++ b/src/SMAPI.Common/SemanticVersionImpl.cs
@@ -49,6 +49,19 @@ namespace StardewModdingAPI.Common
}
/// <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>
/// <exception cref="FormatException">The <paramref name="version"/> is not a valid semantic version.</exception>
diff --git a/src/SMAPI.Tests/Utilities/SemanticVersionTests.cs b/src/SMAPI.Tests/Utilities/SemanticVersionTests.cs
index 73ecd56e..d3e0988e 100644
--- a/src/SMAPI.Tests/Utilities/SemanticVersionTests.cs
+++ b/src/SMAPI.Tests/Utilities/SemanticVersionTests.cs
@@ -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("")]
diff --git a/src/SMAPI/SemanticVersion.cs b/src/SMAPI/SemanticVersion.cs
index ce86dceb..4826c947 100644
--- a/src/SMAPI/SemanticVersion.cs
+++ b/src/SMAPI/SemanticVersion.cs
@@ -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>