Adjust a test

This commit is contained in:
Bjørn Erik Pedersen 2022-09-27 11:41:15 +02:00
parent 51010a69bc
commit cac773aeff
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F

View file

@ -476,58 +476,79 @@ C-%s`
func TestShortcodeParentResourcesOnRebuild(t *testing.T) { func TestShortcodeParentResourcesOnRebuild(t *testing.T) {
t.Parallel() t.Parallel()
b := newTestSitesBuilder(t).Running().WithSimpleConfigFile() files := `
b.WithTemplatesAdded( -- config.toml --
"index.html", ` baseURL = 'http://example.com/'
{{ $b := .Site.GetPage "b1" }} -- content/b1/index.md --
b1 Content: {{ $b.Content }} ---
{{$p := $b.Resources.GetMatch "p1*" }} title: MyPage
Content: {{ $p.Content }} ---
{{ $article := .Site.GetPage "blog/article" }} CONTENT
Article Content: {{ $article.Content }} -- content/b1/data.txt --
`, b1 data
"shortcodes/c.html", ` -- content/b1/p1.md --
{{ range .Page.Parent.Resources }}
* Parent resource: {{ .Name }}: {{ .RelPermalink }}
{{ end }}
`)
pageContent := `
--- ---
title: MyPage title: MyPage
--- ---
SHORTCODE: {{< c >}} SHORTCODE: {{< c >}}
-- content/blog/_index.md --
---
title: MyPage
---
` SHORTCODE: {{< c >}}
-- content/blog/article.md --
---
title: MyPage
---
b.WithContent("b1/index.md", pageContent, SHORTCODE: {{< c >}}
"b1/logo.png", "PNG logo", -- content/blog/data-article.txt --
"b1/p1.md", pageContent, data article
"blog/_index.md", pageContent, -- layouts/index.html --
"blog/logo-article.png", "PNG logo", {{ $b := .Site.GetPage "b1" }}
"blog/article.md", pageContent, b1 Content: {{ $b.Path }}|{{ $b.Content }}|
) {{$p := $b.Resources.GetMatch "p1*" }}
p1: {{ $p.Path }}|{{ $p.Content }}|
{{ $article := .Site.GetPage "blog/article" }}
Article Content: {{ $article.Content }}
-- layouts/shortcodes/c.html --
{{ range $i, $e := .Page.Parent.Resources }}{{ $i }}:{{ $.Page.Parent.Path }}: Parent resource: {{ .Name }}: {{ .RelPermalink }}|{{ end }}`
b.Build(BuildCfg{}) c := qt.New(t)
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: c,
TxtarString: files,
Running: true,
},
).Build()
assert := func(matchers ...string) { assert := func(matchers ...string) {
allMatchers := append(matchers, "Parent resource: logo.png: /b1/logo.png",
"Article Content: <p>SHORTCODE: \n\n* Parent resource: logo-article.png: /blog/logo-article.png",
)
b.AssertFileContent("public/index.html", b.AssertFileContent("public/index.html",
allMatchers..., `
b1 Content: b1/index.md|
p1: b1/p1.md|<p>SHORTCODE: 0:b1/index.md: Parent resource: p1.md: |1:b1/index.md: Parent resource: data.txt: /b1/data.txt|</p>
Article Content: <p>SHORTCODE: 0:blog/_index.md: Parent resource: data-article.txt: /blog/data-article.txt|</p>
`,
) )
for _, m := range matchers {
b.AssertFileContent("public/index.html", m)
}
} }
assert() assert()
b.EditFiles("content/b1/index.md", pageContent+" Edit.") b.EditFileReplace("content/b1/index.md", func(s string) string { return strings.ReplaceAll(s, "CONTENT", "Content Edit") })
b.Build(BuildCfg{}) b.Build()
assert("Edit.") assert("Content Edit")
} }
func TestShortcodePreserveOrder(t *testing.T) { func TestShortcodePreserveOrder(t *testing.T) {