NotMatch succeeds if the string doesn't match to given regexp. regexp.Compile is used to construct regexp, and Regexp.MatchString is used to perform match. Example: s := NewString(t, "a") s.NotMatch(`[^a]`)
(re string)
| 918 | // s := NewString(t, "a") |
| 919 | // s.NotMatch(`[^a]`) |
| 920 | func (s *String) NotMatch(re string) *String { |
| 921 | opChain := s.chain.enter("NotMatch()") |
| 922 | defer opChain.leave() |
| 923 | |
| 924 | rx, err := regexp.Compile(re) |
| 925 | if err != nil { |
| 926 | opChain.fail(AssertionFailure{ |
| 927 | Type: AssertValid, |
| 928 | Actual: &AssertionValue{re}, |
| 929 | Errors: []error{ |
| 930 | errors.New("expected: valid regexp"), |
| 931 | err, |
| 932 | }, |
| 933 | }) |
| 934 | return s |
| 935 | } |
| 936 | |
| 937 | if rx.MatchString(s.value) { |
| 938 | opChain.fail(AssertionFailure{ |
| 939 | Type: AssertNotMatchRegexp, |
| 940 | Actual: &AssertionValue{s.value}, |
| 941 | Expected: &AssertionValue{re}, |
| 942 | Errors: []error{ |
| 943 | errors.New("expected: string does not match regexp"), |
| 944 | }, |
| 945 | }) |
| 946 | return s |
| 947 | } |
| 948 | |
| 949 | return s |
| 950 | } |
| 951 | |
| 952 | // MatchAll find all matches in string for given regexp and returns a list |
| 953 | // of found matches. |