Skip to content

Commit

Permalink
Add pre-compiled regexp example for Matches, ErrorMatches, and PanicM…
Browse files Browse the repository at this point in the history
…atches

Documentation added both to the checker.go file and the README.md file
  • Loading branch information
pajlada committed Nov 22, 2022
1 parent e144d26 commit 08f7639
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ the provided regular expression.
For instance:

c.Assert(err, qt.ErrorMatches, `bad wolf .*`)
c.Assert(err, qt.ErrorMatches, regexp.MustCompile("bad wolf .*"))


### HasLen
Expand Down Expand Up @@ -301,6 +302,7 @@ For instance:

c.Assert("these are the voyages", qt.Matches, `these are .*`)
c.Assert(net.ParseIP("1.2.3.4"), qt.Matches, `1.*`)
c.Assert("line 1\nline 2", qt.Matches, regexp.MustCompile(`line \d\nline \d`))


### Not
Expand All @@ -321,6 +323,7 @@ the provided regular expression.
For instance:

c.Assert(func() {panic("bad wolf ...")}, qt.PanicMatches, `bad wolf .*`)
c.Assert(func() {panic("bad wolf ...")}, qt.PanicMatches, regexp.MustCompile(`bad wolf .*`))


### Satisfies
Expand Down
3 changes: 3 additions & 0 deletions checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ var ContentEquals = CmpEquals(cmpopts.SortSlices(func(x, y interface{}) bool {
//
// c.Assert("these are the voyages", qt.Matches, "these are .*")
// c.Assert(net.ParseIP("1.2.3.4"), qt.Matches, "1.*")
// c.Assert("my multi-line\nnumber", qt.Matches, regexp.MustCompile(`my multi-line\n(string|number)`))
var Matches Checker = &matchesChecker{
argNames: []string{"got value", "regexp"},
}
Expand Down Expand Up @@ -210,6 +211,7 @@ func checkFirstArgIsError(got interface{}, note func(key string, value interface
// For instance:
//
// c.Assert(err, qt.ErrorMatches, "bad wolf .*")
// c.Assert(err, qt.ErrorMatches, regexp.MustCompile("bad wolf .*"))
var ErrorMatches Checker = &errorMatchesChecker{
argNames: []string{"got error", "regexp"},
}
Expand All @@ -235,6 +237,7 @@ func (c *errorMatchesChecker) Check(got interface{}, args []interface{}, note fu
// For instance:
//
// c.Assert(func() {panic("bad wolf ...")}, qt.PanicMatches, "bad wolf .*")
// c.Assert(func() {panic("bad wolf ...")}, qt.PanicMatches, regexp.MustCompile(`bad wolf .*`))
var PanicMatches Checker = &panicMatchesChecker{
argNames: []string{"function", "regexp"},
}
Expand Down

0 comments on commit 08f7639

Please sign in to comment.