summaryrefslogtreecommitdiffstats
path: root/hugolib/shortcode_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-01-10 01:36:59 +0100
committerGitHub <noreply@github.com>2017-01-10 01:36:59 +0100
commitd6000a208c7687ca3a3efd6961ac941ce325e199 (patch)
tree9644609a0d19894b46d065faec2cfe2aaeb410bd /hugolib/shortcode_test.go
parent4ea4359ac17a3b5304fb0d73773f99a07975ee1e (diff)
all: Refactor to nonglobal template handling
Updates #2701
Diffstat (limited to 'hugolib/shortcode_test.go')
-rw-r--r--hugolib/shortcode_test.go42
1 files changed, 23 insertions, 19 deletions
diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go
index 01cdd97ae..243705345 100644
--- a/hugolib/shortcode_test.go
+++ b/hugolib/shortcode_test.go
@@ -32,8 +32,13 @@ import (
)
// TODO(bep) remove
-func pageFromString(in, filename string) (*Page, error) {
- return pageTestSite.NewPageFrom(strings.NewReader(in), filename)
+func pageFromString(in, filename string, withTemplate ...func(templ tpl.Template) error) (*Page, error) {
+ s := pageTestSite
+ if len(withTemplate) > 0 {
+ // Have to create a new site
+ s = NewSiteDefaultLang(withTemplate...)
+ }
+ return s.NewPageFrom(strings.NewReader(in), filename)
}
func CheckShortCodeMatch(t *testing.T, input, expected string, withTemplate func(templ tpl.Template) error) {
@@ -83,10 +88,10 @@ title: "Title"
}
func TestShortcodeGoFuzzReports(t *testing.T) {
- tem := tpl.New(logger)
- tem.AddInternalShortcode("sc.html", `foo`)
- p, _ := pageFromString(simplePage, "simple.md")
+ p, _ := pageFromString(simplePage, "simple.md", func(templ tpl.Template) error {
+ return templ.AddInternalShortcode("sc.html", `foo`)
+ })
for i, this := range []struct {
data string
@@ -94,7 +99,7 @@ func TestShortcodeGoFuzzReports(t *testing.T) {
}{
{"{{</*/", true},
} {
- output, err := HandleShortcodes(this.data, p, tem)
+ output, err := HandleShortcodes(this.data, p)
if this.expectErr && err == nil {
t.Errorf("[%d] should have errored", i)
@@ -304,15 +309,13 @@ func TestHighlight(t *testing.T) {
viper.Set("pygmentsStyle", "bw")
viper.Set("pygmentsUseClasses", false)
- templ := tpl.New(logger)
-
code := `
{{< highlight java >}}
void do();
{{< /highlight >}}`
p, _ := pageFromString(simplePage, "simple.md")
- output, err := HandleShortcodes(code, p, templ)
+ output, err := HandleShortcodes(code, p)
if err != nil {
t.Fatal("Handle shortcode error", err)
@@ -379,16 +382,17 @@ func TestExtractShortcodes(t *testing.T) {
fmt.Sprintf("Hello %sworld%s. And that's it.", testScPlaceholderRegexp, testScPlaceholderRegexp), ""},
} {
- p, _ := pageFromString(simplePage, "simple.md")
- tem := tpl.New(logger)
- tem.AddInternalShortcode("tag.html", `tag`)
- tem.AddInternalShortcode("sc1.html", `sc1`)
- tem.AddInternalShortcode("sc2.html", `sc2`)
- tem.AddInternalShortcode("inner.html", `{{with .Inner }}{{ . }}{{ end }}`)
- tem.AddInternalShortcode("inner2.html", `{{.Inner}}`)
- tem.AddInternalShortcode("inner3.html", `{{.Inner}}`)
-
- content, shortCodes, err := extractShortcodes(this.input, p, tem)
+ p, _ := pageFromString(simplePage, "simple.md", func(templ tpl.Template) error {
+ templ.AddInternalShortcode("tag.html", `tag`)
+ templ.AddInternalShortcode("sc1.html", `sc1`)
+ templ.AddInternalShortcode("sc2.html", `sc2`)
+ templ.AddInternalShortcode("inner.html", `{{with .Inner }}{{ . }}{{ end }}`)
+ templ.AddInternalShortcode("inner2.html", `{{.Inner}}`)
+ templ.AddInternalShortcode("inner3.html", `{{.Inner}}`)
+ return nil
+ })
+
+ content, shortCodes, err := extractShortcodes(this.input, p)
if b, ok := this.expect.(bool); ok && !b {
if err == nil {