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

Function TestWhitespaceHandlingErrorPresentation

policy/compiler_test.go:248–279  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

246}
247
248func TestWhitespaceHandlingErrorPresentation(t *testing.T) {
249 policy := parsePolicy(t, "yaml_parsing_cel_error", []ParserOption{})
250 _, _, iss := compile(t, "yaml_parsing_cel_error", policy, []cel.EnvOption{}, []CompilerOption{})
251 if iss.Err() == nil {
252 t.Fatalf("compile('yaml_parsing_cel_error') did not error, wanted error")
253 }
254
255 wantErrors := []string{
256 `ERROR: testdata/yaml_parsing_cel_error/policy.yaml:11:16: found no matching overload for '_+_' applied to '(string, int)'
257 | ("bar" + 1)
258 | ...............^`,
259 `ERROR: testdata/yaml_parsing_cel_error/policy.yaml:15:18: found no matching overload for '_+_' applied to '(string, int)'
260 | ("bar" + 1)
261 | .................^`,
262 `ERROR: testdata/yaml_parsing_cel_error/policy.yaml:19:16: found no matching overload for '_+_' applied to '(string, int)'
263 | ("bar" + 1)
264 | ...............^`,
265 `ERROR: testdata/yaml_parsing_cel_error/policy.yaml:23:18: found no matching overload for '_+_' applied to '(string, int)'
266 | ("bar" + 1)
267 | .................^`,
268 }
269 found := false
270 for _, wantError := range wantErrors {
271 if !strings.Contains(iss.Err().Error(), wantError) {
272 found = true
273 t.Errorf("compile('yaml_parsing_cel_error') does not contain error %s", wantError)
274 }
275 }
276 if found {
277 t.Errorf("compile('yaml_parsing_cel_error') missing errors, got: %s", iss.Err().Error())
278 }
279}
280
281func BenchmarkCompile(b *testing.B) {
282 for _, tst := range policyTests {

Callers

nothing calls this directly

Calls 5

parsePolicyFunction · 0.85
ErrMethod · 0.80
compileFunction · 0.70
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected