【rich function】CustomVersionCompare append

This commit is contained in:
sunwei
2020-08-09 02:04:38 +08:00
committed by Kevin Wan
parent babb240cbe
commit 1104363988
2 changed files with 117 additions and 0 deletions

View File

@@ -28,3 +28,33 @@ func TestCompareVersions(t *testing.T) {
})
}
}
func TestCustomCompareVersions(t *testing.T) {
cases := []struct {
ver1 string
ver2 string
operator string
out bool
}{
{"1", "1.0.1", ">", false},
{"1", "0.9.9", ">", true},
{"1", "1-0.1", "<", true},
{"1.0.1", "1-0.1", "<", false},
{"1.0.1", "1.0.1", "==", true},
{"1.0.1", "1.0.2", "==", false},
{"1.1-1", "1.0.2", "==", false},
{"1.0.1", "1.0.2", ">=", false},
{"1.0.2", "1.0.2", ">=", true},
{"1.0.3", "1.0.2", ">=", true},
{"1.0.4", "1.0.2", "<=", false},
{"1.0.4", "1.0.6", "<=", true},
{"1.0.4", "1.0.4", "<=", true},
}
for _, each := range cases {
t.Run(each.ver1, func(t *testing.T) {
actual := CustomCompareVersions(each.ver1, each.ver2, each.operator)
assert.Equal(t, each.out, actual)
})
}
}