MCPcopy Create free account
hub / github.com/gavv/httpexpect / HasSubmatches

Method HasSubmatches

match.go:275–299  ·  view source on GitHub ↗

HasSubmatches succeeds if submatches array, starting from index 1, is equal to given array. Note that submatch with index 0 contains the whole match and is not included into this check. Example: s := "http://example.com/users/john" r := regexp.MustCompile(`http://(.+)/users/(.+)`) m := NewMatc

(submatchValues ...string)

Source from the content-addressed store, hash-verified

273// m := NewMatch(t, r.FindStringSubmatch(s), nil)
274// m.HasSubmatches("example.com", "john")
275func (m *Match) HasSubmatches(submatchValues ...string) *Match {
276 opChain := m.chain.enter("HasSubmatches()")
277 defer opChain.leave()
278
279 if opChain.failed() {
280 return m
281 }
282
283 if submatchValues == nil {
284 submatchValues = []string{}
285 }
286
287 if !reflect.DeepEqual(submatchValues, m.getValues()) {
288 opChain.fail(AssertionFailure{
289 Type: AssertEqual,
290 Actual: &AssertionValue{m.submatchValues},
291 Expected: &AssertionValue{submatchValues},
292 Errors: []error{
293 errors.New("expected: sub-match lists are equal"),
294 },
295 })
296 }
297
298 return m
299}
300
301// NotHasSubmatches succeeds if submatches array, starting from index 1, is not
302// equal to given array.

Callers 3

ValuesMethod · 0.95
TestMatch_FailedChainFunction · 0.80
TestMatch_ValuesFunction · 0.80

Calls 5

getValuesMethod · 0.95
enterMethod · 0.80
leaveMethod · 0.80
failedMethod · 0.80
failMethod · 0.80

Tested by 2

TestMatch_FailedChainFunction · 0.64
TestMatch_ValuesFunction · 0.64