tpl: Sync go_templates for Go 1.18

Using Go tag go1.18 4aa1efed4853ea067d665a952eee77c52faac774

Updates #9677
This commit is contained in:
Bjørn Erik Pedersen
2022-03-16 08:48:16 +01:00
parent 4d6d1d08da
commit 65a78cae1e
48 changed files with 697 additions and 223 deletions

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.13 && !windows
// +build go1.13,!windows
package template
@@ -39,8 +40,8 @@ func TestEscape(t *testing.T) {
A, E []string
B, M json.Marshaler
N int
U interface{} // untyped nil
Z *int // typed nil
U any // untyped nil
Z *int // typed nil
W htmltemplate.HTML
}{
F: false,
@@ -862,7 +863,7 @@ func TestEscapeSet(t *testing.T) {
// pred is a template function that returns the predecessor of a
// natural number for testing recursive templates.
fns := FuncMap{"pred": func(a ...interface{}) (interface{}, error) {
fns := FuncMap{"pred": func(a ...any) (any, error) {
if len(a) == 1 {
if i, _ := a[0].(int); i > 0 {
return i - 1, nil
@@ -924,6 +925,22 @@ func TestErrors(t *testing.T) {
"<a href='/foo?{{range .Items}}&{{.K}}={{.V}}{{end}}'>",
"",
},
{
"{{range .Items}}<a{{if .X}}{{end}}>{{end}}",
"",
},
{
"{{range .Items}}<a{{if .X}}{{end}}>{{continue}}{{end}}",
"",
},
{
"{{range .Items}}<a{{if .X}}{{end}}>{{break}}{{end}}",
"",
},
{
"{{range .Items}}<a{{if .X}}{{end}}>{{if .X}}{{break}}{{end}}{{end}}",
"",
},
// Error cases.
{
"{{if .Cond}}<a{{end}}",
@@ -959,6 +976,14 @@ func TestErrors(t *testing.T) {
"\n{{range .Items}} x='<a{{end}}",
"z:2:8: on range loop re-entry: {{range}} branches",
},
{
"{{range .Items}}<a{{if .X}}{{break}}{{end}}>{{end}}",
"z:1:29: at range loop break: {{range}} branches end in different contexts",
},
{
"{{range .Items}}<a{{if .X}}{{continue}}{{end}}>{{end}}",
"z:1:29: at range loop continue: {{range}} branches end in different contexts",
},
{
"<a b=1 c={{.H}}",
"z: ends in a non-text context: {stateAttr delimSpaceOrTagEnd",
@@ -1768,7 +1793,7 @@ func TestEscapeSetErrorsNotIgnorable(t *testing.T) {
}
func TestRedundantFuncs(t *testing.T) {
inputs := []interface{}{
inputs := []any{
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f" +
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" +
` !"#$%&'()*+,-./` +
@@ -1788,9 +1813,9 @@ func TestRedundantFuncs(t *testing.T) {
}
for n0, m := range redundantFuncs {
f0 := funcMap[n0].(func(...interface{}) string)
f0 := funcMap[n0].(func(...any) string)
for n1 := range m {
f1 := funcMap[n1].(func(...interface{}) string)
f1 := funcMap[n1].(func(...any) string)
for _, input := range inputs {
want := f0(input)
if got := f1(want); want != got {