mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
hugolib: Add some integration tests for in/uniq using Pages
See #5875 See #5852
This commit is contained in:
parent
7fbfedf013
commit
6c80acbd5e
1 changed files with 36 additions and 0 deletions
|
@ -118,6 +118,42 @@ tags_weight: %d
|
|||
"unionWeightedPages: page.WeightedPages 6")
|
||||
}
|
||||
|
||||
func TestCollectionsFuncs(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
|
||||
pageContent := `
|
||||
---
|
||||
title: "Page"
|
||||
tags: ["blue", "green"]
|
||||
tags_weight: %d
|
||||
---
|
||||
|
||||
`
|
||||
b := newTestSitesBuilder(t)
|
||||
b.WithSimpleConfigFile().
|
||||
WithContent("page1.md", fmt.Sprintf(pageContent, 10), "page2.md", fmt.Sprintf(pageContent, 20),
|
||||
"page3.md", fmt.Sprintf(pageContent, 30)).
|
||||
WithTemplatesAdded("index.html", `
|
||||
{{ $uniqPages := first 2 .Site.RegularPages | append .Site.RegularPages | uniq }}
|
||||
{{ $inTrue := in .Site.RegularPages (index .Site.RegularPages 1) }}
|
||||
{{ $inFalse := in .Site.RegularPages (.Site.Home) }}
|
||||
|
||||
{{ printf "uniqPages: %T %d" $uniqPages (len $uniqPages) }}
|
||||
{{ printf "inTrue: %t" $inTrue }}
|
||||
{{ printf "inFalse: %t" $inFalse }}
|
||||
`)
|
||||
b.CreateSites().Build(BuildCfg{})
|
||||
|
||||
assert.Equal(1, len(b.H.Sites))
|
||||
require.Len(t, b.H.Sites[0].RegularPages(), 3)
|
||||
|
||||
b.AssertFileContent("public/index.html",
|
||||
"uniqPages: page.Pages 3",
|
||||
"inTrue: true",
|
||||
"inFalse: false",
|
||||
)
|
||||
}
|
||||
|
||||
func TestAppendFunc(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
|
||||
|
|
Loading…
Reference in a new issue