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

Function TestValidateRegexProgramSizeLimit

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

Source from the content-addressed store, hash-verified

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