github.com/ZuluSpl0it/Sia@v1.3.7/build/version_test.go (about) 1 package build 2 3 import ( 4 "testing" 5 ) 6 7 // TestVersionCmp checks that in all cases, VersionCmp returns the correct 8 // result. 9 func TestVersionCmp(t *testing.T) { 10 versionTests := []struct { 11 a, b string 12 exp int 13 }{ 14 {"0.1", "0.0.9", 1}, 15 {"0.1", "0.1", 0}, 16 {"0.1", "0.1.1", -1}, 17 {"0.1", "0.1.0", -1}, 18 {"0.1", "1.1", -1}, 19 {"0.1.1.0", "0.1.1", 1}, 20 } 21 22 for _, test := range versionTests { 23 if actual := VersionCmp(test.a, test.b); actual != test.exp { 24 t.Errorf("Comparing %v to %v should return %v (got %v)", test.a, test.b, test.exp, actual) 25 } 26 } 27 } 28 29 // TestIsVersion tests the IsVersion function. 30 func TestIsVersion(t *testing.T) { 31 versionTests := []struct { 32 str string 33 exp bool 34 }{ 35 {"1.0", true}, 36 {"1", true}, 37 {"0.1.2.3.4.5", true}, 38 39 {"foo", false}, 40 {".1", false}, 41 {"1.", false}, 42 {"a.b", false}, 43 {"1.o", false}, 44 {".", false}, 45 {"", false}, 46 } 47 48 for _, test := range versionTests { 49 if IsVersion(test.str) != test.exp { 50 t.Errorf("IsVersion(%v) should return %v", test.str, test.exp) 51 } 52 } 53 }