mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-19 21:21:39 +02:00
tpl/collections: Fix slice type handling in sort
The `sort` template func was producing a `[]page.Page` which did not work in `.Paginate`. Fixes #6023
This commit is contained in:
@@ -53,3 +53,24 @@ func TestProbablyEq(t *testing.T) {
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func TestToPages(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
|
||||
p1, p2 := &testPage{title: "p1"}, &testPage{title: "p2"}
|
||||
pages12 := Pages{p1, p2}
|
||||
|
||||
mustToPages := func(in interface{}) Pages {
|
||||
p, err := ToPages(in)
|
||||
assert.NoError(err)
|
||||
return p
|
||||
}
|
||||
|
||||
assert.Equal(Pages{}, mustToPages(nil))
|
||||
assert.Equal(pages12, mustToPages(pages12))
|
||||
assert.Equal(pages12, mustToPages([]Page{p1, p2}))
|
||||
assert.Equal(pages12, mustToPages([]interface{}{p1, p2}))
|
||||
|
||||
_, err := ToPages("not a page")
|
||||
assert.Error(err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user