mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
tpl: Sync go_templates for Go 1.18
Using Go tag go1.18 4aa1efed4853ea067d665a952eee77c52faac774 Updates #9677
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
// Tests for template execution, copied from text/template.
|
||||
|
||||
//go:build go1.13 && !windows
|
||||
// +build go1.13,!windows
|
||||
|
||||
package template
|
||||
@@ -53,7 +54,7 @@ type T struct {
|
||||
MSI map[string]int
|
||||
MSIone map[string]int // one element, for deterministic output
|
||||
MSIEmpty map[string]int
|
||||
MXI map[interface{}]int
|
||||
MXI map[any]int
|
||||
MII map[int]int
|
||||
MI32S map[int32]string
|
||||
MI64S map[int64]string
|
||||
@@ -63,11 +64,11 @@ type T struct {
|
||||
MUI8S map[uint8]string
|
||||
SMSI []map[string]int
|
||||
// Empty interfaces; used to see if we can dig inside one.
|
||||
Empty0 interface{} // nil
|
||||
Empty1 interface{}
|
||||
Empty2 interface{}
|
||||
Empty3 interface{}
|
||||
Empty4 interface{}
|
||||
Empty0 any // nil
|
||||
Empty1 any
|
||||
Empty2 any
|
||||
Empty3 any
|
||||
Empty4 any
|
||||
// Non-empty interfaces.
|
||||
NonEmptyInterface I
|
||||
NonEmptyInterfacePtS *I
|
||||
@@ -145,7 +146,7 @@ var tVal = &T{
|
||||
SB: []bool{true, false},
|
||||
MSI: map[string]int{"one": 1, "two": 2, "three": 3},
|
||||
MSIone: map[string]int{"one": 1},
|
||||
MXI: map[interface{}]int{"one": 1},
|
||||
MXI: map[any]int{"one": 1},
|
||||
MII: map[int]int{1: 1},
|
||||
MI32S: map[int32]string{1: "one", 2: "two"},
|
||||
MI64S: map[int64]string{2: "i642", 3: "i643"},
|
||||
@@ -216,7 +217,7 @@ func (t *T) Method2(a uint16, b string) string {
|
||||
return fmt.Sprintf("Method2: %d %s", a, b)
|
||||
}
|
||||
|
||||
func (t *T) Method3(v interface{}) string {
|
||||
func (t *T) Method3(v any) string {
|
||||
return fmt.Sprintf("Method3: %v", v)
|
||||
}
|
||||
|
||||
@@ -256,7 +257,7 @@ func (u *U) TrueFalse(b bool) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func typeOf(arg interface{}) string {
|
||||
func typeOf(arg any) string {
|
||||
return fmt.Sprintf("%T", arg)
|
||||
}
|
||||
|
||||
@@ -264,7 +265,7 @@ type execTest struct {
|
||||
name string
|
||||
input string
|
||||
output string
|
||||
data interface{}
|
||||
data any
|
||||
ok bool
|
||||
}
|
||||
|
||||
@@ -397,7 +398,7 @@ var execTests = []execTest{
|
||||
{".VariadicFuncInt", "{{call .VariadicFuncInt 33 `he` `llo`}}", "33=<he+llo>", tVal, true},
|
||||
{"if .BinaryFunc call", "{{ if .BinaryFunc}}{{call .BinaryFunc `1` `2`}}{{end}}", "[1=2]", tVal, true},
|
||||
{"if not .BinaryFunc call", "{{ if not .BinaryFunc}}{{call .BinaryFunc `1` `2`}}{{else}}No{{end}}", "No", tVal, true},
|
||||
{"Interface Call", `{{stringer .S}}`, "foozle", map[string]interface{}{"S": bytes.NewBufferString("foozle")}, true},
|
||||
{"Interface Call", `{{stringer .S}}`, "foozle", map[string]any{"S": bytes.NewBufferString("foozle")}, true},
|
||||
{".ErrFunc", "{{call .ErrFunc}}", "bla", tVal, true},
|
||||
{"call nil", "{{call nil}}", "", tVal, false},
|
||||
|
||||
@@ -571,6 +572,8 @@ var execTests = []execTest{
|
||||
{"range empty no else", "{{range .SIEmpty}}-{{.}}-{{end}}", "", tVal, true},
|
||||
{"range []int else", "{{range .SI}}-{{.}}-{{else}}EMPTY{{end}}", "-3--4--5-", tVal, true},
|
||||
{"range empty else", "{{range .SIEmpty}}-{{.}}-{{else}}EMPTY{{end}}", "EMPTY", tVal, true},
|
||||
{"range []int break else", "{{range .SI}}-{{.}}-{{break}}NOTREACHED{{else}}EMPTY{{end}}", "-3-", tVal, true},
|
||||
{"range []int continue else", "{{range .SI}}-{{.}}-{{continue}}NOTREACHED{{else}}EMPTY{{end}}", "-3--4--5-", tVal, true},
|
||||
{"range []bool", "{{range .SB}}-{{.}}-{{end}}", "-true--false-", tVal, true},
|
||||
{"range []int method", "{{range .SI | .MAdd .I}}-{{.}}-{{end}}", "-20--21--22-", tVal, true},
|
||||
{"range map", "{{range .MSI}}-{{.}}-{{end}}", "-1--3--2-", tVal, true},
|
||||
@@ -742,7 +745,7 @@ func add(args ...int) int {
|
||||
return sum
|
||||
}
|
||||
|
||||
func echo(arg interface{}) interface{} {
|
||||
func echo(arg any) any {
|
||||
return arg
|
||||
}
|
||||
|
||||
@@ -761,7 +764,7 @@ func stringer(s fmt.Stringer) string {
|
||||
return s.String()
|
||||
}
|
||||
|
||||
func mapOfThree() interface{} {
|
||||
func mapOfThree() any {
|
||||
return map[string]int{"three": 3}
|
||||
}
|
||||
|
||||
@@ -1440,7 +1443,7 @@ func TestBlock(t *testing.T) {
|
||||
func TestEvalFieldErrors(t *testing.T) {
|
||||
tests := []struct {
|
||||
name, src string
|
||||
value interface{}
|
||||
value any
|
||||
want string
|
||||
}{
|
||||
{
|
||||
@@ -1583,7 +1586,7 @@ func TestInterfaceValues(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
tmpl := Must(New("tmpl").Parse(tt.text))
|
||||
var buf bytes.Buffer
|
||||
err := tmpl.Execute(&buf, map[string]interface{}{
|
||||
err := tmpl.Execute(&buf, map[string]any{
|
||||
"PlusOne": func(n int) int {
|
||||
return n + 1
|
||||
},
|
||||
@@ -1612,7 +1615,7 @@ func TestInterfaceValues(t *testing.T) {
|
||||
|
||||
// Check that panics during calls are recovered and returned as errors.
|
||||
func TestExecutePanicDuringCall(t *testing.T) {
|
||||
funcs := map[string]interface{}{
|
||||
funcs := map[string]any{
|
||||
"doPanic": func() string {
|
||||
panic("custom panic string")
|
||||
},
|
||||
@@ -1620,7 +1623,7 @@ func TestExecutePanicDuringCall(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
data interface{}
|
||||
data any
|
||||
wantErr string
|
||||
}{
|
||||
{
|
||||
@@ -1724,8 +1727,6 @@ var v = "v";
|
||||
`
|
||||
|
||||
func TestEscapeRace(t *testing.T) {
|
||||
// t.Skip("this test currently fails with -race; see issue #39807")
|
||||
|
||||
tmpl := New("")
|
||||
_, err := tmpl.New("templ.html").Parse(raceText)
|
||||
if err != nil {
|
||||
@@ -1820,7 +1821,7 @@ func TestRecursiveExecuteViaMethod(t *testing.T) {
|
||||
func TestTemplateFuncsAfterClone(t *testing.T) {
|
||||
s := `{{ f . }}`
|
||||
want := "test"
|
||||
orig := New("orig").Funcs(map[string]interface{}{
|
||||
orig := New("orig").Funcs(map[string]any{
|
||||
"f": func(in string) string {
|
||||
return in
|
||||
},
|
||||
|
Reference in New Issue
Block a user