Commit cf8b9ce5 authored by Russ Cox's avatar Russ Cox

test & fix template used twice

R=r
DELTA=30  (30 added, 0 deleted, 0 changed)
OCL=27470
CL=27474
parent fa602260
......@@ -514,6 +514,7 @@ func (t *Template) Execute(data interface{}, wr io.Write) *os.Error {
val := reflect.NewValue(data);
ch := make(chan *os.Error);
go func() {
t.p = 0;
t.execute(&state{nil, ch, val, wr});
ch <- nil; // clean return;
}();
......
......@@ -199,8 +199,37 @@ func TestStringDriverType(t *testing.T) {
}
var b io.ByteBuffer;
err = tmpl.Execute("hello", &b);
if err != nil {
t.Error("unexpected parse error:", err)
}
s := string(b.Data());
if s != "template: hello" {
t.Errorf("failed passing string as data: expected %q got %q", "template: hello", s)
}
}
func TestTwice(t *testing.T) {
tmpl, err, line := Parse("template: {@}", nil);
if err != nil {
t.Error("unexpected parse error:", err)
}
var b io.ByteBuffer;
err = tmpl.Execute("hello", &b);
if err != nil {
t.Error("unexpected parse error:", err)
}
s := string(b.Data());
text := "template: hello";
if s != text {
t.Errorf("failed passing string as data: expected %q got %q", text, s);
}
err = tmpl.Execute("hello", &b);
if err != nil {
t.Error("unexpected parse error:", err)
}
s = string(b.Data());
text += text;
if s != text {
t.Errorf("failed passing string as data: expected %q got %q", text, s);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment