TestErrors reporting and recording.
(t *testing.T)
| 22 | |
| 23 | // TestErrors reporting and recording. |
| 24 | func TestErrors(t *testing.T) { |
| 25 | source := NewStringSource("a.b\n&&arg(missing, paren", "errors-test") |
| 26 | errors := NewErrors(source) |
| 27 | errors.ReportError(NewLocation(1, 1), "No such field") |
| 28 | if len(errors.GetErrors()) != 1 { |
| 29 | t.Errorf("%s first error not recorded", t.Name()) |
| 30 | } |
| 31 | errors.ReportError(NewLocation(2, 20), |
| 32 | "Syntax error, missing paren") |
| 33 | if len(errors.GetErrors()) != 2 { |
| 34 | t.Errorf("%s second error not recorded", t.Name()) |
| 35 | } |
| 36 | got := errors.ToDisplayString() |
| 37 | want := |
| 38 | "ERROR: errors-test:1:2: No such field\n" + |
| 39 | " | a.b\n" + |
| 40 | " | .^\n" + |
| 41 | "ERROR: errors-test:2:21: Syntax error, missing paren\n" + |
| 42 | " | &&arg(missing, paren\n" + |
| 43 | " | ....................^" |
| 44 | if got != want { |
| 45 | t.Errorf("%s got %s, wanted %s", t.Name(), got, want) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | func TestErrorsReportingLimit(t *testing.T) { |
| 50 | errors := NewErrors(NewTextSource("hello world")) |
nothing calls this directly
no test coverage detected