4
4
5
5
// Tests for template execution, copied from text/template.
6
6
7
- //go:build !windows
8
- // +build !windows
7
+ //go:build go1.13 && !windows
8
+ // +build go1.13, !windows
9
9
10
10
package template
11
11
@@ -325,16 +325,12 @@ var execTests = []execTest{
325
325
{"$.U.V" , "{{$.U.V}}" , "v" , tVal , true },
326
326
{"declare in action" , "{{$x := $.U.V}}{{$x}}" , "v" , tVal , true },
327
327
{"simple assignment" , "{{$x := 2}}{{$x = 3}}{{$x}}" , "3" , tVal , true },
328
- {
329
- "nested assignment" ,
328
+ {"nested assignment" ,
330
329
"{{$x := 2}}{{if true}}{{$x = 3}}{{end}}{{$x}}" ,
331
- "3" , tVal , true ,
332
- },
333
- {
334
- "nested assignment changes the last declaration" ,
330
+ "3" , tVal , true },
331
+ {"nested assignment changes the last declaration" ,
335
332
"{{$x := 1}}{{if true}}{{$x := 2}}{{if true}}{{$x = 3}}{{end}}{{end}}{{$x}}" ,
336
- "1" , tVal , true ,
337
- },
333
+ "1" , tVal , true },
338
334
339
335
// Type with String method.
340
336
{"V{6666}.String()" , "-{{.V0}}-" , "-{6666}-" , tVal , true }, // NOTE: -<6666>- in text/template
@@ -381,21 +377,15 @@ var execTests = []execTest{
381
377
{".Method3(nil constant)" , "-{{.Method3 nil}}-" , "-Method3: <nil>-" , tVal , true },
382
378
{".Method3(nil value)" , "-{{.Method3 .MXI.unset}}-" , "-Method3: <nil>-" , tVal , true },
383
379
{"method on var" , "{{if $x := .}}-{{$x.Method2 .U16 $x.X}}{{end}}-" , "-Method2: 16 x-" , tVal , true },
384
- {
385
- "method on chained var" ,
380
+ {"method on chained var" ,
386
381
"{{range .MSIone}}{{if $.U.TrueFalse $.True}}{{$.U.TrueFalse $.True}}{{else}}WRONG{{end}}{{end}}" ,
387
- "true" , tVal , true ,
388
- },
389
- {
390
- "chained method" ,
382
+ "true" , tVal , true },
383
+ {"chained method" ,
391
384
"{{range .MSIone}}{{if $.GetU.TrueFalse $.True}}{{$.U.TrueFalse $.True}}{{else}}WRONG{{end}}{{end}}" ,
392
- "true" , tVal , true ,
393
- },
394
- {
395
- "chained method on variable" ,
385
+ "true" , tVal , true },
386
+ {"chained method on variable" ,
396
387
"{{with $x := .}}{{with .SI}}{{$.GetU.TrueFalse $.True}}{{end}}{{end}}" ,
397
- "true" , tVal , true ,
398
- },
388
+ "true" , tVal , true },
399
389
{".NilOKFunc not nil" , "{{call .NilOKFunc .PI}}" , "false" , tVal , true },
400
390
{".NilOKFunc nil" , "{{call .NilOKFunc nil}}" , "true" , tVal , true },
401
391
{"method on nil value from slice" , "-{{range .}}{{.Method1 1234}}{{end}}-" , "-1234-" , tSliceOfNil , true },
@@ -481,14 +471,10 @@ var execTests = []execTest{
481
471
{"printf lots" , `{{printf "%d %s %g %s" 127 "hello" 7-3i .Method0}}` , "127 hello (7-3i) M0" , tVal , true },
482
472
483
473
// HTML.
484
- {
485
- "html" , `{{html "<script>alert(\"XSS\");</script>"}}` ,
486
- "<script>alert("XSS");</script>" , nil , true ,
487
- },
488
- {
489
- "html pipeline" , `{{printf "<script>alert(\"XSS\");</script>" | html}}` ,
490
- "<script>alert("XSS");</script>" , nil , true ,
491
- },
474
+ {"html" , `{{html "<script>alert(\"XSS\");</script>"}}` ,
475
+ "<script>alert("XSS");</script>" , nil , true },
476
+ {"html pipeline" , `{{printf "<script>alert(\"XSS\");</script>" | html}}` ,
477
+ "<script>alert("XSS");</script>" , nil , true },
492
478
{"html" , `{{html .PS}}` , "a string" , tVal , true },
493
479
{"html typed nil" , `{{html .NIL}}` , "<nil>" , tVal , true },
494
480
{"html untyped nil" , `{{html .Empty0}}` , "<nil>" , tVal , true }, // NOTE: "<no value>" in text/template
@@ -854,7 +840,7 @@ var delimPairs = []string{
854
840
855
841
func TestDelims (t * testing.T ) {
856
842
const hello = "Hello, world"
857
- value : = struct { Str string }{hello }
843
+ var value = struct { Str string }{hello }
858
844
for i := 0 ; i < len (delimPairs ); i += 2 {
859
845
text := ".Str"
860
846
left := delimPairs [i + 0 ]
@@ -877,7 +863,7 @@ func TestDelims(t *testing.T) {
877
863
if err != nil {
878
864
t .Fatalf ("delim %q text %q parse err %s" , left , text , err )
879
865
}
880
- b : = new (strings.Builder )
866
+ var b = new (strings.Builder )
881
867
err = tmpl .Execute (b , value )
882
868
if err != nil {
883
869
t .Fatalf ("delim %q exec err %s" , left , err )
@@ -978,7 +964,7 @@ const treeTemplate = `
978
964
`
979
965
980
966
func TestTree (t * testing.T ) {
981
- tree : = & Tree {
967
+ var tree = & Tree {
982
968
1 ,
983
969
& Tree {
984
970
2 , & Tree {
@@ -1229,7 +1215,7 @@ var cmpTests = []cmpTest{
1229
1215
1230
1216
func TestComparison (t * testing.T ) {
1231
1217
b := new (strings.Builder )
1232
- cmpStruct : = struct {
1218
+ var cmpStruct = struct {
1233
1219
Uthree , Ufour uint
1234
1220
NegOne , Three int
1235
1221
Ptr , NilPtr * int
0 commit comments