From 475333b2f36135097691be0b4e0a7eff3f83103f Mon Sep 17 00:00:00 2001 From: Travis Leeden Date: Wed, 3 Jan 2024 16:28:46 +1000 Subject: [PATCH 1/2] Added new versioning type - Unsortable --- .../UnsortableVersionCompareTests.cs | 62 ++++++++ .../UnsortableVersionParserTests.cs | 81 +++++++++++ .../Unsortable/UnsortableVersion.cs | 136 ++++++++++++++++++ .../Unsortable/UnsortableVersionParser.cs | 56 ++++++++ source/Octopus.Versioning/VersionFactory.cs | 22 +++ source/Octopus.Versioning/VersionFormat.cs | 3 +- 6 files changed, 359 insertions(+), 1 deletion(-) create mode 100644 source/Octopus.Versioning.Tests/Unsortable/UnsortableVersionCompareTests.cs create mode 100644 source/Octopus.Versioning.Tests/Unsortable/UnsortableVersionParserTests.cs create mode 100644 source/Octopus.Versioning/Unsortable/UnsortableVersion.cs create mode 100644 source/Octopus.Versioning/Unsortable/UnsortableVersionParser.cs diff --git a/source/Octopus.Versioning.Tests/Unsortable/UnsortableVersionCompareTests.cs b/source/Octopus.Versioning.Tests/Unsortable/UnsortableVersionCompareTests.cs new file mode 100644 index 0000000..dfa5ca5 --- /dev/null +++ b/source/Octopus.Versioning.Tests/Unsortable/UnsortableVersionCompareTests.cs @@ -0,0 +1,62 @@ +using NUnit.Framework; +using Octopus.Versioning.Unsortable; + +namespace Octopus.Versioning.Tests.Unsortable; + +public class UnsortableVersionCompareTests +{ + static readonly UnsortableVersionParser UnsortableVersionParser = new(); + + [Test] + [TestCase("release", "release", 0)] + [TestCase("release", "qrelease", 1)] + [TestCase("release", "srelease", -1)] + [TestCase("123", "123", 0)] + [TestCase("123", "100", 1)] + [TestCase("123", "321", -1)] + [TestCase("123Release", "123Release", 0)] + [TestCase("123Release", "100Release", 1)] + [TestCase("123Release", "321Release", -1)] + [TestCase("release-1", "release-1", 0)] + [TestCase("release-1", "release-0", 1)] + [TestCase("release-1", "release-2", -1)] + [TestCase("release.1", "release.1", 0)] + [TestCase("release.1", "release.0", 1)] + [TestCase("release.1", "release.2", -1)] + [TestCase("release_1", "release_1", 0)] + [TestCase("release_1", "release_0", 1)] + [TestCase("release_1", "release_2", -1)] + [TestCase("release-1", "release_1", 0)] + [TestCase("release.1", "release_1", 0)] + [TestCase("release-1", "release_0", 1)] + [TestCase("release.1", "release_2", -1)] + [TestCase("release+123", "release+321", 0)] + [TestCase("release-1+123", "release-1+321", 0)] + [TestCase("release-1+123", "release-0+321", 1)] + [TestCase("release-1+123", "release-2+321", -1)] + public void TestComparisons(string version1, string version2, int result) + { + var parsedVersion1 = UnsortableVersionParser.Parse(version1); + var parsedVersion2 = UnsortableVersionParser.Parse(version2); + Assert.AreEqual(result, parsedVersion1.CompareTo(parsedVersion2)); + } + + [Test] + [TestCase("release-1", "release-1", true)] + [TestCase("release-1", "release-2", false)] + public void TestEquality(string version1, string version2, bool result) + { + var parsedVersion1 = UnsortableVersionParser.Parse(version1); + var parsedVersion2 = UnsortableVersionParser.Parse(version2); + Assert.AreEqual(result, Equals(parsedVersion1, parsedVersion2)); + } + + [Test] + public void TestGetHashCode() + { + var versionString = "release-1"; + var parsedVersion = UnsortableVersionParser.Parse(versionString); + + Assert.AreEqual(versionString.GetHashCode(), parsedVersion.GetHashCode()); + } +} \ No newline at end of file diff --git a/source/Octopus.Versioning.Tests/Unsortable/UnsortableVersionParserTests.cs b/source/Octopus.Versioning.Tests/Unsortable/UnsortableVersionParserTests.cs new file mode 100644 index 0000000..cc2ad3a --- /dev/null +++ b/source/Octopus.Versioning.Tests/Unsortable/UnsortableVersionParserTests.cs @@ -0,0 +1,81 @@ +using System; +using NUnit.Framework; +using Octopus.Versioning.Unsortable; + +namespace Octopus.Versioning.Tests.Unsortable; + +[TestFixture] +public class UnsortableVersionParserTests +{ + [Test] + // Release + [TestCase("foobar", "foobar", "")] + [TestCase("2db4a87840113c", "2db4a87840113c", "")] + [TestCase("123456", "123456", "")] + [TestCase("foobar-qwerty", "foobar-qwerty", "")] + [TestCase("foobar.qwerty", "foobar.qwerty", "")] + [TestCase("foobar_qwerty", "foobar_qwerty", "")] + [TestCase("foobar-12345", "foobar-12345", "")] + // Metadata + [TestCase("foobar+12345", "foobar", "12345")] + [TestCase("foobar+123.456", "foobar", "123.456")] + [TestCase("foobar+123_456", "foobar", "123_456")] + [TestCase("foobar+123-456", "foobar", "123-456")] + [TestCase("foobar+123+456", "foobar", "123+456")] + [TestCase("foobar+1.2_3-4+5", "foobar", "1.2_3-4+5")] + [TestCase("foobar+qwerty", "foobar", "qwerty")] + [TestCase("foobar-qwerty+12345", "foobar-qwerty", "12345")] + // Fail Cases + [TestCase("!@#$%^", "", "")] + [TestCase("foobar-!@#$%", "", "")] + [TestCase("foobar-qwerty+!@#$%", "", "")] + [TestCase("foo bar", "", "")] + [TestCase("foobar-qwe ty", "", "")] + [TestCase("foobar+123 456", "", "")] + [TestCase("foo bar-qwe ty+123 456", "", "")] + [TestCase("!foobar", "", "")] + [TestCase("foo!bar", "", "")] + [TestCase("foobar!", "", "")] + public void ShouldParseSuccessfully(string input, string expectedRelease, string expectedMetadata) + { + _ = new UnsortableVersionParser().TryParse(input, out var parsedVersion); + AssertVersionNumbersAreZero(parsedVersion); + Assert.AreEqual(expectedRelease, parsedVersion.Release); + Assert.AreEqual(expectedMetadata, parsedVersion.Metadata); + } + + [Test] + public void ShouldThrowExceptionOnEmptyInput() + { + var input = ""; + Assert.Catch(() => new UnsortableVersionParser().Parse(input)); + } + + [Test] + public void ShouldThrowExceptionOnWhiteSpaceInput() + { + var input = " "; + Assert.Catch(() => new UnsortableVersionParser().Parse(input)); + } + + [Test] + public void ShouldThrowExceptionOnNullInput() + { + Assert.Catch(() => new UnsortableVersionParser().Parse(null)); + } + + [Test] + public void ShouldThrowExceptionOnFailureToParse() + { + var input = "bad versions string"; + Assert.Catch(() => new UnsortableVersionParser().Parse(input)); + } + + void AssertVersionNumbersAreZero(UnsortableVersion version) + { + Assert.AreEqual(0, version.Major); + Assert.AreEqual(0, version.Minor); + Assert.AreEqual(0, version.Patch); + Assert.AreEqual(0, version.Revision); + } +} \ No newline at end of file diff --git a/source/Octopus.Versioning/Unsortable/UnsortableVersion.cs b/source/Octopus.Versioning/Unsortable/UnsortableVersion.cs new file mode 100644 index 0000000..66ebf00 --- /dev/null +++ b/source/Octopus.Versioning/Unsortable/UnsortableVersion.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Octopus.Versioning.Unsortable +{ + public class UnsortableVersion: IVersion + { + public UnsortableVersion(string release, string? metadata, string? originalString) + { + Metadata = metadata; + Release = release; + OriginalString = originalString ?? string.Empty; + } + + public int Major => 0; + public int Minor => 0; + public int Patch => 0; + public int Revision => 0; + public bool IsPrerelease => false; + public IEnumerable ReleaseLabels => Enumerable.Empty(); + public string? Metadata { get; } + public bool HasMetadata => !string.IsNullOrWhiteSpace(Metadata); + public string Release { get; } + public string OriginalString { get; } + + public VersionFormat Format => VersionFormat.Unsortable; + + public int CompareTo(object obj) + { + if (!(obj is IVersion objVersion)) + return -1; + + if (string.Compare(Release.AlphaNumericOnly(), (objVersion.Release ?? string.Empty).AlphaNumericOnly(), StringComparison.Ordinal) != 0) + return CompareReleaseLabels(Release.AlphaNumericOnly().Split('.', '-', '_'), (objVersion.Release ?? string.Empty).AlphaNumericOnly().Split('.', '-', '_')); + + return 0; + } + + public override string ToString() + { + return OriginalString; + } + + public override bool Equals(object obj) + { + if (obj is IVersion objVersion) + return CompareTo(objVersion) == 0; + + return false; + } + + public override int GetHashCode() + { + return Release.GetHashCode(); + } + + /// + /// Compares sets of release labels. + /// + static int CompareReleaseLabels(IEnumerable version1, IEnumerable version2) + { + var result = 0; + + using var a = version1.GetEnumerator(); + using var b = version2.GetEnumerator(); + + var aExists = a.MoveNext(); + var bExists = b.MoveNext(); + + while (aExists || bExists) + { + if (!aExists && bExists) + return -1; + + if (aExists && !bExists) + return 1; + + // compare the labels + result = CompareRelease(a.Current, b.Current); + + if (result != 0) + return result; + + aExists = a.MoveNext(); + bExists = b.MoveNext(); + } + + return result; + } + + /// + /// Release labels are compared as numbers if they are numeric, otherwise they will be compared + /// as strings. + /// + static int CompareRelease(string version1, string version2) + { + var version1Num = 0; + var version2Num = 0; + var result = 0; + + // check if the identifiers are numeric + var v1IsNumeric = int.TryParse(version1, out version1Num); + var v2IsNumeric = int.TryParse(version2, out version2Num); + + // if both are numeric compare them as numbers + if (v1IsNumeric && v2IsNumeric) + { + result = version1Num.CompareTo(version2Num); + } + else if (v1IsNumeric || v2IsNumeric) + { + // numeric labels come before alpha labels + if (v1IsNumeric) + result = -1; + else + result = 1; + } + else + { + // Ignoring 2.0.0 case sensitive compare. Everything will be compared case insensitively as 2.0.1 specifies. + var stringCompareResult = StringComparer.OrdinalIgnoreCase.Compare(version1, version2); + if (stringCompareResult < 0) + { + result = -1; + } + else if (stringCompareResult > 0) + { + result = 1; + } + } + + return result; + } + } +} \ No newline at end of file diff --git a/source/Octopus.Versioning/Unsortable/UnsortableVersionParser.cs b/source/Octopus.Versioning/Unsortable/UnsortableVersionParser.cs new file mode 100644 index 0000000..79ba0e6 --- /dev/null +++ b/source/Octopus.Versioning/Unsortable/UnsortableVersionParser.cs @@ -0,0 +1,56 @@ +using System; +using System.Text.RegularExpressions; + +namespace Octopus.Versioning.Unsortable +{ + public class UnsortableVersionParser + { + const string Release = "release"; + const string Meta = "buildmetadata"; + + static readonly Regex VersionRegex = new Regex($@"^(?<{Release}>([A-Za-z0-9]*?)([.\-_\\]([A-Za-z0-9.\-_\\]*?)?)?)?" + + $@"(?:\+(?<{Meta}>[A-Za-z0-9_\-.\\+]*?))?\s*$" + ); + + public UnsortableVersion Parse(string? version) + { + if (string.IsNullOrWhiteSpace(version)) + throw new ArgumentException("The version can not be an empty string"); + + var sanitisedVersion = version ?? string.Empty; + // SemVerFactory treated the original string as if it had no spaces at all + var noSpaces = sanitisedVersion.Replace(" ", ""); + + // We parse on the original string. This *does not* tolerate spaces in prerelease fields or metadata + // just like SemVerFactory. + var result = VersionRegex.Match(sanitisedVersion); + + if (!result.Success) + throw new ArgumentException("The supplied version was not valid"); + + return new UnsortableVersion( + result.Groups[Release].Success ? result.Groups[Release].Value : string.Empty, + result.Groups[Meta].Success ? result.Groups[Meta].Value : string.Empty, + noSpaces + ); + } + + public bool TryParse(string version, out UnsortableVersion parsedVersion) + { + try + { + parsedVersion = Parse(version); + return true; + } + catch + { + parsedVersion = new UnsortableVersion( + string.Empty, + string.Empty, + null + ); + return false; + } + } + } +} \ No newline at end of file diff --git a/source/Octopus.Versioning/VersionFactory.cs b/source/Octopus.Versioning/VersionFactory.cs index d079b93..edcb258 100644 --- a/source/Octopus.Versioning/VersionFactory.cs +++ b/source/Octopus.Versioning/VersionFactory.cs @@ -4,6 +4,7 @@ using Octopus.Versioning.Maven; using Octopus.Versioning.Octopus; using Octopus.Versioning.Semver; +using Octopus.Versioning.Unsortable; namespace Octopus.Versioning { @@ -19,6 +20,8 @@ public static IVersion CreateVersion(string input, VersionFormat format) return CreateDockerTag(input); case VersionFormat.Octopus: return CreateOctopusVersion(input); + case VersionFormat.Unsortable: + return CreateUnsortableVersion(input); default: return CreateSemanticVersion(input); } @@ -34,6 +37,8 @@ public static IVersion CreateVersion(string input, VersionFormat format) return TryCreateDockerTag(input); case VersionFormat.Octopus: return TryCreateOctopusVersion(input); + case VersionFormat.Unsortable: + return TryCreateUnsortableVersion(input); default: return TryCreateSemanticVersion(input); } @@ -150,5 +155,22 @@ public static IVersion CreateOctopusVersion(string input) return null; } } + + public static IVersion CreateUnsortableVersion(string input) + { + return new UnsortableVersionParser().Parse(input); + } + + public static IVersion? TryCreateUnsortableVersion(string input) + { + try + { + return CreateUnsortableVersion(input); + } + catch + { + return null; + } + } } } \ No newline at end of file diff --git a/source/Octopus.Versioning/VersionFormat.cs b/source/Octopus.Versioning/VersionFormat.cs index 12051fc..14e84f7 100644 --- a/source/Octopus.Versioning/VersionFormat.cs +++ b/source/Octopus.Versioning/VersionFormat.cs @@ -7,6 +7,7 @@ public enum VersionFormat Semver, Maven, Docker, - Octopus + Octopus, + Unsortable } } \ No newline at end of file From 48638fd40dd42309906557e6ca72098b6826185a Mon Sep 17 00:00:00 2001 From: Travis Leeden Date: Fri, 12 Jan 2024 15:28:11 +1000 Subject: [PATCH 2/2] Rename to LexicographicSortedVersion --- ...LexicographicSortedVersionCompareTests.cs} | 19 ++++++++++--------- .../LexicographicSortedVersionParserTests.cs} | 18 +++++++++--------- .../LexicographicSortedVersion.cs} | 8 ++++---- .../LexicographicSortedVersionParser.cs} | 12 ++++++------ source/Octopus.Versioning/VersionFactory.cs | 18 +++++++++--------- source/Octopus.Versioning/VersionFormat.cs | 2 +- 6 files changed, 39 insertions(+), 38 deletions(-) rename source/Octopus.Versioning.Tests/{Unsortable/UnsortableVersionCompareTests.cs => LexicographicSortedVersion/LexicographicSortedVersionCompareTests.cs} (73%) rename source/Octopus.Versioning.Tests/{Unsortable/UnsortableVersionParserTests.cs => LexicographicSortedVersion/LexicographicSortedVersionParserTests.cs} (74%) rename source/Octopus.Versioning/{Unsortable/UnsortableVersion.cs => Lexicographic/LexicographicSortedVersion.cs} (93%) rename source/Octopus.Versioning/{Unsortable/UnsortableVersionParser.cs => Lexicographic/LexicographicSortedVersionParser.cs} (81%) diff --git a/source/Octopus.Versioning.Tests/Unsortable/UnsortableVersionCompareTests.cs b/source/Octopus.Versioning.Tests/LexicographicSortedVersion/LexicographicSortedVersionCompareTests.cs similarity index 73% rename from source/Octopus.Versioning.Tests/Unsortable/UnsortableVersionCompareTests.cs rename to source/Octopus.Versioning.Tests/LexicographicSortedVersion/LexicographicSortedVersionCompareTests.cs index dfa5ca5..ab92cc6 100644 --- a/source/Octopus.Versioning.Tests/Unsortable/UnsortableVersionCompareTests.cs +++ b/source/Octopus.Versioning.Tests/LexicographicSortedVersion/LexicographicSortedVersionCompareTests.cs @@ -1,11 +1,12 @@ +using System; using NUnit.Framework; -using Octopus.Versioning.Unsortable; +using Octopus.Versioning.Lexicographic; -namespace Octopus.Versioning.Tests.Unsortable; +namespace Octopus.Versioning.Tests.LexicographicSortedVersion; -public class UnsortableVersionCompareTests +public class LexicographicSortedVersionCompareTests { - static readonly UnsortableVersionParser UnsortableVersionParser = new(); + static readonly LexicographicSortedVersionParser LexicographicSortedVersionParser = new(); [Test] [TestCase("release", "release", 0)] @@ -36,8 +37,8 @@ public class UnsortableVersionCompareTests [TestCase("release-1+123", "release-2+321", -1)] public void TestComparisons(string version1, string version2, int result) { - var parsedVersion1 = UnsortableVersionParser.Parse(version1); - var parsedVersion2 = UnsortableVersionParser.Parse(version2); + var parsedVersion1 = LexicographicSortedVersionParser.Parse(version1); + var parsedVersion2 = LexicographicSortedVersionParser.Parse(version2); Assert.AreEqual(result, parsedVersion1.CompareTo(parsedVersion2)); } @@ -46,8 +47,8 @@ public void TestComparisons(string version1, string version2, int result) [TestCase("release-1", "release-2", false)] public void TestEquality(string version1, string version2, bool result) { - var parsedVersion1 = UnsortableVersionParser.Parse(version1); - var parsedVersion2 = UnsortableVersionParser.Parse(version2); + var parsedVersion1 = LexicographicSortedVersionParser.Parse(version1); + var parsedVersion2 = LexicographicSortedVersionParser.Parse(version2); Assert.AreEqual(result, Equals(parsedVersion1, parsedVersion2)); } @@ -55,7 +56,7 @@ public void TestEquality(string version1, string version2, bool result) public void TestGetHashCode() { var versionString = "release-1"; - var parsedVersion = UnsortableVersionParser.Parse(versionString); + var parsedVersion = LexicographicSortedVersionParser.Parse(versionString); Assert.AreEqual(versionString.GetHashCode(), parsedVersion.GetHashCode()); } diff --git a/source/Octopus.Versioning.Tests/Unsortable/UnsortableVersionParserTests.cs b/source/Octopus.Versioning.Tests/LexicographicSortedVersion/LexicographicSortedVersionParserTests.cs similarity index 74% rename from source/Octopus.Versioning.Tests/Unsortable/UnsortableVersionParserTests.cs rename to source/Octopus.Versioning.Tests/LexicographicSortedVersion/LexicographicSortedVersionParserTests.cs index cc2ad3a..3b305c5 100644 --- a/source/Octopus.Versioning.Tests/Unsortable/UnsortableVersionParserTests.cs +++ b/source/Octopus.Versioning.Tests/LexicographicSortedVersion/LexicographicSortedVersionParserTests.cs @@ -1,11 +1,11 @@ using System; using NUnit.Framework; -using Octopus.Versioning.Unsortable; +using Octopus.Versioning.Lexicographic; -namespace Octopus.Versioning.Tests.Unsortable; +namespace Octopus.Versioning.Tests.LexicographicSortedVersion; [TestFixture] -public class UnsortableVersionParserTests +public class LexicographicSortedVersionParserTests { [Test] // Release @@ -38,7 +38,7 @@ public class UnsortableVersionParserTests [TestCase("foobar!", "", "")] public void ShouldParseSuccessfully(string input, string expectedRelease, string expectedMetadata) { - _ = new UnsortableVersionParser().TryParse(input, out var parsedVersion); + _ = new LexicographicSortedVersionParser().TryParse(input, out var parsedVersion); AssertVersionNumbersAreZero(parsedVersion); Assert.AreEqual(expectedRelease, parsedVersion.Release); Assert.AreEqual(expectedMetadata, parsedVersion.Metadata); @@ -48,30 +48,30 @@ public void ShouldParseSuccessfully(string input, string expectedRelease, string public void ShouldThrowExceptionOnEmptyInput() { var input = ""; - Assert.Catch(() => new UnsortableVersionParser().Parse(input)); + Assert.Catch(() => new LexicographicSortedVersionParser().Parse(input)); } [Test] public void ShouldThrowExceptionOnWhiteSpaceInput() { var input = " "; - Assert.Catch(() => new UnsortableVersionParser().Parse(input)); + Assert.Catch(() => new LexicographicSortedVersionParser().Parse(input)); } [Test] public void ShouldThrowExceptionOnNullInput() { - Assert.Catch(() => new UnsortableVersionParser().Parse(null)); + Assert.Catch(() => new LexicographicSortedVersionParser().Parse(null)); } [Test] public void ShouldThrowExceptionOnFailureToParse() { var input = "bad versions string"; - Assert.Catch(() => new UnsortableVersionParser().Parse(input)); + Assert.Catch(() => new LexicographicSortedVersionParser().Parse(input)); } - void AssertVersionNumbersAreZero(UnsortableVersion version) + void AssertVersionNumbersAreZero(Lexicographic.LexicographicSortedVersion version) { Assert.AreEqual(0, version.Major); Assert.AreEqual(0, version.Minor); diff --git a/source/Octopus.Versioning/Unsortable/UnsortableVersion.cs b/source/Octopus.Versioning/Lexicographic/LexicographicSortedVersion.cs similarity index 93% rename from source/Octopus.Versioning/Unsortable/UnsortableVersion.cs rename to source/Octopus.Versioning/Lexicographic/LexicographicSortedVersion.cs index 66ebf00..d6a2b3e 100644 --- a/source/Octopus.Versioning/Unsortable/UnsortableVersion.cs +++ b/source/Octopus.Versioning/Lexicographic/LexicographicSortedVersion.cs @@ -2,11 +2,11 @@ using System.Collections.Generic; using System.Linq; -namespace Octopus.Versioning.Unsortable +namespace Octopus.Versioning.Lexicographic { - public class UnsortableVersion: IVersion + public class LexicographicSortedVersion: IVersion { - public UnsortableVersion(string release, string? metadata, string? originalString) + public LexicographicSortedVersion(string release, string? metadata, string? originalString) { Metadata = metadata; Release = release; @@ -24,7 +24,7 @@ public UnsortableVersion(string release, string? metadata, string? originalStrin public string Release { get; } public string OriginalString { get; } - public VersionFormat Format => VersionFormat.Unsortable; + public VersionFormat Format => VersionFormat.Lexicographic; public int CompareTo(object obj) { diff --git a/source/Octopus.Versioning/Unsortable/UnsortableVersionParser.cs b/source/Octopus.Versioning/Lexicographic/LexicographicSortedVersionParser.cs similarity index 81% rename from source/Octopus.Versioning/Unsortable/UnsortableVersionParser.cs rename to source/Octopus.Versioning/Lexicographic/LexicographicSortedVersionParser.cs index 79ba0e6..0476d02 100644 --- a/source/Octopus.Versioning/Unsortable/UnsortableVersionParser.cs +++ b/source/Octopus.Versioning/Lexicographic/LexicographicSortedVersionParser.cs @@ -1,9 +1,9 @@ using System; using System.Text.RegularExpressions; -namespace Octopus.Versioning.Unsortable +namespace Octopus.Versioning.Lexicographic { - public class UnsortableVersionParser + public class LexicographicSortedVersionParser { const string Release = "release"; const string Meta = "buildmetadata"; @@ -12,7 +12,7 @@ public class UnsortableVersionParser $@"(?:\+(?<{Meta}>[A-Za-z0-9_\-.\\+]*?))?\s*$" ); - public UnsortableVersion Parse(string? version) + public LexicographicSortedVersion Parse(string? version) { if (string.IsNullOrWhiteSpace(version)) throw new ArgumentException("The version can not be an empty string"); @@ -28,14 +28,14 @@ public UnsortableVersion Parse(string? version) if (!result.Success) throw new ArgumentException("The supplied version was not valid"); - return new UnsortableVersion( + return new LexicographicSortedVersion( result.Groups[Release].Success ? result.Groups[Release].Value : string.Empty, result.Groups[Meta].Success ? result.Groups[Meta].Value : string.Empty, noSpaces ); } - public bool TryParse(string version, out UnsortableVersion parsedVersion) + public bool TryParse(string version, out LexicographicSortedVersion parsedVersion) { try { @@ -44,7 +44,7 @@ public bool TryParse(string version, out UnsortableVersion parsedVersion) } catch { - parsedVersion = new UnsortableVersion( + parsedVersion = new LexicographicSortedVersion( string.Empty, string.Empty, null diff --git a/source/Octopus.Versioning/VersionFactory.cs b/source/Octopus.Versioning/VersionFactory.cs index edcb258..76adb04 100644 --- a/source/Octopus.Versioning/VersionFactory.cs +++ b/source/Octopus.Versioning/VersionFactory.cs @@ -1,10 +1,10 @@ using System; using System.Collections.Generic; using Octopus.Versioning.Docker; +using Octopus.Versioning.Lexicographic; using Octopus.Versioning.Maven; using Octopus.Versioning.Octopus; using Octopus.Versioning.Semver; -using Octopus.Versioning.Unsortable; namespace Octopus.Versioning { @@ -20,8 +20,8 @@ public static IVersion CreateVersion(string input, VersionFormat format) return CreateDockerTag(input); case VersionFormat.Octopus: return CreateOctopusVersion(input); - case VersionFormat.Unsortable: - return CreateUnsortableVersion(input); + case VersionFormat.Lexicographic: + return CreateLexicographicSortedVersion(input); default: return CreateSemanticVersion(input); } @@ -37,8 +37,8 @@ public static IVersion CreateVersion(string input, VersionFormat format) return TryCreateDockerTag(input); case VersionFormat.Octopus: return TryCreateOctopusVersion(input); - case VersionFormat.Unsortable: - return TryCreateUnsortableVersion(input); + case VersionFormat.Lexicographic: + return TryCreateLexicographicSortedVersion(input); default: return TryCreateSemanticVersion(input); } @@ -156,16 +156,16 @@ public static IVersion CreateOctopusVersion(string input) } } - public static IVersion CreateUnsortableVersion(string input) + public static IVersion CreateLexicographicSortedVersion(string input) { - return new UnsortableVersionParser().Parse(input); + return new LexicographicSortedVersionParser().Parse(input); } - public static IVersion? TryCreateUnsortableVersion(string input) + public static IVersion? TryCreateLexicographicSortedVersion(string input) { try { - return CreateUnsortableVersion(input); + return CreateLexicographicSortedVersion(input); } catch { diff --git a/source/Octopus.Versioning/VersionFormat.cs b/source/Octopus.Versioning/VersionFormat.cs index 14e84f7..5f3054c 100644 --- a/source/Octopus.Versioning/VersionFormat.cs +++ b/source/Octopus.Versioning/VersionFormat.cs @@ -8,6 +8,6 @@ public enum VersionFormat Maven, Docker, Octopus, - Unsortable + Lexicographic } } \ No newline at end of file