byPattern generates a random value that satisfies the pattern. Note: if multiple patterns are given, only one of them is used.
(a *AttributeExpr, r *ExampleGenerator)
| 229 | // |
| 230 | // Note: if multiple patterns are given, only one of them is used. |
| 231 | func byPattern(a *AttributeExpr, r *ExampleGenerator) any { |
| 232 | if !hasPatternValidation(a) { |
| 233 | return false |
| 234 | } |
| 235 | pattern := a.Validation.Pattern |
| 236 | re, err := syntax.Parse(pattern, syntax.Perl) |
| 237 | if err != nil { |
| 238 | return r.Name() |
| 239 | } |
| 240 | return patgen(re.Simplify(), r) |
| 241 | } |
| 242 | |
| 243 | func patgen(re *syntax.Regexp, r *ExampleGenerator) string { |
| 244 | switch re.Op { |
no test coverage detected