PR c++/86342 - -Wdeprecated-copy and system headers.
[official-gcc.git] / libgo / go / html / template / transition_test.go
blob412a4c71b752dad247ad241f026cd46d4ab53f69
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.
5 package template
7 import (
8 "bytes"
9 "strings"
10 "testing"
13 func TestFindEndTag(t *testing.T) {
14 tests := []struct {
15 s, tag string
16 want int
18 {"", "tag", -1},
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) {
44 r := struct {
45 Name, Gift string
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
52 var buf bytes.Buffer
53 for i := 0; i < b.N; i++ {
54 tmpl := Must(New("foo").Parse(html))
55 if err := tmpl.Execute(&buf, r); err != nil {
56 b.Fatal(err)
58 buf.Reset()