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

Function TestCompiledRuleHasOptionalOutput

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

Source from the content-addressed store, hash-verified

106}
107
108func TestCompiledRuleHasOptionalOutput(t *testing.T) {
109 env, err := cel.NewEnv()
110 if err != nil {
111 t.Fatalf("cel.NewEnv() failed: %v", err)
112 }
113 tests := []struct {
114 rule *CompiledRule
115 optional bool
116 }{
117 {rule: &CompiledRule{}, optional: false},
118 {
119 rule: &CompiledRule{
120 matches: []*CompiledMatch{{}},
121 },
122 optional: true,
123 },
124 {
125 rule: &CompiledRule{
126 matches: []*CompiledMatch{{}},
127 },
128 optional: true,
129 },
130 {
131 rule: &CompiledRule{
132 matches: []*CompiledMatch{{cond: mustCompileExpr(t, env, "true")}},
133 },
134 optional: false,
135 },
136 {
137 rule: &CompiledRule{
138 matches: []*CompiledMatch{{cond: mustCompileExpr(t, env, "1 < 0")}},
139 },
140 optional: true,
141 },
142 {
143 rule: &CompiledRule{
144 matches: []*CompiledMatch{
145 {
146 cond: mustCompileExpr(t, env, "true"),
147 nestedRule: &CompiledRule{
148 matches: []*CompiledMatch{{cond: mustCompileExpr(t, env, "1 > 0")}},
149 },
150 },
151 {cond: mustCompileExpr(t, env, "true")},
152 },
153 },
154 optional: false,
155 },
156 }
157 for _, tst := range tests {
158 got := tst.rule.HasOptionalOutput()
159 if got != tst.optional {
160 t.Errorf("rule.HasOptionalOutput() got %v, wanted, %v", got, tst.optional)
161 }
162 }
163}
164
165func 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