(t *testing.T)
| 205 | } |
| 206 | |
| 207 | func 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 | |
| 251 | func TestValidateRegexProgramSizeLimitToConfig(t *testing.T) { |
| 252 | val := ValidateRegexProgramSizeLimit(5) |
nothing calls this directly
no test coverage detected