Skip to content

Commit d2874f2

Browse files
committed
Deprecate In, NotIn
1 parent 8e27a2d commit d2874f2

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

in.go

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,24 @@
11
package be
22

33
import (
4-
"bytes"
5-
"reflect"
6-
"strings"
4+
"regexp"
75
"testing"
86
)
97

108
// In calls t.Fatalf if needle is not contained in the string or []byte haystack.
9+
//
10+
// Deprecated: Use Match(t, regexp.QuoteMeta(needle), haystack).
11+
//
12+
//go:fix inline
1113
func In[byteseq ~string | ~[]byte](t testing.TB, needle string, haystack byteseq) {
12-
t.Helper()
13-
if !in(needle, haystack) {
14-
t.Fatalf("%q not in %q", needle, haystack)
15-
}
14+
Match(t, regexp.QuoteMeta(needle), haystack)
1615
}
1716

1817
// NotIn calls t.Fatalf if needle is contained in the string or []byte haystack.
18+
//
19+
// Deprecated: Use NoMatch(t, regexp.QuoteMeta(needle), haystack).
20+
//
21+
//go:fix inline
1922
func NotIn[byteseq ~string | ~[]byte](t testing.TB, needle string, haystack byteseq) {
20-
t.Helper()
21-
if in(needle, haystack) {
22-
t.Fatalf("%q in %q", needle, haystack)
23-
}
24-
}
25-
26-
func in[byteseq ~string | ~[]byte](needle string, haystack byteseq) bool {
27-
rv := reflect.ValueOf(haystack)
28-
switch rv.Kind() {
29-
case reflect.String:
30-
return strings.Contains(rv.String(), needle)
31-
case reflect.Slice:
32-
return bytes.Contains(rv.Bytes(), []byte(needle))
33-
}
34-
panic("unreachable")
23+
NoMatch(t, regexp.QuoteMeta(needle), haystack)
3524
}

0 commit comments

Comments
 (0)