summaryrefslogtreecommitdiff
path: root/libgo/go/text/template/multi_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/text/template/multi_test.go')
-rw-r--r--libgo/go/text/template/multi_test.go37
1 files changed, 35 insertions, 2 deletions
diff --git a/libgo/go/text/template/multi_test.go b/libgo/go/text/template/multi_test.go
index 8142f008fdf..5d8c08f06f1 100644
--- a/libgo/go/text/template/multi_test.go
+++ b/libgo/go/text/template/multi_test.go
@@ -363,7 +363,7 @@ func TestEmptyTemplate(t *testing.T) {
{[]string{"{{.}}", ""}, "twice", ""},
}
- for _, c := range cases {
+ for i, c := range cases {
root := New("root")
var (
@@ -378,10 +378,43 @@ func TestEmptyTemplate(t *testing.T) {
}
buf := &bytes.Buffer{}
if err := m.Execute(buf, c.in); err != nil {
- t.Fatal(err)
+ t.Error(i, err)
+ continue
}
if buf.String() != c.want {
t.Errorf("expected string %q: got %q", c.want, buf.String())
}
}
}
+
+// Issue 19249 was a regression in 1.8 caused by the handling of empty
+// templates added in that release, which got different answers depending
+// on the order templates appeared in the internal map.
+func TestIssue19294(t *testing.T) {
+ // The empty block in "xhtml" should be replaced during execution
+ // by the contents of "stylesheet", but if the internal map associating
+ // names with templates is built in the wrong order, the empty block
+ // looks non-empty and this doesn't happen.
+ var inlined = map[string]string{
+ "stylesheet": `{{define "stylesheet"}}stylesheet{{end}}`,
+ "xhtml": `{{block "stylesheet" .}}{{end}}`,
+ }
+ all := []string{"stylesheet", "xhtml"}
+ for i := 0; i < 100; i++ {
+ res, err := New("title.xhtml").Parse(`{{template "xhtml" .}}`)
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, name := range all {
+ _, err := res.New(name).Parse(inlined[name])
+ if err != nil {
+ t.Fatal(err)
+ }
+ }
+ var buf bytes.Buffer
+ res.Execute(&buf, 0)
+ if buf.String() != "stylesheet" {
+ t.Fatalf("iteration %d: got %q; expected %q", i, buf.String(), "stylesheet")
+ }
+ }
+}