summaryrefslogtreecommitdiffstats
path: root/tpl/collections
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-01 10:19:19 +0200
committerGitHub <noreply@github.com>2019-08-01 10:19:19 +0200
commit53077b0da54906feee64a03612e5186043e17341 (patch)
treec99b1456485cfc2ed41f3a1b732e44c4acbc3061 /tpl/collections
parenta4f96a9d8c2d2da40796757f7e9a3023157abd2f (diff)
Merge pull request #6149 from bep/sort-caseinsensitive
Implement lexicographically string sorting
Diffstat (limited to 'tpl/collections')
-rw-r--r--tpl/collections/sort.go8
-rw-r--r--tpl/collections/sort_test.go1
2 files changed, 5 insertions, 4 deletions
diff --git a/tpl/collections/sort.go b/tpl/collections/sort.go
index 1ab4409b6..9639fe1d0 100644
--- a/tpl/collections/sort.go
+++ b/tpl/collections/sort.go
@@ -23,7 +23,7 @@ import (
"github.com/spf13/cast"
)
-var comp = compare.New()
+var sortComp = compare.New(true)
// Sort returns a sorted sequence.
func (ns *Namespace) Sort(seq interface{}, args ...interface{}) (interface{}, error) {
@@ -133,15 +133,15 @@ func (p pairList) Less(i, j int) bool {
if iv.IsValid() {
if jv.IsValid() {
// can only call Interface() on valid reflect Values
- return comp.Lt(iv.Interface(), jv.Interface())
+ return sortComp.Lt(iv.Interface(), jv.Interface())
}
// if j is invalid, test i against i's zero value
- return comp.Lt(iv.Interface(), reflect.Zero(iv.Type()))
+ return sortComp.Lt(iv.Interface(), reflect.Zero(iv.Type()))
}
if jv.IsValid() {
// if i is invalid, test j against j's zero value
- return comp.Lt(reflect.Zero(jv.Type()), jv.Interface())
+ return sortComp.Lt(reflect.Zero(jv.Type()), jv.Interface())
}
return false
diff --git a/tpl/collections/sort_test.go b/tpl/collections/sort_test.go
index f5f291f0b..612a928cb 100644
--- a/tpl/collections/sort_test.go
+++ b/tpl/collections/sort_test.go
@@ -45,6 +45,7 @@ func TestSort(t *testing.T) {
}{
{[]string{"class1", "class2", "class3"}, nil, "asc", []string{"class1", "class2", "class3"}},
{[]string{"class3", "class1", "class2"}, nil, "asc", []string{"class1", "class2", "class3"}},
+ {[]string{"CLASS3", "class1", "class2"}, nil, "asc", []string{"class1", "class2", "CLASS3"}},
// Issue 6023
{stringsSlice{"class3", "class1", "class2"}, nil, "asc", stringsSlice{"class1", "class2", "class3"}},