Skip to content

Commit 121ddb9

Browse files
committed
clarify behavior of Subset/NotSubset when passing maps
1 parent 2a9c44b commit 121ddb9

File tree

5 files changed

+96
-40
lines changed

5 files changed

+96
-40
lines changed

assert/assertion_format.go

Lines changed: 12 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assert/assertion_forward.go

Lines changed: 24 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assert/assertions.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -982,11 +982,15 @@ func NotContains(t TestingT, s, contains interface{}, msgAndArgs ...interface{})
982982

983983
}
984984

985-
// Subset asserts that the specified list(array, slice...) or map contains all
986-
// elements given in the specified subset list(array, slice...) or map.
985+
// Subset asserts that the list (array, slice, or map) contains all elements
986+
// given in the subset (array, slice, or map).
987+
// Map elements are key-value pairs unless compared with an array or slice where
988+
// only the map key is evaluated.
987989
//
988990
// assert.Subset(t, [1, 2, 3], [1, 2])
989991
// assert.Subset(t, {"x": 1, "y": 2}, {"x": 1})
992+
// assert.Subset(t, [1, 2, 3], {1: "one", 2: "two"})
993+
// assert.Subset(t, {"x": 1, "y": 2}, ["x"])
990994
func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok bool) {
991995
if h, ok := t.(tHelper); ok {
992996
h.Helper()
@@ -1046,12 +1050,15 @@ func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok
10461050
return true
10471051
}
10481052

1049-
// NotSubset asserts that the specified list(array, slice...) or map does NOT
1050-
// contain all elements given in the specified subset list(array, slice...) or
1051-
// map.
1053+
// NotSubset asserts that the list (array, slice, or map) does NOT contain all
1054+
// elements given in the subset (array, slice, or map).
1055+
// Map elements are key-value pairs unless compared with an array or slice where
1056+
// only the map key is evaluated.
10521057
//
10531058
// assert.NotSubset(t, [1, 3, 4], [1, 2])
10541059
// assert.NotSubset(t, {"x": 1, "y": 2}, {"z": 3})
1060+
// assert.NotSubset(t, [1, 3, 4], {1: "one", 2: "two"})
1061+
// assert.NotSubset(t, {"x": 1, "y": 2}, ["z"])
10551062
func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok bool) {
10561063
if h, ok := t.(tHelper); ok {
10571064
h.Helper()

require/require.go

Lines changed: 24 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

require/require_forward.go

Lines changed: 24 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)