Something went wrong. Try again.
Maps Linux distribution source packages to their upstream repositories, and through them to each other
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243package debian
import "testing"
func TestCompareVersions(t *testing.T) { cases := []struct { a, b string want int }{ {"1.0", "1.0", 0}, {"1.0-1", "1.0-2", -1}, {"1:1.0", "2.0", 1}, {"1.0~rc1", "1.0", -1}, {"1.0~rc1-1", "1.0~rc2-1", -1}, {"1.0", "1.0~", 1}, {"1.0a", "1.0", 1}, {"1.0a", "1.0+", -1}, // letters before non-letters {"1.0.10", "1.0.9", 1}, // numeric runs {"8.23.0~rc1-1", "8.22.0-1", 1}, {"8.22.0-1+exp1", "8.22.0-1", 1}, {"1:1.3.dfsg+really1.3.2-3", "1:1.3.dfsg+really1.3.2-2", 1}, {"1:1.3.dfsg+really1.3.2-3", "1:1.3.dfsg-1", 1}, {"2.32.3+dfsg-5+deb13u1", "2.32.5+dfsg-2", -1}, {"1.14-1~exp2", "1.14-1", -1}, {"1.14-1", "1.13-1+deb13u1", 1}, {"0", "00", 0}, {"1.0-1", "1.0", 1}, {"5.9.2-1", "5.9-8", 1}, } for _, c := range cases { if got := CompareVersions(c.a, c.b); got != c.want { t.Errorf("CompareVersions(%q,%q) = %d, want %d", c.a, c.b, got, c.want) } if got := CompareVersions(c.b, c.a); got != -c.want { t.Errorf("CompareVersions(%q,%q) = %d, want %d (antisymmetry)", c.b, c.a, got, -c.want) } } e, u, r := SplitVersion("1:1.3.dfsg+really1.3.2-3") if e != 1 || u != "1.3.dfsg+really1.3.2" || r != "3" { t.Errorf("SplitVersion = %d %q %q", e, u, r) }}