summaryrefslogtreecommitdiff
path: root/src/pkg/template/template_test.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2009-07-31 12:52:03 -0700
committerRob Pike <r@golang.org>2009-07-31 12:52:03 -0700
commita317be2de29a4772b9d562cd94b5064b6ddcd3af (patch)
tree013abb71ff0675494fd6d42a5a8288fb17f85aa5 /src/pkg/template/template_test.go
parent612fef314e8ca5f110749e4ca54207c49a59f30c (diff)
downloadgolang-a317be2de29a4772b9d562cd94b5064b6ddcd3af.tar.gz
add test of invariant in findVar
R=rsc DELTA=23 (23 added, 0 deleted, 0 changed) OCL=32592 CL=32595
Diffstat (limited to 'src/pkg/template/template_test.go')
-rw-r--r--src/pkg/template/template_test.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/pkg/template/template_test.go b/src/pkg/template/template_test.go
index 7aeec6d37..c293f6646 100644
--- a/src/pkg/template/template_test.go
+++ b/src/pkg/template/template_test.go
@@ -28,6 +28,7 @@ type S struct {
integer int;
raw string;
innerT T;
+ innerPointerT *T;
data []T;
pdata []*T;
empty []*T;
@@ -341,3 +342,25 @@ func TestCustomDelims(t *testing.T) {
}
}
}
+
+// Test that a variable evaluates to the field itself and does not further indirection
+func TestVarIndirection(t *testing.T) {
+ s := new(S);
+ // initialized by hand for clarity.
+ s.innerPointerT = &t1;
+
+ var buf bytes.Buffer;
+ input := "{.section @}{innerPointerT}{.end}";
+ tmpl, err := Parse(input, nil);
+ if err != nil {
+ t.Fatal("unexpected parse error:", err);
+ }
+ err = tmpl.Execute(s, &buf);
+ if err != nil {
+ t.Fatal("unexpected execute error:", err)
+ }
+ expect := fmt.Sprintf("%v", &t1); // output should be hex address of t1
+ if string(buf.Data()) != expect {
+ t.Errorf("for %q: expected %q got %q", input, expect, string(buf.Data()));
+ }
+}