Files
felhom.eu/hub/internal/semver/semver_test.go
T

39 lines
1000 B
Go

package semver
import "testing"
func TestCompare(t *testing.T) {
cases := []struct {
a, b string
want int
}{
{"0.81.0", "0.82.0", -1},
{"0.82.0", "0.81.0", 1},
{"0.81.0", "0.81.0", 0},
{"v0.81.0", "0.81.0", 0}, // v-prefix tolerated
{"0.100.0", "0.81.0", 1}, // numeric, not lexicographic
{"1.0.0", "0.99.9", 1}, // major
{"1.2.10", "1.2.3", 1}, // patch numeric
{"garbage", "0.81.0", 0}, // parse error → 0 (callers guard with Valid)
{"0.81", "0.81.0", 0}, // too few parts → 0
}
for _, c := range cases {
if got := Compare(c.a, c.b); got != c.want {
t.Errorf("Compare(%q,%q) = %d, want %d", c.a, c.b, got, c.want)
}
}
}
func TestValid(t *testing.T) {
for _, ok := range []string{"0.81.0", "v0.82.0", "10.20.30"} {
if !Valid(ok) {
t.Errorf("Valid(%q) = false, want true", ok)
}
}
for _, bad := range []string{"", "0.81", "0.81.0-rc1", "a.b.c", "dev"} {
if Valid(bad) {
t.Errorf("Valid(%q) = true, want false", bad)
}
}
}