git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/semver/semver_test.go (about) 1 package semver 2 3 import ( 4 "testing" 5 ) 6 7 func TestIsValid(t *testing.T) { 8 tests := []struct { 9 version string 10 expectedResult bool 11 }{ 12 {"1.0.0", true}, 13 {"2.0.0", true}, 14 {"100.0.0", true}, 15 {"1.0efds.0", false}, 16 {"1", true}, 17 } 18 19 for _, test := range tests { 20 if IsValid(test.version) != test.expectedResult { 21 t.Errorf("got (%v) for (%s). Expected result: %v", IsValid(test.version), test.version, test.expectedResult) 22 } 23 } 24 } 25 26 func TestCompare(t *testing.T) { 27 tests := []struct { 28 v string 29 w string 30 expectedResult int 31 }{ 32 { 33 "1.0.0", 34 "1.1.1", 35 -1, 36 }, 37 { 38 "1.0.0", 39 "1.0.0", 40 0, 41 }, 42 { 43 "2.0.0", 44 "1.0.0", 45 1, 46 }, 47 } 48 49 for _, test := range tests { 50 if Compare(test.v, test.w) != test.expectedResult { 51 t.Errorf("got (%d) for (%s, %s). Expected result: %d", Compare(test.v, test.w), test.v, test.w, test.expectedResult) 52 } 53 } 54 }