diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-12-18 16:50:34 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-12-18 20:05:22 +0100 |
commit | d20ca3700512d661247b44d953515b9455e57ed6 (patch) | |
tree | 2db72cf0bc6246e1c28106942af6b1e6f679e4e1 /hugolib | |
parent | 3e316155c5d4fbf166d38e997a41101b6aa501d5 (diff) |
tpl: Get rid of the custom template truth logic
Fixes #6615
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/template_test.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/hugolib/template_test.go b/hugolib/template_test.go index 4c41894ca..80a703801 100644 --- a/hugolib/template_test.go +++ b/hugolib/template_test.go @@ -337,6 +337,34 @@ Partial cached3: {{ partialCached "p1" "input3" $key2 }} `) } +// https://github.com/gohugoio/hugo/issues/6615 +func TestTemplateTruth(t *testing.T) { + b := newTestSitesBuilder(t) + b.WithTemplatesAdded("index.html", ` +{{ $p := index site.RegularPages 0 }} +{{ $zero := $p.ExpiryDate }} +{{ $notZero := time.Now }} + +if: Zero: {{ if $zero }}FAIL{{ else }}OK{{ end }} +if: Not Zero: {{ if $notZero }}OK{{ else }}Fail{{ end }} +not: Zero: {{ if not $zero }}OK{{ else }}FAIL{{ end }} +not: Not Zero: {{ if not $notZero }}FAIL{{ else }}OK{{ end }} + +with: Zero {{ with $zero }}FAIL{{ else }}OK{{ end }} + +`) + + b.Build(BuildCfg{}) + + b.AssertFileContent("public/index.html", ` +if: Zero: OK +if: Not Zero: OK +not: Zero: OK +not: Not Zero: OK +with: Zero OK +`) +} + func TestTemplateDependencies(t *testing.T) { b := newTestSitesBuilder(t).Running() |