From 2ff937397163f0ad5940b636bc7312ac747d9c39 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 18 Oct 2017 10:59:57 -0400 Subject: fix compatibility check crashing for players with SDV 1.08 --- src/SMAPI.Tests/Utilities/SemanticVersionTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/SMAPI.Tests') diff --git a/src/SMAPI.Tests/Utilities/SemanticVersionTests.cs b/src/SMAPI.Tests/Utilities/SemanticVersionTests.cs index 03cd26c9..73ecd56e 100644 --- a/src/SMAPI.Tests/Utilities/SemanticVersionTests.cs +++ b/src/SMAPI.Tests/Utilities/SemanticVersionTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json; using NUnit.Framework; @@ -239,6 +239,7 @@ namespace StardewModdingAPI.Tests.Utilities [TestCase("1.06")] [TestCase("1.07")] [TestCase("1.07a")] + [TestCase("1.08")] [TestCase("1.1")] [TestCase("1.11")] [TestCase("1.2")] -- cgit From 1bea3a9e3273b8222cc2cc5c153bfb70fdba521a Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 29 Oct 2017 23:15:18 -0400 Subject: let SemanticVersion be constructed from a System.Version (#375) --- docs/release-notes.md | 1 + src/SMAPI.Common/SemanticVersionImpl.cs | 13 +++++++++++++ src/SMAPI.Tests/Utilities/SemanticVersionTests.cs | 20 ++++++++++++++++++-- src/SMAPI/SemanticVersion.cs | 6 ++++++ 4 files changed, 38 insertions(+), 2 deletions(-) (limited to 'src/SMAPI.Tests') 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 @@ -48,6 +48,19 @@ namespace StardewModdingAPI.Common this.Tag = this.GetNormalisedTag(tag); } + /// Construct an instance. + /// The assembly version. + /// The is null. + 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; + } + /// Construct an instance. /// The semantic version string. /// The is null. 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)) { } + /// Construct an instance. + /// The assembly version. + /// The is null. + public SemanticVersion(Version version) + : this(new SemanticVersionImpl(version)) { } + /// Get an integer indicating whether this version precedes (less than 0), supercedes (more than 0), or is equivalent to (0) the specified version. /// The version to compare with this instance. /// The value is null. -- cgit