From 1ed98c837c6aec0603a83b4f1b7102322ee7b4ca Mon Sep 17 00:00:00 2001 From: HerickJ-22 Date: Mon, 11 Jul 2022 12:30:21 +0200 Subject: [PATCH 1/2] fix: map systemVersion -1 to 0 --- src/Yaapii.Atoms/Map/VersionMap.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Yaapii.Atoms/Map/VersionMap.cs b/src/Yaapii.Atoms/Map/VersionMap.cs index 450e951a..d344c846 100644 --- a/src/Yaapii.Atoms/Map/VersionMap.cs +++ b/src/Yaapii.Atoms/Map/VersionMap.cs @@ -179,16 +179,22 @@ IEnumerator IEnumerable.GetEnumerator() private Value Match(Version candidate) { + var prettyCandidate = new Version( + candidate.Major, + candidate.Minor, + candidate.Build == -1 ? 0 : candidate.Build, + candidate.Revision == -1 ? 0 : candidate.Revision + ); var match = new Version(0, 0); var matched = false; foreach (var lowerBound in this.map.Keys) { - if (candidate >= lowerBound) + if (prettyCandidate >= lowerBound) { match = lowerBound; matched = true; } - else if (match < candidate) + else if (match < prettyCandidate) { break; } @@ -202,10 +208,10 @@ private Value Match(Version candidate) } else { - throw this.versionNotFound(candidate, this.map.Keys); + throw this.versionNotFound(prettyCandidate, this.map.Keys); } } - throw this.versionNotFound(candidate, this.map.Keys); + throw this.versionNotFound(prettyCandidate, this.map.Keys); } } } From ba4faf88afe0b4c1fe56d8d8bed15283cfb73589 Mon Sep 17 00:00:00 2001 From: HerickJ-22 Date: Mon, 11 Jul 2022 12:30:29 +0200 Subject: [PATCH 2/2] feat: test for versionMap --- .../Yaapii.Atoms.Tests/Map/VersionMapTests.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/Yaapii.Atoms.Tests/Map/VersionMapTests.cs b/tests/Yaapii.Atoms.Tests/Map/VersionMapTests.cs index 2916d975..5353558c 100644 --- a/tests/Yaapii.Atoms.Tests/Map/VersionMapTests.cs +++ b/tests/Yaapii.Atoms.Tests/Map/VersionMapTests.cs @@ -82,5 +82,28 @@ public void MatchesWithinClosedEnd() ).ContainsKey(new Version(2, 0, 0, 0)) ); } + + [Fact] + public void MatchesEndingZero() + { + Assert.True( + new VersionMap(false, + new KvpOf(new Version(1, 0, 0, 0), "ainz"), + new KvpOf(new Version(5, 0, 0, 0), "zway") + ).ContainsKey(new Version(1, 0)) + ); + } + + [Fact] + public void MatchesMajorMinorVersion() + { + Assert.Equal( + "zway", + new VersionMap(true, + new KvpOf(new Version(1, 0, 0, 0), "ainz"), + new KvpOf(new Version(5, 0, 0, 0), "zway") + )[new Version(5, 0)] + ); + } } }