"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tpl/internal/go_templates/texttemplate/multi_test.go" between
hugo-0.80.0.tar.gz and hugo-0.81.0.tar.gz

About: Hugo is a static site generator that takes a source directory of Markdown files and templates and uses these as input to create a complete website (written in Go).

multi_test.go  (hugo-0.80.0):multi_test.go  (hugo-0.81.0)
skipping to change at line 15 skipping to change at line 15
// +build go1.13,!windows // +build go1.13,!windows
package template package template
// Tests for multiple-template parsing and execution. // Tests for multiple-template parsing and execution.
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate/parse" "github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate/parse"
"os"
"testing" "testing"
) )
const ( const (
noError = true noError = true
hasError = false hasError = false
) )
type multiParseTest struct { type multiParseTest struct {
name string name string
skipping to change at line 158 skipping to change at line 159
t.Error("expected error for bad pattern; got none") t.Error("expected error for bad pattern; got none")
} }
template := New("root") template := New("root")
_, err = template.ParseGlob("testdata/file*.tmpl") _, err = template.ParseGlob("testdata/file*.tmpl")
if err != nil { if err != nil {
t.Fatalf("error parsing files: %v", err) t.Fatalf("error parsing files: %v", err)
} }
testExecute(multiExecTests, template, t) testExecute(multiExecTests, template, t)
} }
func TestParseFS(t *testing.T) {
fs := os.DirFS("testdata")
{
_, err := ParseFS(fs, "DOES NOT EXIST")
if err == nil {
t.Error("expected error for non-existent file; got none")
}
}
{
template := New("root")
_, err := template.ParseFS(fs, "file1.tmpl", "file2.tmpl")
if err != nil {
t.Fatalf("error parsing files: %v", err)
}
testExecute(multiExecTests, template, t)
}
{
template := New("root")
_, err := template.ParseFS(fs, "file*.tmpl")
if err != nil {
t.Fatalf("error parsing files: %v", err)
}
testExecute(multiExecTests, template, t)
}
}
// In these tests, actual content (not just template definitions) comes from the parsed files. // In these tests, actual content (not just template definitions) comes from the parsed files.
var templateFileExecTests = []execTest{ var templateFileExecTests = []execTest{
{"test", `{{template "tmpl1.tmpl"}}{{template "tmpl2.tmpl"}}`, "template1 \n\ny\ntemplate2\n\nx\n", 0, true}, {"test", `{{template "tmpl1.tmpl"}}{{template "tmpl2.tmpl"}}`, "template1 \n\ny\ntemplate2\n\nx\n", 0, true},
} }
func TestParseFilesWithData(t *testing.T) { func TestParseFilesWithData(t *testing.T) {
template, err := New("root").ParseFiles("testdata/tmpl1.tmpl", "testdata/ tmpl2.tmpl") template, err := New("root").ParseFiles("testdata/tmpl1.tmpl", "testdata/ tmpl2.tmpl")
if err != nil { if err != nil {
t.Fatalf("error parsing files: %v", err) t.Fatalf("error parsing files: %v", err)
skipping to change at line 364 skipping to change at line 394
t.Fatalf("parsing test: %s", err) t.Fatalf("parsing test: %s", err)
} }
} }
func TestEmptyTemplate(t *testing.T) { func TestEmptyTemplate(t *testing.T) {
cases := []struct { cases := []struct {
defn []string defn []string
in string in string
want string want string
}{ }{
{[]string{"x", "y"}, "", "y"},
{[]string{""}, "once", ""}, {[]string{""}, "once", ""},
{[]string{"", ""}, "twice", ""}, {[]string{"", ""}, "twice", ""},
{[]string{"{{.}}", "{{.}}"}, "twice", "twice"}, {[]string{"{{.}}", "{{.}}"}, "twice", "twice"},
{[]string{"{{/* a comment */}}", "{{/* a comment */}}"}, "comment ", ""}, {[]string{"{{/* a comment */}}", "{{/* a comment */}}"}, "comment ", ""},
{[]string{"{{.}}", ""}, "twice", ""}, {[]string{"{{.}}", ""}, "twice", ""},
} }
for i, c := range cases { for i, c := range cases {
root := New("root") root := New("root")
 End of changes. 3 change blocks. 
0 lines changed or deleted 31 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)