MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestErrors

Function TestErrors

common/errors_test.go:24–47  ·  view source on GitHub ↗

TestErrors reporting and recording.

(t *testing.T)

Source from the content-addressed store, hash-verified

22
23// TestErrors reporting and recording.
24func 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
49func TestErrorsReportingLimit(t *testing.T) {
50 errors := NewErrors(NewTextSource("hello world"))

Callers

nothing calls this directly

Calls 7

ReportErrorMethod · 0.95
GetErrorsMethod · 0.95
ToDisplayStringMethod · 0.95
NewStringSourceFunction · 0.85
NewErrorsFunction · 0.85
NewLocationFunction · 0.85
NameMethod · 0.65

Tested by

no test coverage detected