@@ -20,4 +20,110 @@ func TestSlice(t *testing.T) {
2020 got := verify .Slice (want ).FluentAny .Got // type embedding done properly
2121 assertEqual (t , got , want )
2222 })
23+
24+ t .Run ("Empty" , func (t * testing.T ) {
25+ t .Run ("Passed" , func (t * testing.T ) {
26+ got := verify .Slice ([]A {}).Empty ()
27+ assertPassed (t , got )
28+ })
29+ t .Run ("Failed" , func (t * testing.T ) {
30+ got := verify .Slice ([]A {{}}).Empty ()
31+ assertFailed (t , got , "not an empty slice" )
32+ })
33+ })
34+ t .Run ("NotEmpty" , func (t * testing.T ) {
35+ t .Run ("Passed" , func (t * testing.T ) {
36+ got := verify .Slice ([]A {{}}).NotEmpty ()
37+ assertPassed (t , got )
38+ })
39+ t .Run ("Failed" , func (t * testing.T ) {
40+ got := verify .Slice ([]A {}).NotEmpty ()
41+ assertFailed (t , got , "an empty slice" )
42+ })
43+ })
44+
45+ list := []A {
46+ {Str : "text" , Bool : true , Slice : []int {1 , 2 , 3 }},
47+ {Slice : []int {9 , 8 , 7 }},
48+ }
49+ eq := []A {
50+ {Slice : []int {9 , 8 , 7 }},
51+ {Str : "text" , Bool : true , Slice : []int {1 , 2 , 3 }},
52+ }
53+ notEq := []A {
54+ {Slice : []int {0 , 0 , 0 }},
55+ {Str : "text" , Bool : true , Slice : []int {1 , 2 , 3 }},
56+ }
57+ t .Run ("Equivalent" , func (t * testing.T ) {
58+ t .Run ("Passed" , func (t * testing.T ) {
59+ got := verify .Slice (list ).Equivalent (eq )
60+ assertPassed (t , got )
61+ })
62+ t .Run ("Failed" , func (t * testing.T ) {
63+ got := verify .Slice (list ).Equivalent (notEq )
64+ assertFailed (t , got , "not equivalent" )
65+ })
66+ })
67+ t .Run ("NotEquivalent" , func (t * testing.T ) {
68+ t .Run ("Passed" , func (t * testing.T ) {
69+ got := verify .Slice (list ).NotEquivalent (notEq )
70+ assertPassed (t , got )
71+ })
72+ t .Run ("Failed" , func (t * testing.T ) {
73+ got := verify .Slice (list ).NotEquivalent (eq )
74+ assertFailed (t , got , "equivalent" )
75+ })
76+ })
77+
78+ t .Run ("Contain" , func (t * testing.T ) {
79+ t .Run ("Passed" , func (t * testing.T ) {
80+ got := verify .Slice (list ).Contain (A {Str : "text" , Bool : true , Slice : []int {1 , 2 , 3 }})
81+ assertPassed (t , got )
82+ })
83+ t .Run ("Failed" , func (t * testing.T ) {
84+ got := verify .Slice (list ).Contain (A {})
85+ assertFailed (t , got , "slice does not contain the item" )
86+ })
87+ })
88+ t .Run ("NotContain" , func (t * testing.T ) {
89+ t .Run ("Passed" , func (t * testing.T ) {
90+ got := verify .Slice (list ).NotContain (A {})
91+ assertPassed (t , got )
92+ })
93+ t .Run ("Failed" , func (t * testing.T ) {
94+ got := verify .Slice (list ).NotContain (A {Str : "text" , Bool : true , Slice : []int {1 , 2 , 3 }})
95+ assertFailed (t , got , "slice contains the item" )
96+ })
97+ })
98+
99+ t .Run ("Any" , func (t * testing.T ) {
100+ t .Run ("Passed" , func (t * testing.T ) {
101+ got := verify .Slice (list ).Any (func (a A ) bool { return true })
102+ assertPassed (t , got )
103+ })
104+ t .Run ("Failed" , func (t * testing.T ) {
105+ got := verify .Slice (list ).Any (func (a A ) bool { return false })
106+ assertFailed (t , got , "none item does meet the predicate criteria" )
107+ })
108+ })
109+ t .Run ("All" , func (t * testing.T ) {
110+ t .Run ("Passed" , func (t * testing.T ) {
111+ got := verify .Slice (list ).All (func (a A ) bool { return true })
112+ assertPassed (t , got )
113+ })
114+ t .Run ("Failed" , func (t * testing.T ) {
115+ got := verify .Slice (list ).All (func (a A ) bool { return false })
116+ assertFailed (t , got , "an item does not meet the predicate criteria" )
117+ })
118+ })
119+ t .Run ("None" , func (t * testing.T ) {
120+ t .Run ("Passed" , func (t * testing.T ) {
121+ got := verify .Slice (list ).None (func (a A ) bool { return false })
122+ assertPassed (t , got )
123+ })
124+ t .Run ("Failed" , func (t * testing.T ) {
125+ got := verify .Slice (list ).None (func (a A ) bool { return true })
126+ assertFailed (t , got , "an item meets the predicate criteria" )
127+ })
128+ })
23129}
0 commit comments