From f81a7c03b97cd1397342b6abaf82ae2861561b65 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Mon, 9 Aug 2021 15:17:01 +0200 Subject: [PATCH] test: add more sorting tests --- tagcmp_test.go | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/tagcmp_test.go b/tagcmp_test.go index c3af536..42eec1d 100644 --- a/tagcmp_test.go +++ b/tagcmp_test.go @@ -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)