(t *testing.T)
| 273 | } |
| 274 | |
| 275 | func TestGetExplanationOutputPolicy(t *testing.T) { |
| 276 | tst := ` |
| 277 | rule: |
| 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 | |
| 327 | func TestCustomTagVisitor(t *testing.T) { |
| 328 | tst := `name: "test" |
nothing calls this directly
no test coverage detected