From e23abf75b3da03a826a4e7c52487c03f862a6b91 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Mon, 13 Oct 2025 18:50:18 -0400 Subject: Add support for array/slice/map/pointer in Contains/NotContains --- assert/assert.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'assert/assert.go') diff --git a/assert/assert.go b/assert/assert.go index b5bba9c..43bd5f2 100644 --- a/assert/assert.go +++ b/assert/assert.go @@ -140,24 +140,36 @@ func NotEqual(t checkmate.TestingT, actual, expected any, msgAndArgs ...any) { } } -// Contains asserts if a string contains a substring. -func Contains(t checkmate.TestingT, s, substr string, msgAndArgs ...any) { +// Contains asserts a container includes a specified item. +// +// Supported container types: +// - string: asserts if the string contains the given substring (item must be a string). +// - slice or array: asserts if the container contains an element equal to the item. +// - map: asserts if the map has the given key (item must be the key type). +// - pointer to any of the above: dereferences and asserts the underlying value. +func Contains(t checkmate.TestingT, container, item any, msgAndArgs ...any) { if ht, ok := t.(helperT); ok { ht.Helper() } - if passed := check.Contains(t, s, substr, msgAndArgs...); !passed { + if passed := check.Contains(t, container, item, msgAndArgs...); !passed { t.FailNow() } } -// NotContains asserts if a string does not contain a substring. -func NotContains(t checkmate.TestingT, s, substr string, msgAndArgs ...any) { +// NotContains asserts whether a container does not include a specified item. +// +// Supported container types: +// - string: asserts if the string does not contain the given substring (item must be a string). +// - slice or array: asserts if the container does not contain an element equal to the item. +// - map: asserts if the map does not have the given key (item must be the key type). +// - pointer to any of the above: dereferences and asserts the underlying value. +func NotContains(t checkmate.TestingT, container, item any, msgAndArgs ...any) { if ht, ok := t.(helperT); ok { ht.Helper() } - if passed := check.NotContains(t, s, substr, msgAndArgs...); !passed { + if passed := check.NotContains(t, container, item, msgAndArgs...); !passed { t.FailNow() } } -- cgit v1.2.3