Fix Params case handling in the index, sort and where func

This means that you can now do:

```
{{ range where .Site.Pages "Params.MYPARAM" "foo" }}
```
This commit is contained in:
Bjørn Erik Pedersen
2019-11-21 21:59:38 +01:00
parent cd07e6d57b
commit a3fe5e5e35
33 changed files with 317 additions and 155 deletions

View File

@@ -18,6 +18,8 @@ import (
"reflect"
"testing"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/deps"
)
@@ -100,6 +102,20 @@ func TestSort(t *testing.T) {
"asc",
[]*TstX{{A: "a", B: "b"}, {A: "c", B: "d"}, {A: "e", B: "f"}, {A: "g", B: "h"}, {A: "i", B: "j"}},
},
// Lower case Params, slice
{
[]TstParams{{params: maps.Params{"color": "indigo"}}, {params: maps.Params{"color": "blue"}}, {params: maps.Params{"color": "green"}}},
".Params.COLOR",
"asc",
[]TstParams{{params: maps.Params{"color": "blue"}}, {params: maps.Params{"color": "green"}}, {params: maps.Params{"color": "indigo"}}},
},
// Lower case Params, map
{
map[string]TstParams{"1": {params: maps.Params{"color": "indigo"}}, "2": {params: maps.Params{"color": "blue"}}, "3": {params: maps.Params{"color": "green"}}},
".Params.CoLoR",
"asc",
[]TstParams{{params: maps.Params{"color": "blue"}}, {params: maps.Params{"color": "green"}}, {params: maps.Params{"color": "indigo"}}},
},
// test map sorting by struct's method
{
map[string]TstX{"1": {A: "i", B: "j"}, "2": {A: "e", B: "f"}, "3": {A: "c", B: "d"}, "4": {A: "g", B: "h"}, "5": {A: "a", B: "b"}},