@@ -60,8 +60,42 @@ $ go test
60
60
want: " ok"
61
61
```
62
62
63
+ ⚠ Do not forget calling
64
+ [ ` Assert(t) ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#FailureMessage.Assert )
65
+ or [ ` Require(t) ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#FailureMessage.Require )
66
+ which executes the actual assertion.
67
+
68
+ ## Supported types
69
+
70
+ Out-of-the-box the package provides fluent assertions for the following types.
71
+ The more specific function you use, the more assertions you get.
72
+
73
+ | Go type | Assertion entry point |
74
+ | - | - |
75
+ | ` interface{} ` ([ ` any ` ] ( https://pkg.go.dev/builtin#any ) ) | [ ` verify.Any() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#Any ) |
76
+ | [ ` comparable ` ] ( https://pkg.go.dev/builtin#comparable ) | [ ` verify.Obj() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#Obj ) |
77
+ | [ ` constraints.Ordered ` ] ( https://pkg.go.dev/golang.org/x/exp/constraints#Ordered ) | [ ` verify.Ordered() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#Ordered ) |
78
+ | [ ` constraints.Number ` ] ( https://pkg.go.dev/golang.org/x/exp/constraints#Number ) | [ ` verify.Number() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#Number ) |
79
+ | [ ` string ` ] ( https://pkg.go.dev/builtin#string ) | [ ` verify.String() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#String ) |
80
+ | [ ` error ` ] ( https://go.dev/ref/spec#Errors ) | [ ` verify.Error() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#Error ) |
81
+ | ` []T ` ([ slice] ( https://go.dev/ref/spec#Slice_types ) ) | [ ` verify.Slice() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#Slice ) |
82
+ | ` map[K]V ` ([ map] ( https://go.dev/ref/spec#Map_types ) ) | [ ` verify.Map() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#Map ) |
83
+
84
+ Below you can find some convenience functions.
85
+
86
+ - [ ` verify.NoError() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#NoError )
87
+ - [ ` verify.IsError() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#IsError )
88
+ - [ ` verify.Nil() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#Nil )
89
+ - [ ` verify.NotNil() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#NotNil )
90
+ - [ ` verify.True() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#True )
91
+ - [ ` verify.False() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#False )
92
+
63
93
### Deep equality
64
94
95
+ For testing deep equality use
96
+ [ ` DeepEqual() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#FluentAny.DeepEqual )
97
+ or [ ` NotDeepEqual() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#FluentAny.NotDeepEqual ) .
98
+
65
99
``` go
66
100
package test
67
101
@@ -104,7 +138,10 @@ $ go test
104
138
}
105
139
```
106
140
107
- ### Collection unordered equality
141
+ ### Collection assertions
142
+
143
+ The library contains many collection assertion.
144
+ Below is an example of checking unordered equality.
108
145
109
146
``` go
110
147
package test
@@ -135,6 +172,10 @@ $ go test
135
172
136
173
### Periodic polling
137
174
175
+ For asynchronous testing you can use
176
+ [ ` verify.Eventually() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#Eventually )
177
+ or [ ` verify.EventuallyChan() ` ] ( https://pkg.go.dev/github.com/fluentassert/verify#EventuallyChan ) .
178
+
138
179
``` go
139
180
package test
140
181
@@ -166,12 +207,13 @@ $ go test
166
207
Get " http://not-existing:1234" : context deadline exceeded (Client.Timeout exceeded while awaiting headers)
167
208
` ` `
168
209
169
- # # Extensibility
170
-
171
210
# ## Custom predicates
172
211
173
212
For the most basic scenarios, you can use one of the
174
- ` Check` , ` Should` , ` ShouldNot` assertions.
213
+ [` Check()` ](https://pkg.go.dev/github.com/fluentassert/verify#FluentAny.Check),
214
+ [` Should()` ](https://pkg.go.dev/github.com/fluentassert/verify#FluentAny.Should),
215
+ [` ShouldNot()` ](https://pkg.go.dev/github.com/fluentassert/verify#FluentAny.ShouldNot)
216
+ assertions.
175
217
176
218
` ` ` go
177
219
package test
@@ -201,11 +243,18 @@ $ go test
201
243
got: " wrong"
202
244
` ` `
203
245
246
+ # ## Panics
247
+
248
+ For testing panics use [` verify.Panics()` ](https://pkg.go.dev/github.com/fluentassert/verify#Panics)
249
+ and [` verify.NotPanics()` ](https://pkg.go.dev/github.com/fluentassert/verify#NotPanics).
250
+
204
251
# ## Custom assertion function
205
252
206
- You can create a function that returns ` FailureMessage` .
207
- Use ` And` and ` Or` functions together with ` FailureMessage.Prefix` method
208
- to create complex assertions.
253
+ You can create a function that returns [` FailureMessage` ](https://pkg.go.dev/github.com/fluentassert/verify#FailureMessage).
254
+ Use [` verify.And()` ](https://pkg.go.dev/github.com/fluentassert/verify#And)
255
+ and [` verify.Or()` ](https://pkg.go.dev/github.com/fluentassert/verify#Or)
256
+ functions together with [` Prefix()` ](https://pkg.go.dev/github.com/fluentassert/verify#FailureMessage.Prefix)
257
+ method to create complex assertions.
209
258
210
259
` ` ` go
211
260
package test
@@ -246,9 +295,10 @@ $ go test
246
295
got.Ok: the value is false
247
296
` ` `
248
297
249
- # ## Custom fluent assertions
298
+ # # Extensibility
250
299
251
- You can take advantage of the ` FailureMessage` and ` Fluent* ` types
300
+ You can take advantage of the [` FailureMessage` ](https://pkg.go.dev/github.com/fluentassert/verify#FailureMessage)
301
+ and ` Fluent* ` types
252
302
to create your own fluent assertions for a given type.
253
303
254
304
For reference, take a look at the implementation
0 commit comments