github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/api/types/versions/compare_test.go (about) 1 package versions // import "github.com/demonoid81/moby/api/types/versions" 2 3 import ( 4 "testing" 5 ) 6 7 func assertVersion(t *testing.T, a, b string, result int) { 8 if r := compare(a, b); r != result { 9 t.Fatalf("Unexpected version comparison result. Found %d, expected %d", r, result) 10 } 11 } 12 13 func TestCompareVersion(t *testing.T) { 14 assertVersion(t, "1.12", "1.12", 0) 15 assertVersion(t, "1.0.0", "1", 0) 16 assertVersion(t, "1", "1.0.0", 0) 17 assertVersion(t, "1.05.00.0156", "1.0.221.9289", 1) 18 assertVersion(t, "1", "1.0.1", -1) 19 assertVersion(t, "1.0.1", "1", 1) 20 assertVersion(t, "1.0.1", "1.0.2", -1) 21 assertVersion(t, "1.0.2", "1.0.3", -1) 22 assertVersion(t, "1.0.3", "1.1", -1) 23 assertVersion(t, "1.1", "1.1.1", -1) 24 assertVersion(t, "1.1.1", "1.1.2", -1) 25 assertVersion(t, "1.1.2", "1.2", -1) 26 }