(t *testing.T)
| 53 | } |
| 54 | |
| 55 | func TestCompose_Unnest(t *testing.T) { |
| 56 | policyYAML := `name: unnest |
| 57 | rule: |
| 58 | match: |
| 59 | - condition: "2 == 1" |
| 60 | output: "'hi'" |
| 61 | - output: "'hello'" |
| 62 | ` |
| 63 | src := StringSource(policyYAML, "unnest.yaml") |
| 64 | parser, err := NewParser() |
| 65 | if err != nil { |
| 66 | t.Fatalf("NewParser() failed: %v", err) |
| 67 | } |
| 68 | policy, iss := parser.Parse(src) |
| 69 | if iss.Err() != nil { |
| 70 | t.Fatalf("parser.Parse() failed: %v", iss.Err()) |
| 71 | } |
| 72 | |
| 73 | env, err := cel.NewEnv(cel.OptionalTypes(), ext.Bindings()) |
| 74 | if err != nil { |
| 75 | t.Fatalf("cel.NewEnv() failed: %v", err) |
| 76 | } |
| 77 | compiledRule, iss := CompileRule(env, policy) |
| 78 | if iss.Err() != nil { |
| 79 | t.Fatalf("CompileRule() failed: %v", iss.Err()) |
| 80 | } |
| 81 | |
| 82 | composer, err := NewRuleComposer(env, ExpressionUnnestHeight(1)) |
| 83 | if err != nil { |
| 84 | t.Fatalf("NewRuleComposer() failed: %v", err) |
| 85 | } |
| 86 | compAST, iss := composer.Compose(compiledRule) |
| 87 | if iss.Err() != nil { |
| 88 | t.Fatalf("composer.Compose() failed: %v", iss.Err()) |
| 89 | } |
| 90 | |
| 91 | verifySourceInfoTransfer(t, compiledRule, compAST) |
| 92 | if t.Failed() { |
| 93 | t.Logf("composed AST: %s", debug.ToDebugStringWithIDs(compAST.NativeRep().Expr())) |
| 94 | t.Logf("SourceInfo: %v", compAST.NativeRep().SourceInfo().OffsetRanges()) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | // verifySourceInfoTransfer checks that each offset range in the compiledRule has a corresponding node in composed |
| 99 | func verifySourceInfoTransfer(t *testing.T, compiledRule *CompiledRule, composed *cel.Ast) { |
nothing calls this directly
no test coverage detected