template_funcs_test.go - hugo - [fork] hugo port for 9front
HTML git clone https://git.drkhsh.at/hugo.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
template_funcs_test.go (2298B)
---
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 -- config.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.NewIntegrationTestBuilder(
50 hugolib.IntegrationTestConfig{
51 T: t,
52 TxtarString: files,
53 NeedsOsFS: true,
54 },
55 ).Build()
56
57 d := b.H.Sites[0].Deps
58
59 var (
60 templates []string
61 expected []string
62 )
63
64 for _, nsf := range internal.TemplateFuncsNamespaceRegistry {
65 ns := nsf(d)
66 for _, mm := range ns.MethodMappings {
67 for _, example := range mm.Examples {
68 // These will fail the build, so skip.
69 if strings.Contains(example[0], "errorf") ||
70 strings.Contains(example[0], "transform.XMLEscape") ||
71 strings.Contains(example[0], "math.Rand") {
72 continue
73 }
74 templates = append(templates, example[0])
75 expected = append(expected, example[1])
76 }
77 }
78 }
79
80 files += fmt.Sprintf("-- layouts/_default/single.html --\n%s\n", strings.Join(templates, "\n"))
81 b = hugolib.NewIntegrationTestBuilder(
82 hugolib.IntegrationTestConfig{
83 T: t,
84 TxtarString: files,
85 NeedsOsFS: true,
86 },
87 ).Build()
88
89 b.AssertFileContent("public/blog/hugo-rocks/index.html", expected...)
90 }