Contains asserts that the specified string, list(array, slice...) or map contains the specified substring or element. assert.Contains(t, "Hello World", "World") assert.Contains(t, ["Hello", "World"], "World") assert.Contains(t, {"Hello": "World"}, "Hello")
(t TestingT, s, contains interface{}, msgAndArgs ...interface{})
| 958 | // assert.Contains(t, ["Hello", "World"], "World") |
| 959 | // assert.Contains(t, {"Hello": "World"}, "Hello") |
| 960 | func Contains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bool { |
| 961 | if h, ok := t.(tHelper); ok { |
| 962 | h.Helper() |
| 963 | } |
| 964 | |
| 965 | ok, found := containsElement(s, contains) |
| 966 | if !ok { |
| 967 | return Fail(t, fmt.Sprintf("%#v could not be applied builtin len()", s), msgAndArgs...) |
| 968 | } |
| 969 | if !found { |
| 970 | return Fail(t, fmt.Sprintf("%#v does not contain %#v", s, contains), msgAndArgs...) |
| 971 | } |
| 972 | |
| 973 | return true |
| 974 | } |
| 975 | |
| 976 | // NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the |
| 977 | // specified substring or element. |