aboutsummaryrefslogtreecommitdiffstats
path: root/check/check.go
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2025-10-11 10:32:42 -0400
committerEugene Triguba <hello@eugenetriguba.com>2025-10-11 10:32:42 -0400
commitb362eb8ba12834161e1de038395566c3c1f99d59 (patch)
treed46498d8fe8957b9d28d459663031bbd177c60de /check/check.go
parentAdd usage example (diff)
downloadcheckmate-b362eb8ba12834161e1de038395566c3c1f99d59.zip
Add Contains and NotContains
Diffstat (limited to 'check/check.go')
-rw-r--r--check/check.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/check/check.go b/check/check.go
index 6fd320e..25c5a73 100644
--- a/check/check.go
+++ b/check/check.go
@@ -186,6 +186,32 @@ func NotEqual(t checkmate.TestingT, actual, expected any, msgAndArgs ...any) boo
return check(t, actual != expected, msgAndArgs...)
}
+// Contains checks if a string contains a substring.
+func Contains(t checkmate.TestingT, s, substr string, msgAndArgs ...any) bool {
+ if ht, ok := t.(helperT); ok {
+ ht.Helper()
+ }
+
+ if len(msgAndArgs) == 0 {
+ msgAndArgs = []any{"expected %s to contain %s", s, substr}
+ }
+
+ return check(t, strings.Contains(s, substr), msgAndArgs...)
+}
+
+// NotContains checks if a string does not contain a substring.
+func NotContains(t checkmate.TestingT, s, substr string, msgAndArgs ...any) bool {
+ if ht, ok := t.(helperT); ok {
+ ht.Helper()
+ }
+
+ if len(msgAndArgs) == 0 {
+ msgAndArgs = []any{"expected %s to not contain %s", s, substr}
+ }
+
+ return check(t, !strings.Contains(s, substr), msgAndArgs...)
+}
+
// Check evaluates a boolean condition and if the condition is false,
// it will log out a message and mark the test as failed. However, it does
// not immediately stop execution, unlike the assert functions.