diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-03-16 09:04:30 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-03-16 10:36:46 +0100 |
commit | 42cc5f88b6e38d94e1a7d146d7f53210d94c0a35 (patch) | |
tree | 6862f77a13d9fc615d05bb356bccd7b62b41f1e8 /tpl/tplimpl/integration_test.go | |
parent | a6488e7bad883c71fb08655948d83574d7f703f9 (diff) |
tpl: Adjustments and an integration test for Go 1.18
Updates #9677
Diffstat (limited to 'tpl/tplimpl/integration_test.go')
-rw-r--r-- | tpl/tplimpl/integration_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tpl/tplimpl/integration_test.go b/tpl/tplimpl/integration_test.go index f71e28bc1..18cebc7d1 100644 --- a/tpl/tplimpl/integration_test.go +++ b/tpl/tplimpl/integration_test.go @@ -59,3 +59,56 @@ title: "P1" b.Assert(names, qt.DeepEquals, []string{"_default/single.json", "baseof.json", "partials/unusedpartial.html", "post/single.html", "shortcodes/unusedshortcode.html"}) b.Assert(unused[0].Filename(), qt.Equals, filepath.Join(b.Cfg.WorkingDir, "layouts/_default/single.json")) } + +// Verify that the new keywords in Go 1.18 is available. +func TestGo18Constructs(t *testing.T) { + t.Parallel() + + files := ` +-- config.toml -- +baseURL = 'http://example.com/' +disableKinds = ["section", "home", "rss", "taxonomy", "term", "rss"] +-- content/p1.md -- +--- +title: "P1" +--- +-- layouts/partials/counter.html -- +{{ if .Scratch.Get "counter" }}{{ .Scratch.Add "counter" 1 }}{{ else }}{{ .Scratch.Set "counter" 1 }}{{ end }}{{ return true }} +-- layouts/_default/single.html -- +{{/* Note no spaces in {{continue}} or {{break}}, see https://github.com/golang/go/issues/51670 */}} +continue:{{ range seq 5 }}{{ if eq . 2 }}{{continue}}{{ end }}{{ . }}{{ end }}:END: +break:{{ range seq 5 }}{{ if eq . 2 }}{{break}}{{ end }}{{ . }}{{ end }}:END: + +counter1: {{ partial "counter.html" . }}/{{ .Scratch.Get "counter" }} +and1: {{ if (and false (partial "counter.html" .)) }}true{{ else }}false{{ end }} +or1: {{ if (or true (partial "counter.html" .)) }}true{{ else }}false{{ end }} +and2: {{ if (and true (partial "counter.html" .)) }}true{{ else }}false{{ end }} +or2: {{ if (or false (partial "counter.html" .)) }}true{{ else }}false{{ end }} + + +counter2: {{ .Scratch.Get "counter" }} + + + ` + + b := hugolib.NewIntegrationTestBuilder( + hugolib.IntegrationTestConfig{ + T: t, + TxtarString: files, + NeedsOsFS: true, + }, + ) + b.Build() + + b.AssertFileContent("public/p1/index.html", ` +continue:1345:END: +break:1:END: +counter1: true/1 +and1: false +or1: true +and2: true +or2: true +counter2: 3 +`) + +} |