mirror of
https://github.com/golang/go
synced 2024-11-26 00:28:00 -07:00
test & fix template used twice
R=r DELTA=30 (30 added, 0 deleted, 0 changed) OCL=27470 CL=27474
This commit is contained in:
parent
fa60226073
commit
cf8b9ce580
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user