From 586b80dbd36b8219711dbb4011eb48334bc13962 Mon Sep 17 00:00:00 2001 From: Luca Scalzotto Date: Sat, 9 Dec 2023 09:50:17 +0100 Subject: [PATCH] Add SemVerMatches tests --- internal/semver_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 internal/semver_test.go diff --git a/internal/semver_test.go b/internal/semver_test.go new file mode 100644 index 0000000..1cb5503 --- /dev/null +++ b/internal/semver_test.go @@ -0,0 +1,28 @@ +package internal + +import "testing" + +func TestSemVerMatches(t *testing.T) { + cases := [][]any{ + {"1.2.3", "1.2.3", true}, + {"1.2.3", "1.2", true}, + {"1.2.3", "1", true}, + {"invalid", "2.0.0", false}, + {"2.0.0", "invalid", false}, + {"", "3.0.0", false}, + {"4.0.0", "v4", true}, + {"v4.0.0", "4", true}, + {" 5.0.0 ", "5.0.0", true}, + {"5.0.0 ", " 5.0.0 ", true}, + } + + for _, c := range cases { + a := c[0].(string) + b := c[1].(string) + expected := c[2].(bool) + actual := SemVerMatches(a, b) + if actual != expected { + t.Errorf("SemVerMatches(%s, %s) = %t, expected %t", a, b, actual, expected) + } + } +}