Contains succeeds if item is in collection. The collection may be a string, map, slice, or array. See [gotest.tools/v3/assert/cmp.Contains]. When either item or collection is a multi-line string, the failure message contains a multi-line report of the differences.
(collection, item any)
| 21 | // item or collection is a multi-line string, the failure message contains a |
| 22 | // multi-line report of the differences. |
| 23 | func Contains(collection, item any) Comparison { |
| 24 | cString, cStringOK := collection.(string) |
| 25 | iString, iStringOK := item.(string) |
| 26 | |
| 27 | if cStringOK && iStringOK { |
| 28 | if strings.Contains(cString, "\n") || strings.Contains(iString, "\n") { |
| 29 | return func() gotest.Result { |
| 30 | if strings.Contains(cString, iString) { |
| 31 | return gotest.ResultSuccess |
| 32 | } |
| 33 | return gotest.ResultFailureTemplate(` |
| 34 | --- {{ with callArg 0 }}{{ formatNode . }}{{else}}←{{end}} string does not contain |
| 35 | +++ {{ with callArg 1 }}{{ formatNode . }}{{else}}→{{end}} substring |
| 36 | {{ .Data.diff }}`, |
| 37 | map[string]any{ |
| 38 | "diff": gocmp.Diff(collection, item), |
| 39 | }) |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | return gotest.Contains(collection, item) |
| 45 | } |
| 46 | |
| 47 | // DeepEqual compares two values using [github.com/google/go-cmp/cmp] and |
| 48 | // succeeds if the values are equal. The comparison can be customized using |
no outgoing calls