-
Notifications
You must be signed in to change notification settings - Fork 554
Open
Description
add below code in assertions/strings.go
func ShouldMatchRegex(actual interface{}, expected ...interface{}) string {
if fail := need(1, expected); fail != success {
return fail
}
obs, valueIsString := actual.(string)
pattern, expecIsString := expected[0].(string)
if !valueIsString || !expecIsString {
return fmt.Sprintf(shouldBothBeStrings, reflect.TypeOf(actual), reflect.TypeOf(expected[0]))
}
matched, err := regexp.MatchString(pattern, obs)
if err != nil {
return fmt.Sprintf("error from regex.MatchString: '%v' in trying to match observed '%s' against expected pattern '%s'", err, obs, pattern)
}
if !matched {
return fmt.Sprintf("failed to match observed '%s' against expected pattern '%s'", obs, pattern)
}
return success
}then add ShouldMatchRegex in convey/assertions.go
ShouldMatchRegex = assertions.ShouldMatchRegexMetadata
Metadata
Assignees
Labels
No labels