Commits

Rob Pike  committed 2457f88 Draft

add test of invariant in findVar

R=rsc
DELTA=23 (23 added, 0 deleted, 0 changed)
OCL=32592
CL=32595

  • Participants
  • Parent commits 3cbf22e

Comments (0)

Files changed (1)

File src/pkg/template/template_test.go

 	integer int;
 	raw string;
 	innerT T;
+	innerPointerT *T;
 	data []T;
 	pdata []*T;
 	empty []*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()));
+	}
+}