test: add more sorting tests

This commit is contained in:
decentral1se 2021-08-09 15:17:01 +02:00
parent 19bcaca6e6
commit f81a7c03b9
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
1 changed files with 38 additions and 1 deletions

View File

@ -617,7 +617,7 @@ func TestIsCompatible(t *testing.T) {
}
}
func TestSort(t *testing.T) {
func TestSort1(t *testing.T) {
rawTags := []string{
"v1.4.8",
"v1.3.9",
@ -656,6 +656,43 @@ func TestSort(t *testing.T) {
}
}
func TestSort2(t *testing.T) {
rawTags := []string{
"10.0",
"10.6",
"10.2",
"10.1",
"10.5",
"5.5",
}
var tags []tagcmp.Tag
for _, rawTag := range rawTags {
tag, err := tagcmp.Parse(rawTag)
if err != nil {
t.Errorf("'%s' should have parsed but didn't: %s", tag, err)
}
tags = append(tags, tag)
}
sort.Sort(tagcmp.ByTag(tags))
expected := []string{
"5.5",
"10.0",
"10.1",
"10.2",
"10.5",
"10.6",
}
for idx, tag := range tags {
if tag.String() != expected[idx] {
t.Errorf("'%s' sorted out of order, saw '%s', expected '%s'", tag, tags, expected)
}
}
}
func TestString(t *testing.T) {
for _, tag := range supported {
p, err := tagcmp.Parse(tag)