LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package parse | 5 package parse |
6 | 6 |
7 import ( | 7 import ( |
8 "flag" | 8 "flag" |
9 "fmt" | 9 "fmt" |
10 "strings" | 10 "strings" |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 if err != nil { | 325 if err != nil { |
326 t.Errorf("%q: unexpected error: %v", test.name, err) | 326 t.Errorf("%q: unexpected error: %v", test.name, err) |
327 continue | 327 continue |
328 } | 328 } |
329 if empty := IsEmptyTree(tree.Root); empty != test.empty { | 329 if empty := IsEmptyTree(tree.Root); empty != test.empty { |
330 t.Errorf("%q: expected %t got %t", test.name, test.empty
, empty) | 330 t.Errorf("%q: expected %t got %t", test.name, test.empty
, empty) |
331 } | 331 } |
332 } | 332 } |
333 } | 333 } |
334 | 334 |
| 335 func TestErrorContextWithShallowTreeCopy(t *testing.T) { |
| 336 tree, err := New("root").Parse("{{if true}}{{end}}", "", "", make(map[st
ring]*Tree), nil) |
| 337 if err != nil { |
| 338 t.Fatalf("unexpected tree parse failure: %v", err) |
| 339 } |
| 340 // copy all available (exported) fields |
| 341 treeCopy := &Tree{ |
| 342 Name: tree.Name, |
| 343 Root: tree.Root.CopyList(), |
| 344 ParseName: tree.ParseName, |
| 345 Text: tree.Text, |
| 346 } |
| 347 wantLocation, wantContext := tree.ErrorContext(tree.Root.Nodes[0]) |
| 348 gotLocation, gotContext := treeCopy.ErrorContext(treeCopy.Root.Nodes[0]) |
| 349 if wantLocation != gotLocation { |
| 350 t.Errorf("wrong error location want %q got %q", wantLocation, go
tLocation) |
| 351 } |
| 352 if wantContext != gotContext { |
| 353 t.Errorf("wrong error location want %q got %q", wantContext, got
Context) |
| 354 } |
| 355 } |
| 356 |
335 // All failures, and the result is a string that must appear in the error messag
e. | 357 // All failures, and the result is a string that must appear in the error messag
e. |
336 var errorTests = []parseTest{ | 358 var errorTests = []parseTest{ |
337 // Check line numbers are accurate. | 359 // Check line numbers are accurate. |
338 {"unclosed1", | 360 {"unclosed1", |
339 "line1\n{{", | 361 "line1\n{{", |
340 hasError, `unclosed1:2: unexpected unclosed action in command`}, | 362 hasError, `unclosed1:2: unexpected unclosed action in command`}, |
341 {"unclosed2", | 363 {"unclosed2", |
342 "line1\n{{define `x`}}line2\n{{", | 364 "line1\n{{define `x`}}line2\n{{", |
343 hasError, `unclosed2:3: unexpected unclosed action in command`}, | 365 hasError, `unclosed2:3: unexpected unclosed action in command`}, |
344 // Specific errors. | 366 // Specific errors. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 _, err := New(test.name).Parse(test.input, "", "", make(map[stri
ng]*Tree)) | 417 _, err := New(test.name).Parse(test.input, "", "", make(map[stri
ng]*Tree)) |
396 if err == nil { | 418 if err == nil { |
397 t.Errorf("%q: expected error", test.name) | 419 t.Errorf("%q: expected error", test.name) |
398 continue | 420 continue |
399 } | 421 } |
400 if !strings.Contains(err.Error(), test.result) { | 422 if !strings.Contains(err.Error(), test.result) { |
401 t.Errorf("%q: error %q does not contain %q", test.name,
err, test.result) | 423 t.Errorf("%q: error %q does not contain %q", test.name,
err, test.result) |
402 } | 424 } |
403 } | 425 } |
404 } | 426 } |
LEFT | RIGHT |