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