Skip to content

Commit

Permalink
fix: Update comments and make byte slice condition clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
nickajacks1 committed Feb 17, 2024
1 parent 99903c5 commit 5583f5d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
4 changes: 4 additions & 0 deletions assert/assertion_format.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions assert/assertion_forward.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions assert/assertions.go
Expand Up @@ -881,13 +881,13 @@ func containsElement(list interface{}, element interface{}) (ok, found bool) {
}
return true, false
case reflect.Slice:
// Special case: use bytes.Contains if both element and list are []byte.
elementValue := reflect.ValueOf(element)
if elementValue.Kind() != reflect.Slice ||
elementValue.Type().Elem().Kind() != reflect.Uint8 ||
listType.Elem().Kind() != reflect.Uint8 {
break
if elementValue.Kind() == reflect.Slice &&
elementValue.Type().Elem().Kind() == reflect.Uint8 &&
listType.Elem().Kind() == reflect.Uint8 {
return true, bytes.Contains(listValue.Bytes(), elementValue.Bytes())
}
return true, bytes.Contains(listValue.Bytes(), elementValue.Bytes())
}

for i := 0; i < listValue.Len(); i++ {
Expand All @@ -905,6 +905,8 @@ func containsElement(list interface{}, element interface{}) (ok, found bool) {
// assert.Contains(t, "Hello World", "World")
// assert.Contains(t, ["Hello", "World"], "World")
// assert.Contains(t, {"Hello": "World"}, "Hello")
// assert.Contains(t, []byte("Hello World"), []byte("World"))
// assert.Contains(t, [[]byte("Hello"), []byte("World")], []byte("World"))
func Contains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
Expand All @@ -928,6 +930,8 @@ func Contains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bo
// assert.NotContains(t, "Hello World", "Earth")
// assert.NotContains(t, ["Hello", "World"], "Earth")
// assert.NotContains(t, {"Hello": "World"}, "Earth")
// assert.NotContains(t, []byte("Hello World"), []byte("Earth"))
// assert.NotContains(t, [[]byte("Hello"), []byte("World")], []byte("Earth"))
func NotContains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
Expand Down
8 changes: 8 additions & 0 deletions require/require.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions require/require_forward.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5583f5d

Please sign in to comment.