1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 func TestFindEndTag(t
*testing
.T
) {
19 {"hello </textarea> hello", "textarea", 6},
20 {"hello </TEXTarea> hello", "textarea", 6},
21 {"hello </textAREA>", "textarea", 6},
22 {"hello </textarea", "textareax", -1},
23 {"hello </textarea>", "tag", -1},
24 {"hello tag </textarea", "tag", -1},
25 {"hello </tag> </other> </textarea> <other>", "textarea", 22},
26 {"</textarea> <other>", "textarea", 0},
27 {"<div> </div> </TEXTAREA>", "textarea", 13},
28 {"<div> </div> </TEXTAREA\t>", "textarea", 13},
29 {"<div> </div> </TEXTAREA >", "textarea", 13},
30 {"<div> </div> </TEXTAREAfoo", "textarea", -1},
31 {"</TEXTAREAfoo </textarea>", "textarea", 14},
32 {"<</script >", "script", 1},
33 {"</script>", "textarea", -1},
35 for _
, test
:= range tests
{
36 if got
:= indexTagEnd([]byte(test
.s
), []byte(test
.tag
)); test
.want
!= got
{
37 t
.Errorf("%q/%q: want\n\t%d\nbut got\n\t%d", test
.s
, test
.tag
, test
.want
, got
)
42 func BenchmarkTemplateSpecialTags(b
*testing
.B
) {
46 }{"Aunt Mildred", "bone china tea set"}
48 h1
:= "<textarea> Hello Hello Hello </textarea> "
49 h2
:= "<textarea> <p> Dear {{.Name}},\n{{with .Gift}}Thank you for the lovely {{.}}. {{end}}\nBest wishes. </p>\n</textarea>"
50 html
:= strings
.Repeat(h1
, 100) + h2
+ strings
.Repeat(h1
, 100) + h2
53 for i
:= 0; i
< b
.N
; i
++ {
54 tmpl
:= Must(New("foo").Parse(html
))
55 if err
:= tmpl
.Execute(&buf
, r
); err
!= nil {