Debian Codegraph @

tpl/tplimpl/template_funcs_test.go

raw
1 // Copyright 2025 The Hugo Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package tplimpl_test
15
16 import (
17 "fmt"
18 "runtime"
19 "strings"
20 "testing"
21
22 "github.com/gohugoio/hugo/hugolib"
23
24 "github.com/gohugoio/hugo/tpl/internal"
25 )
26
27 func TestTemplateFuncsExamples(t *testing.T) {
28 if runtime.GOARCH == "s390x" {
29 t.Skip("Skip on s390x, see https://github.com/gohugoio/hugo/issues/13204")
30 }
31 t.Parallel()
32
33 files := `
34 -- hugo.toml --
35 disableKinds=["home", "section", "taxonomy", "term", "sitemap", "robotsTXT"]
36 ignoreErrors = ["my-err-id"]
37 [outputs]
38 home=["HTML"]
39 -- layouts/_partials/header.html --
40 <title>Hugo Rocks!</title>
41 -- files/README.txt --
42 Hugo Rocks!
43 -- content/blog/hugo-rocks.md --
44 ---
45 title: "**BatMan**"
46 ---
47 `
48
49 b := hugolib.Test(t, files, hugolib.TestOptOsFs())
50
51 d := b.H.Sites[0].Deps
52
53 var (
54 templates []string
55 expected []string
56 )
57
58 for _, nsf := range internal.TemplateFuncsNamespaceRegistry {
59 ns := nsf(d)
60 for _, mm := range ns.MethodMappings {
61 for _, example := range mm.Examples {
62 // These will fail the build, so skip.
63 if strings.Contains(example[0], "errorf") ||
64 strings.Contains(example[0], "transform.XMLEscape") ||
65 strings.Contains(example[0], "math.Rand") {
66 continue
67 }
68 templates = append(templates, example[0])
69 expected = append(expected, example[1])
70 }
71 }
72 }
73
74 files += fmt.Sprintf("-- layouts/single.html --\n%s\n", strings.Join(templates, "\n"))
75 b = hugolib.Test(t, files, hugolib.TestOptOsFs())
76
77 b.AssertFileContent("public/blog/hugo-rocks/index.html", expected...)
78 }