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

@@ -16,9 +16,12 @@ package collections
import (
"fmt"
"reflect"
"strings"
"testing"
"time"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/deps"
)
@@ -162,6 +165,37 @@ func TestWhere(t *testing.T) {
{1: "a", 2: "m"},
},
},
{
seq: []maps.Params{
{"a": "a1", "b": "b1"}, {"a": "a2", "b": "b2"},
},
key: "B", match: "b2",
expect: []maps.Params{
maps.Params{"a": "a2", "b": "b2"},
},
},
{
seq: []maps.Params{
maps.Params{
"a": map[string]interface{}{
"b": "b1",
},
},
maps.Params{
"a": map[string]interface{}{
"b": "b2",
},
},
},
key: "A.B", match: "b2",
expect: []maps.Params{
maps.Params{
"a": map[string]interface{}{
"b": "b2",
},
},
},
},
{
seq: []*TstX{
{A: "a", B: "b"}, {A: "c", B: "d"}, {A: "e", B: "f"},
@@ -557,11 +591,24 @@ func TestWhere(t *testing.T) {
"zap": []interface{}{map[interface{}]interface{}{"a": 5, "b": 6}},
},
},
{
seq: map[string]interface{}{
"foo": []interface{}{maps.Params{"a": 1, "b": 2}},
"bar": []interface{}{maps.Params{"a": 3, "b": 4}},
"zap": []interface{}{maps.Params{"a": 5, "b": 6}},
},
key: "B", op: ">", match: 3,
expect: map[string]interface{}{
"bar": []interface{}{maps.Params{"a": 3, "b": 4}},
"zap": []interface{}{maps.Params{"a": 5, "b": 6}},
},
},
} {
testVariants := createTestVariants(test)
for j, test := range testVariants {
name := fmt.Sprintf("[%d/%d] %T %s %s", i, j, test.seq, test.op, test.key)
name := fmt.Sprintf("%d/%d %T %s %s", i, j, test.seq, test.op, test.key)
name = strings.ReplaceAll(name, "[]", "slice-of-")
t.Run(name, func(t *testing.T) {
var results interface{}
var err error