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

Function TestGetExplanationOutputPolicy

policy/parser_test.go:275–325  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

273}
274
275func TestGetExplanationOutputPolicy(t *testing.T) {
276 tst := `
277rule:
278 match:
279 - condition: "false"
280 rule:
281 match:
282 - condition: "1 > 2"
283 output: "false"
284 explanation: "'bad_inner'"
285 - output: "true"
286 explanation: "'good_inner'"
287 - output: "true"
288 explanation: "'good_outer'"
289 `
290
291 parser, err := NewParser()
292 if err != nil {
293 t.Fatalf("NewParser() failed: %v", err)
294 }
295 policy, iss := parser.Parse(StringSource(tst, "<input>"))
296 if iss != nil {
297 t.Fatalf("Parse() failed: %v", err)
298 }
299
300 explanationPolicy := policy.GetExplanationOutputPolicy()
301
302 want := "'bad_inner'"
303 got := explanationPolicy.Rule().Matches()[0].rule.Matches()[0].output.Value
304 if got != want {
305 t.Errorf("First inner output = %v, wanted %v", got, want)
306 }
307
308 want = "1 > 2"
309 got = explanationPolicy.Rule().Matches()[0].rule.Matches()[0].condition.Value
310 if got != want {
311 t.Errorf("First inner condition = %v, wanted %v", got, want)
312 }
313
314 want = "'good_inner'"
315 got = explanationPolicy.Rule().Matches()[0].rule.Matches()[1].output.Value
316 if got != want {
317 t.Errorf("Second inner output = %v, wanted %v", got, want)
318 }
319
320 want = "'good_outer'"
321 got = explanationPolicy.Rule().Matches()[1].output.Value
322 if got != want {
323 t.Errorf("Second outer output = %v, wanted %v", got, want)
324 }
325}
326
327func TestCustomTagVisitor(t *testing.T) {
328 tst := `name: "test"

Callers

nothing calls this directly

Calls 6

ParseMethod · 0.95
StringSourceFunction · 0.85
NewParserFunction · 0.70
MatchesMethod · 0.45
RuleMethod · 0.45

Tested by

no test coverage detected