@@ -41,7 +41,7 @@ func (x FluentMap[K, V]) Contain(want map[K]V, opts ...cmp.Option) FailureMessag
4141 return FailureMessage (fmt .Sprintf ("not contains all pairs\n got: %+v\n want: %+v\n missing: %+v" , x .Got , want , missing ))
4242}
4343
44- // NotContain tests if the slice does not have the same element as want in any order .
44+ // NotContain tests if the map does not contains all pairs from want.
4545func (x FluentMap [K , V ]) NotContain (want map [K ]V , opts ... cmp.Option ) FailureMessage {
4646 missing := x .miss (want , opts )
4747 if len (missing ) > 0 {
@@ -66,20 +66,56 @@ func (x FluentMap[K, V]) miss(want map[K]V, opts []cmp.Option) map[K]V {
6666 return missing
6767}
6868
69- // TODO: Contain(elements map[K]V) FailureMessage
70-
71- // TODO: NotContain(elements map[K]V) FailureMessage
72-
73- // TODO: ContainKey(keys ...K) FailureMessage
74-
75- // TODO: NotContainKey(keys ...K) FailureMessage
76-
77- // TODO: ContainPair(K,V) FailureMessage
69+ // ContainPair tests if the map contains the pair.
70+ func (x FluentMap [K , V ]) ContainPair (k K , v V , opts ... cmp.Option ) FailureMessage {
71+ got , ok := x .Got [k ]
72+ if ! ok {
73+ return FailureMessage (fmt .Sprintf ("has no value under key\n got: %+v\n key: %+v\n value: %+v" , x .Got , k , v ))
74+ }
75+ if ! cmp .Equal (v , got , opts ... ) {
76+ return FailureMessage (fmt .Sprintf ("has different value under key\n key: %+v\n got: %+v\n want: %+v" , k , got , v ))
77+ }
78+ return ""
79+ }
7880
79- // TODO: NotContainPair(K,V) FailureMessage
81+ // NotContainPair tests if the map does not contain the pair.
82+ func (x FluentMap [K , V ]) NotContainPair (k K , v V , opts ... cmp.Option ) FailureMessage {
83+ got , ok := x .Got [k ]
84+ if ! ok {
85+ return ""
86+ }
87+ if ! cmp .Equal (v , got , opts ... ) {
88+ return ""
89+ }
90+ return FailureMessage (fmt .Sprintf ("contains the pair\n got: %+v\n key: %+v\n value: %+v" , x .Got , k , v ))
91+ }
8092
81- // TODO: Any(func(K,V) bool) FailureMessage
93+ // Any tests if any of the slice's item meets the predicate criteria.
94+ func (x FluentMap [K , V ]) Any (predicate func (K , V ) bool ) FailureMessage {
95+ for k , v := range x .Got {
96+ if predicate (k , v ) {
97+ return ""
98+ }
99+ }
100+ return FailureMessage (fmt .Sprintf ("none pair does meet the predicate criteria\n got: %+v" , x .Got ))
101+ }
82102
83- // TODO: All(func(K,V) bool) FailureMessage
103+ // All tests if all of the slice's items meets the predicate criteria.
104+ func (x FluentMap [K , V ]) All (predicate func (K , V ) bool ) FailureMessage {
105+ for k , v := range x .Got {
106+ if ! predicate (k , v ) {
107+ return FailureMessage (fmt .Sprintf ("a pair does not meet the predicate criteria\n got: %+v\n pair: %+v" , x .Got , v ))
108+ }
109+ }
110+ return ""
111+ }
84112
85- // TODO: None(func(K,V) bool) FailureMessage
113+ // None tests if all of the slice's item does not meet the predicate criteria.
114+ func (x FluentMap [K , V ]) None (predicate func (K , V ) bool ) FailureMessage {
115+ for k , v := range x .Got {
116+ if predicate (k , v ) {
117+ return FailureMessage (fmt .Sprintf ("a pair meets the predicate criteria\n got: %+v\n pair: %+v" , x .Got , v ))
118+ }
119+ }
120+ return ""
121+ }
0 commit comments