Skip to content

Commit

Permalink
html/template: clone is implemented elsewhere, so delete this impleme…
Browse files Browse the repository at this point in the history
…ntation

R=golang-dev, nigeltao
CC=golang-dev
https://golang.org/cl/5676064
  • Loading branch information
robpike committed Feb 16, 2012
1 parent 21be71a commit dfef0c2
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 173 deletions.
90 changes: 0 additions & 90 deletions src/pkg/html/template/clone.go

This file was deleted.

82 changes: 0 additions & 82 deletions src/pkg/html/template/clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,88 +10,6 @@ import (
"text/template/parse"
)

func TestCloneList(t *testing.T) {
tests := []struct {
input, want, wantClone string
}{
{
`Hello, {{if true}}{{"<World>"}}{{end}}!`,
"Hello, <World>!",
"Hello, &lt;World&gt;!",
},
{
`Hello, {{if false}}{{.X}}{{else}}{{"<World>"}}{{end}}!`,
"Hello, <World>!",
"Hello, &lt;World&gt;!",
},
{
`Hello, {{with "<World>"}}{{.}}{{end}}!`,
"Hello, <World>!",
"Hello, &lt;World&gt;!",
},
{
`{{range .}}<p>{{.}}</p>{{end}}`,
"<p>foo</p><p><bar></p><p>baz</p>",
"<p>foo</p><p>&lt;bar&gt;</p><p>baz</p>",
},
{
`Hello, {{"<World>" | html}}!`,
"Hello, &lt;World&gt;!",
"Hello, &lt;World&gt;!",
},
{
`Hello{{if 1}}, World{{else}}{{template "d"}}{{end}}!`,
"Hello, World!",
"Hello, World!",
},
}

for _, test := range tests {
s, err := New("s").Parse(test.input)
if err != nil {
t.Errorf("input=%q: unexpected parse error %v", test.input, err)
}

d, _ := New("d").Parse(test.input)
// Hack: just replace the root of the tree.
d.text.Root = cloneList(s.text.Root)

if want, got := s.text.Root.String(), d.text.Root.String(); want != got {
t.Errorf("want %q, got %q", want, got)
}

err = escapeTemplates(d, "d")
if err != nil {
t.Errorf("%q: failed to escape: %s", test.input, err)
continue
}

if want, got := "s", s.Name(); want != got {
t.Errorf("want %q, got %q", want, got)
continue
}
if want, got := "d", d.Name(); want != got {
t.Errorf("want %q, got %q", want, got)
continue
}

data := []string{"foo", "<bar>", "baz"}

var b bytes.Buffer
d.Execute(&b, data)
if got := b.String(); got != test.wantClone {
t.Errorf("input=%q: want %q, got %q", test.input, test.wantClone, got)
}

// Make sure escaping d did not affect s.
b.Reset()
s.text.Execute(&b, data)
if got := b.String(); got != test.want {
t.Errorf("input=%q: want %q, got %q", test.input, test.want, got)
}
}
}

func TestAddParseTree(t *testing.T) {
root := Must(New("root").Parse(`{{define "a"}} {{.}} {{template "b"}} {{.}} "></a>{{end}}`))
tree, err := parse.Parse("t", `{{define "b"}}<a href="{{end}}`, "", "", nil, nil)
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/html/template/escape.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ func (e *escaper) escapeTree(c context, name string, line int) (context, string)
dt := e.template(dname)
if dt == nil {
dt = template.New(dname)
dt.Tree = &parse.Tree{Name: dname, Root: cloneList(t.Root)}
dt.Tree = &parse.Tree{Name: dname, Root: t.Root.CopyList()}
e.derived[dname] = dt
}
t = dt
Expand Down

0 comments on commit dfef0c2

Please sign in to comment.