mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
parent
6667c6d743
commit
7a97d3e6bc
2 changed files with 11 additions and 1 deletions
|
@ -326,7 +326,7 @@ func (ns *Namespace) Group(key interface{}, items interface{}) (interface{}, err
|
||||||
if tp.Kind() == reflect.Ptr {
|
if tp.Kind() == reflect.Ptr {
|
||||||
tp = tp.Elem()
|
tp = tp.Elem()
|
||||||
}
|
}
|
||||||
in := reflect.Zero(tp).Interface()
|
in := reflect.New(tp).Interface()
|
||||||
switch vv := in.(type) {
|
switch vv := in.(type) {
|
||||||
case collections.Grouper:
|
case collections.Grouper:
|
||||||
return vv.Group(key, items)
|
return vv.Group(key, items)
|
||||||
|
|
|
@ -85,6 +85,14 @@ func (g tstGrouper) Group(key interface{}, items interface{}) (interface{}, erro
|
||||||
return fmt.Sprintf("%v(%d)", key, ilen), nil
|
return fmt.Sprintf("%v(%d)", key, ilen), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type tstGrouper2 struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *tstGrouper2) Group(key interface{}, items interface{}) (interface{}, error) {
|
||||||
|
ilen := reflect.ValueOf(items).Len()
|
||||||
|
return fmt.Sprintf("%v(%d)", key, ilen), nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestGroup(t *testing.T) {
|
func TestGroup(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
@ -98,6 +106,8 @@ func TestGroup(t *testing.T) {
|
||||||
{"a", []*tstGrouper{&tstGrouper{}, &tstGrouper{}}, "a(2)"},
|
{"a", []*tstGrouper{&tstGrouper{}, &tstGrouper{}}, "a(2)"},
|
||||||
{"b", tstGroupers{&tstGrouper{}, &tstGrouper{}}, "b(2)"},
|
{"b", tstGroupers{&tstGrouper{}, &tstGrouper{}}, "b(2)"},
|
||||||
{"a", []tstGrouper{tstGrouper{}, tstGrouper{}}, "a(2)"},
|
{"a", []tstGrouper{tstGrouper{}, tstGrouper{}}, "a(2)"},
|
||||||
|
{"a", []*tstGrouper2{&tstGrouper2{}, &tstGrouper2{}}, "a(2)"},
|
||||||
|
{"b", []tstGrouper2{tstGrouper2{}, tstGrouper2{}}, "b(2)"},
|
||||||
{"a", []*tstGrouper{}, "a(0)"},
|
{"a", []*tstGrouper{}, "a(0)"},
|
||||||
{"a", []string{"a", "b"}, false},
|
{"a", []string{"a", "b"}, false},
|
||||||
{nil, []*tstGrouper{&tstGrouper{}, &tstGrouper{}}, false},
|
{nil, []*tstGrouper{&tstGrouper{}, &tstGrouper{}}, false},
|
||||||
|
|
Loading…
Reference in a new issue