aboutsummaryrefslogtreecommitdiffstats
path: root/assert/assert.go
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2025-10-13 18:50:18 -0400
committerEugene Triguba <hello@eugenetriguba.com>2025-10-13 18:50:18 -0400
commite23abf75b3da03a826a4e7c52487c03f862a6b91 (patch)
tree86e8697e044c80d33d4ff1e7fff88d81ae2624a1 /assert/assert.go
parentAdd test script, scripts/ folder, and use test script in ci (diff)
downloadcheckmate-e23abf75b3da03a826a4e7c52487c03f862a6b91.zip
Add support for array/slice/map/pointer in Contains/NotContains
Diffstat (limited to 'assert/assert.go')
-rw-r--r--assert/assert.go24
1 files changed, 18 insertions, 6 deletions
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()
}
}