summaryrefslogtreecommitdiff
path: root/src/pkg/template/template_test.go
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-02-14 13:23:51 +0100
committerOndřej Surý <ondrej@sury.org>2011-02-14 13:23:51 +0100
commit758ff64c69e34965f8af5b2d6ffd65e8d7ab2150 (patch)
tree6d6b34f8c678862fe9b56c945a7b63f68502c245 /src/pkg/template/template_test.go
parent3e45412327a2654a77944249962b3652e6142299 (diff)
downloadgolang-758ff64c69e34965f8af5b2d6ffd65e8d7ab2150.tar.gz
Imported Upstream version 2011-02-01.1upstream/2011-02-01.1
Diffstat (limited to 'src/pkg/template/template_test.go')
-rw-r--r--src/pkg/template/template_test.go41
1 files changed, 30 insertions, 11 deletions
diff --git a/src/pkg/template/template_test.go b/src/pkg/template/template_test.go
index 57f297e8f..3842b6d6b 100644
--- a/src/pkg/template/template_test.go
+++ b/src/pkg/template/template_test.go
@@ -522,9 +522,27 @@ func TestMapDriverType(t *testing.T) {
t.Error("unexpected execute error:", err)
}
s := b.String()
- expected := "template: Ahoy!"
- if s != expected {
- t.Errorf("failed passing string as data: expected %q got %q", "template: Ahoy!", s)
+ expect := "template: Ahoy!"
+ if s != expect {
+ t.Errorf("failed passing string as data: expected %q got %q", expect, s)
+ }
+}
+
+func TestMapNoEntry(t *testing.T) {
+ mp := make(map[string]int)
+ tmpl, err := Parse("template: {notthere}!", nil)
+ if err != nil {
+ t.Error("unexpected parse error:", err)
+ }
+ var b bytes.Buffer
+ err = tmpl.Execute(mp, &b)
+ if err != nil {
+ t.Error("unexpected execute error:", err)
+ }
+ s := b.String()
+ expect := "template: 0!"
+ if s != expect {
+ t.Errorf("failed passing string as data: expected %q got %q", expect, s)
}
}
@@ -539,8 +557,9 @@ func TestStringDriverType(t *testing.T) {
t.Error("unexpected execute error:", err)
}
s := b.String()
- if s != "template: hello" {
- t.Errorf("failed passing string as data: expected %q got %q", "template: hello", s)
+ expect := "template: hello"
+ if s != expect {
+ t.Errorf("failed passing string as data: expected %q got %q", expect, s)
}
}
@@ -555,18 +574,18 @@ func TestTwice(t *testing.T) {
t.Error("unexpected parse error:", err)
}
s := b.String()
- text := "template: hello"
- if s != text {
- t.Errorf("failed passing string as data: expected %q got %q", text, s)
+ expect := "template: hello"
+ if s != expect {
+ t.Errorf("failed passing string as data: expected %q got %q", expect, s)
}
err = tmpl.Execute("hello", &b)
if err != nil {
t.Error("unexpected parse error:", err)
}
s = b.String()
- text += text
- if s != text {
- t.Errorf("failed passing string as data: expected %q got %q", text, s)
+ expect += expect
+ if s != expect {
+ t.Errorf("failed passing string as data: expected %q got %q", expect, s)
}
}