mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-22 21:42:50 +02:00
tpl/internal: Synch Go templates fork with Go 1.16dev
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate/parse"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -155,6 +156,35 @@ func TestParseGlob(t *testing.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.
|
||||
|
||||
var templateFileExecTests = []execTest{
|
||||
@@ -361,6 +391,7 @@ func TestEmptyTemplate(t *testing.T) {
|
||||
in string
|
||||
want string
|
||||
}{
|
||||
{[]string{"x", "y"}, "", "y"},
|
||||
{[]string{""}, "once", ""},
|
||||
{[]string{"", ""}, "twice", ""},
|
||||
{[]string{"{{.}}", "{{.}}"}, "twice", "twice"},
|
||||
|
Reference in New Issue
Block a user