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

Function TestCompiledRuleHasOptionalOutput

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

Source from the content-addressed store, hash-verified

60}
61
62func TestCompiledRuleHasOptionalOutput(t *testing.T) {
63 env, err := cel.NewEnv()
64 if err != nil {
65 t.Fatalf("cel.NewEnv() failed: %v", err)
66 }
67 tests := []struct {
68 rule *CompiledRule
69 optional bool
70 }{
71 {rule: &CompiledRule{}, optional: false},
72 {
73 rule: &CompiledRule{
74 matches: []*CompiledMatch{{}},
75 },
76 optional: true,
77 },
78 {
79 rule: &CompiledRule{
80 matches: []*CompiledMatch{{}},
81 },
82 optional: true,
83 },
84 {
85 rule: &CompiledRule{
86 matches: []*CompiledMatch{{cond: mustCompileExpr(t, env, "true")}},
87 },
88 optional: false,
89 },
90 {
91 rule: &CompiledRule{
92 matches: []*CompiledMatch{{cond: mustCompileExpr(t, env, "1 < 0")}},
93 },
94 optional: true,
95 },
96 {
97 rule: &CompiledRule{
98 matches: []*CompiledMatch{
99 {
100 cond: mustCompileExpr(t, env, "true"),
101 nestedRule: &CompiledRule{
102 matches: []*CompiledMatch{{cond: mustCompileExpr(t, env, "1 > 0")}},
103 },
104 },
105 {cond: mustCompileExpr(t, env, "true")},
106 },
107 },
108 optional: false,
109 },
110 }
111 for _, tst := range tests {
112 got := tst.rule.HasOptionalOutput()
113 if got != tst.optional {
114 t.Errorf("rule.HasOptionalOutput() got %v, wanted, %v", got, tst.optional)
115 }
116 }
117}
118
119func TestMaxNestedExpressions_Error(t *testing.T) {

Callers

nothing calls this directly

Calls 3

NewEnvFunction · 0.92
mustCompileExprFunction · 0.85
HasOptionalOutputMethod · 0.80

Tested by

no test coverage detected