MCPcopy Create free account
hub / github.com/goadesign/goa / byPattern

Function byPattern

expr/example.go:231–241  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

229//
230// Note: if multiple patterns are given, only one of them is used.
231func 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
243func patgen(re *syntax.Regexp, r *ExampleGenerator) string {
244 switch re.Op {

Callers 1

ExampleMethod · 0.85

Calls 3

hasPatternValidationFunction · 0.85
patgenFunction · 0.85
NameMethod · 0.65

Tested by

no test coverage detected