(t *testing.T)
| 236 | } |
| 237 | |
| 238 | func TestGetExplanationOutputPolicy(t *testing.T) { |
| 239 | tst := ` |
| 240 | rule: |
| 241 | match: |
| 242 | - condition: "false" |
| 243 | rule: |
| 244 | match: |
| 245 | - condition: "1 > 2" |
| 246 | output: "false" |
| 247 | explanation: "'bad_inner'" |
| 248 | - output: "true" |
| 249 | explanation: "'good_inner'" |
| 250 | - output: "true" |
| 251 | explanation: "'good_outer'" |
| 252 | ` |
| 253 | |
| 254 | parser, err := NewParser() |
| 255 | if err != nil { |
| 256 | t.Fatalf("NewParser() failed: %v", err) |
| 257 | } |
| 258 | policy, iss := parser.Parse(StringSource(tst, "<input>")) |
| 259 | if iss != nil { |
| 260 | t.Fatalf("Parse() failed: %v", err) |
| 261 | } |
| 262 | |
| 263 | explanationPolicy := policy.GetExplanationOutputPolicy() |
| 264 | |
| 265 | want := "'bad_inner'" |
| 266 | got := explanationPolicy.Rule().Matches()[0].rule.Matches()[0].output.Value |
| 267 | if got != want { |
| 268 | t.Errorf("First inner output = %v, wanted %v", got, want) |
| 269 | } |
| 270 | |
| 271 | want = "1 > 2" |
| 272 | got = explanationPolicy.Rule().Matches()[0].rule.Matches()[0].condition.Value |
| 273 | if got != want { |
| 274 | t.Errorf("First inner condition = %v, wanted %v", got, want) |
| 275 | } |
| 276 | |
| 277 | want = "'good_inner'" |
| 278 | got = explanationPolicy.Rule().Matches()[0].rule.Matches()[1].output.Value |
| 279 | if got != want { |
| 280 | t.Errorf("Second inner output = %v, wanted %v", got, want) |
| 281 | } |
| 282 | |
| 283 | want = "'good_outer'" |
| 284 | got = explanationPolicy.Rule().Matches()[1].output.Value |
| 285 | if got != want { |
| 286 | t.Errorf("Second outer output = %v, wanted %v", got, want) |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | func TestCustomTagVisitor(t *testing.T) { |
| 291 | tst := `name: "test" |
nothing calls this directly
no test coverage detected