summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs')
-rw-r--r--src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs b/src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs
index 95d0d74f..03cd26c9 100644
--- a/src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs
+++ b/src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs
@@ -1,6 +1,8 @@
using System;
using System.Diagnostics.CodeAnalysis;
+using Newtonsoft.Json;
using NUnit.Framework;
+using StardewModdingAPI.Framework;
namespace StardewModdingAPI.Tests.Utilities
{
@@ -206,6 +208,51 @@ 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<SemanticVersion>(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
+ ****/
+ [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