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)
| 273 | // m := NewMatch(t, r.FindStringSubmatch(s), nil) |
| 274 | // m.HasSubmatches("example.com", "john") |
| 275 | func (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. |