mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-01 22:42:45 +02:00
tpl/collections: Add an integration test for collections.D
Also * improve the handling if invalid input * add a sanity check for number of elements asked for in D (1000000).
This commit is contained in:
@@ -298,3 +298,33 @@ All|{{ .Title }}|
|
||||
|
||||
b.AssertFileContent("public/index.html", "Len: 1|")
|
||||
}
|
||||
|
||||
func TestD(t *testing.T) {
|
||||
t.Parallel()
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
-- layouts/home.html --
|
||||
{{ $p := site.RegularPages }}
|
||||
5 random pages: {{ range collections.D 42 5 ($p | len) }}{{ with (index $p .) }}{{ .RelPermalink }}|{{ end }}{{ end }}$
|
||||
-- content/a.md --
|
||||
-- content/b.md --
|
||||
-- content/c.md --
|
||||
-- content/d.md --
|
||||
-- content/e.md --
|
||||
-- content/f.md --
|
||||
-- content/g.md --
|
||||
-- content/h.md --
|
||||
-- content/i.md --
|
||||
-- content/j.md --
|
||||
-- content/k.md --
|
||||
-- content/l.md --
|
||||
-- content/m.md --
|
||||
-- content/n.md --
|
||||
-- content/o.md --
|
||||
-- content/p.md --
|
||||
|
||||
`
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContentExact("public/index.html", "5 random pages: /b/|/g/|/j/|/k/|/l/|$")
|
||||
}
|
||||
|
Reference in New Issue
Block a user