hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

template_funcs_test.go (2074B)

    1 // Copyright 2019 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 	"strings"
   19 	"testing"
   20 
   21 	"github.com/gohugoio/hugo/hugolib"
   22 
   23 	"github.com/gohugoio/hugo/tpl/internal"
   24 )
   25 
   26 func TestTemplateFuncsExamples(t *testing.T) {
   27 	t.Parallel()
   28 
   29 	files := `
   30 -- config.toml --
   31 disableKinds=["home", "section", "taxonomy", "term", "sitemap", "robotsTXT"]
   32 ignoreErrors = ["my-err-id"]
   33 [outputs]
   34 home=["HTML"]
   35 -- layouts/partials/header.html --
   36 <title>Hugo Rocks!</title>
   37 -- files/README.txt --
   38 Hugo Rocks!
   39 -- content/blog/hugo-rocks.md --
   40 --- 
   41 title: "**BatMan**"
   42 ---
   43 `
   44 
   45 	b := hugolib.NewIntegrationTestBuilder(
   46 		hugolib.IntegrationTestConfig{
   47 			T:           t,
   48 			TxtarString: files,
   49 			NeedsOsFS:   true,
   50 		},
   51 	).Build()
   52 
   53 	d := b.H.Sites[0].Deps
   54 
   55 	var (
   56 		templates []string
   57 		expected  []string
   58 	)
   59 
   60 	for _, nsf := range internal.TemplateFuncsNamespaceRegistry {
   61 		ns := nsf(d)
   62 		for _, mm := range ns.MethodMappings {
   63 			for _, example := range mm.Examples {
   64 				if strings.Contains(example[0], "errorf") {
   65 					// This will fail the build, so skip for now.
   66 					continue
   67 				}
   68 				templates = append(templates, example[0])
   69 				expected = append(expected, example[1])
   70 			}
   71 		}
   72 	}
   73 
   74 	files += fmt.Sprintf("-- layouts/_default/single.html --\n%s\n", strings.Join(templates, "\n"))
   75 	b = hugolib.NewIntegrationTestBuilder(
   76 		hugolib.IntegrationTestConfig{
   77 			T:           t,
   78 			TxtarString: files,
   79 			NeedsOsFS:   true,
   80 		},
   81 	).Build()
   82 
   83 	b.AssertFileContent("public/blog/hugo-rocks/index.html", expected...)
   84 }