Index: src/pkg/text/template/parse/parse_test.go |
=================================================================== |
--- a/src/pkg/text/template/parse/parse_test.go |
+++ b/src/pkg/text/template/parse/parse_test.go |
@@ -332,6 +332,28 @@ |
} |
} |
+func TestErrorContextWithShallowTreeCopy(t *testing.T) { |
+ tree, err := New("root").Parse("{{if true}}{{end}}", "", "", make(map[string]*Tree), nil) |
+ if err != nil { |
+ t.Fatalf("unexpected tree parse failure: %v", err) |
+ } |
+ // copy all available (exported) fields |
+ treeCopy := &Tree{ |
+ Name: tree.Name, |
+ Root: tree.Root.CopyList(), |
+ ParseName: tree.ParseName, |
+ Text: tree.Text, |
+ } |
+ wantLocation, wantContext := tree.ErrorContext(tree.Root.Nodes[0]) |
+ gotLocation, gotContext := treeCopy.ErrorContext(treeCopy.Root.Nodes[0]) |
+ if wantLocation != gotLocation { |
+ t.Errorf("wrong error location want %q got %q", wantLocation, gotLocation) |
+ } |
+ if wantContext != gotContext { |
+ t.Errorf("wrong error location want %q got %q", wantContext, gotContext) |
+ } |
+} |
+ |
// All failures, and the result is a string that must appear in the error message. |
var errorTests = []parseTest{ |
// Check line numbers are accurate. |