Skip to content

Commit 8e27a2d

Browse files
committed
Add NoMatch
1 parent f25f457 commit 8e27a2d

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

be_example_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ func Example() {
3535

3636
type mytype string
3737
var mystring mytype = "hello, world"
38-
be.Match(t, `world`, mystring) // good
39-
be.Match(t, `World`, mystring) // bad
40-
be.Match(t, `^\W*$`, []byte("\a\b\x00\r\t")) // good
41-
be.Match(t, `^\W*$`, []byte("\a\bo\r\t")) // bad
38+
be.Match(t, `world`, mystring) // good
39+
be.Match(t, `World`, mystring) // bad
40+
be.Match(t, `^\W*$`, []byte("\a\b\x00\r\t")) // good
41+
be.NoMatch(t, `^\W*$`, []byte("\a\b\x00\r\t")) // bad
4242

4343
seq := strings.FieldsSeq("1 2 3 4")
4444
be.EqualLength(t, 4, seq) // good
@@ -55,8 +55,8 @@ func Example() {
5555
// got: <nil>
5656
// got errors.Is(<nil>, permission denied) == false
5757
// got errors.As((O_o), **fs.PathError) == false
58-
// /World/ !~ "hello, world"
59-
// /^\W*$/ !~ "\a\bo\r\t"
58+
// missing match: /World/ !~ "hello, world"
59+
// unexpected match: /^\W*$/ =~ "\a\b\x00\r\t"
6060
// want len(seq) == 1; got at least 2
6161
// want len(seq) >= 5; got 4
6262
// want len(seq) >= 4; got 3

match.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,18 @@ func Match[byteseq ~string | ~[]byte](t testing.TB, pattern string, got byteseq)
1313
t.Helper()
1414
reg := regexp.MustCompile(pattern)
1515
if !match(reg, got) {
16-
t.Fatalf("/%s/ !~ %q", pattern, got)
16+
t.Fatalf("missing match: /%s/ !~ %q", pattern, got)
17+
}
18+
}
19+
20+
// NoMatch calls t.Fatalf if got matches the [regexp] pattern.
21+
//
22+
// The pattern must compile.
23+
func NoMatch[byteseq ~string | ~[]byte](t testing.TB, pattern string, got byteseq) {
24+
t.Helper()
25+
reg := regexp.MustCompile(pattern)
26+
if match(reg, got) {
27+
t.Fatalf("unexpected match: /%s/ =~ %q", pattern, got)
1728
}
1829
}
1930

0 commit comments

Comments
 (0)