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

Function TestValidateRegexProgramSizeLimit

cel/validator_test.go:207–249  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

205}
206
207func TestValidateRegexProgramSizeLimit(t *testing.T) {
208 opts := []EnvOption{
209 Variable("x", types.StringType),
210 ASTValidators(ValidateRegexProgramSizeLimit(5)),
211 }
212
213 tests := []struct {
214 expr string
215 iss string
216 }{
217 {
218 expr: `'hello'.matches('el*')`,
219 },
220 {
221 expr: `'hello'.matches('(a|b)*[0-9]+')`,
222 iss: `
223 ERROR: <input>:1:17: regex program size 8 exceeds limit of 5
224 | 'hello'.matches('(a|b)*[0-9]+')
225 | ................^`,
226 },
227 {
228 expr: `'hello'.matches(x)`,
229 },
230 }
231 for _, tst := range tests {
232 tc := tst
233 t.Run(tc.expr, func(t *testing.T) {
234 _, err := Compile(tc.expr, opts...)
235 if tc.iss != "" {
236 if err == nil {
237 t.Fatalf("Compile(%v) returned ast, expected error: %v", tc.expr, tc.iss)
238 }
239 if !test.Compare(err.Error(), tc.iss) {
240 t.Fatalf("Compile(%v) returned %v, expected error: %v", tc.expr, err, tc.iss)
241 }
242 return
243 }
244 if err != nil {
245 t.Fatalf("Compile(%v) failed: %v", tc.expr, err)
246 }
247 })
248 }
249}
250
251func TestValidateRegexProgramSizeLimitToConfig(t *testing.T) {
252 val := ValidateRegexProgramSizeLimit(5)

Callers

nothing calls this directly

Calls 6

CompareFunction · 0.92
ASTValidatorsFunction · 0.85
VariableFunction · 0.70
CompileFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected