From 74be6f13114e8e4cb8421a684009d160c4e861f1 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 23 Jul 2017 13:15:28 -0400 Subject: improve handling of legacy non-semantic game versions (#333) --- .../Utilities/SemanticVersionTests.cs | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs') diff --git a/src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs b/src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs index 95d0d74f..db46aee4 100644 --- a/src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs +++ b/src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics.CodeAnalysis; using NUnit.Framework; +using StardewModdingAPI.Framework; namespace StardewModdingAPI.Tests.Utilities { @@ -206,6 +207,35 @@ namespace StardewModdingAPI.Tests.Utilities return version.IsBetween(lower, upper); } + /**** + ** GameVersion + ****/ + [Test(Description = "Assert that the GameVersion subclass correctly parses legacy game versions.")] + [TestCase("1.0")] + [TestCase("1.01")] + [TestCase("1.02")] + [TestCase("1.03")] + [TestCase("1.04")] + [TestCase("1.05")] + [TestCase("1.051")] + [TestCase("1.051b")] + [TestCase("1.06")] + [TestCase("1.07")] + [TestCase("1.07a")] + [TestCase("1.1")] + [TestCase("1.11")] + [TestCase("1.2")] + [TestCase("1.2.15")] + public void GameVersion(string versionStr) + { + // act + GameVersion version = new GameVersion(versionStr); + + // assert + Assert.AreEqual(versionStr, version.ToString(), "The game version did not round-trip to the same value."); + Assert.IsTrue(version.IsOlderThan(new SemanticVersion("1.2.30")), "The game version should be considered older than the later semantic versions."); + } + /********* ** Private methods -- cgit From 67b1a8398f665a745f57f6d53532e504979ea40f Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 14 Aug 2017 07:55:21 -0400 Subject: fix SemanticVersion not being deserialisable through Json.NET --- release-notes.md | 7 ++++--- .../Utilities/SemanticVersionTests.cs | 17 +++++++++++++++++ src/StardewModdingAPI/SemanticVersion.cs | 16 +++++++++------- 3 files changed, 30 insertions(+), 10 deletions(-) (limited to 'src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs') diff --git a/release-notes.md b/release-notes.md index 9bfd1981..f8980af4 100644 --- a/release-notes.md +++ b/release-notes.md @@ -32,10 +32,11 @@ For players: * Updated compatibility list. For mod developers: -* Added `Context.CanPlayerMove` value for mod convenience. -* Added `helper.Content` properties for the current language. +* Added `Context.CanPlayerMove` property for mod convenience. +* Added content helper properties for the game's current language. +* Fixed `Context.IsPlayerFree` being false if the player is performing an action. * Fixed `GraphicsEvents.Resize` being raised before the game updates its window data. -* Fixed `Context.IsPlayerFree` being incorrectly false in some cases (e.g. when using a tool). +* Fixed `SemanticVersion` not being deserialisable through Json.NET. For SMAPI developers: * Internal changes to support the upcoming SMAPI 2.0 release. diff --git a/src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs b/src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs index db46aee4..03cd26c9 100644 --- a/src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs +++ b/src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; +using Newtonsoft.Json; using NUnit.Framework; using StardewModdingAPI.Framework; @@ -207,6 +208,22 @@ namespace StardewModdingAPI.Tests.Utilities return version.IsBetween(lower, upper); } + /**** + ** Serialisable + ****/ + [Test(Description = "Assert that SemanticVersion can be round-tripped through JSON with no special configuration.")] + [TestCase("1.0")] + public void Serialisable(string versionStr) + { + // act + string json = JsonConvert.SerializeObject(new SemanticVersion(versionStr)); + SemanticVersion after = JsonConvert.DeserializeObject(json); + + // assert + Assert.IsNotNull(after, "The semantic version after deserialisation is unexpectedly null."); + Assert.AreEqual(versionStr, after.ToString(), "The semantic version after deserialisation doesn't match the input version."); + } + /**** ** GameVersion ****/ diff --git a/src/StardewModdingAPI/SemanticVersion.cs b/src/StardewModdingAPI/SemanticVersion.cs index 26de3aa8..e448eae1 100644 --- a/src/StardewModdingAPI/SemanticVersion.cs +++ b/src/StardewModdingAPI/SemanticVersion.cs @@ -1,5 +1,6 @@ using System; using System.Text.RegularExpressions; +using Newtonsoft.Json; namespace StardewModdingAPI { @@ -40,15 +41,16 @@ namespace StardewModdingAPI ** Public methods *********/ /// Construct an instance. - /// The major version incremented for major API changes. - /// The minor version incremented for backwards-compatible changes. - /// The patch version for backwards-compatible bug fixes. + /// The major version incremented for major API changes. + /// The minor version incremented for backwards-compatible changes. + /// The patch version for backwards-compatible bug fixes. /// An optional build tag. - public SemanticVersion(int major, int minor, int patch, string build = null) + [JsonConstructor] + public SemanticVersion(int majorVersion, int minorVersion, int patchVersion, string build = null) { - this.MajorVersion = major; - this.MinorVersion = minor; - this.PatchVersion = patch; + this.MajorVersion = majorVersion; + this.MinorVersion = minorVersion; + this.PatchVersion = patchVersion; this.Build = this.GetNormalisedTag(build); } -- cgit