This repository was archived by the owner on Feb 17, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed
Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ The main additions are the new assertions for
1919### Added
2020
2121- Add ` True ` , ` False ` , assertion functions.
22+ - Add ` Nil ` , ` NotNil ` , assertion functions.
2223- Add ` NoError ` , ` IsError ` assertion functions.
2324- Add ` Panics ` , ` NoPanic ` assertion functions.
2425- Add ` Eventually ` , ` EventuallyChan ` assertion functions.
Original file line number Diff line number Diff line change 1+ package verify
2+
3+ import "fmt"
4+
5+ // Nil tests if provided interface value is nil.
6+ // Use it only for interfaces.
7+ // For structs and pointers use Obj(got).Zero().
8+ func Nil (v interface {}) FailureMessage {
9+ if v == nil {
10+ return ""
11+ }
12+ return FailureMessage (fmt .Sprintf ("value is not nil\n got: %+v" , v ))
13+ }
14+
15+ // NotNil tests if provided interface is not nil.
16+ // Use it only for interfaces.
17+ // For structs and pointers use Obj(got).NonZero().
18+ func NotNil (v any ) FailureMessage {
19+ if v != nil {
20+ return ""
21+ }
22+ return "value is <nil>"
23+ }
Original file line number Diff line number Diff line change 1+ package verify_test
2+
3+ import (
4+ "testing"
5+
6+ "github.com/fluentassert/verify"
7+ )
8+
9+ func TestNil (t * testing.T ) {
10+ t .Run ("Passed" , func (t * testing.T ) {
11+ var err error
12+ msg := verify .Nil (err )
13+ assertPassed (t , msg )
14+ })
15+ t .Run ("Failed" , func (t * testing.T ) {
16+ msg := verify .Nil (0 )
17+ assertFailed (t , msg , "value is not nil" )
18+ })
19+ }
20+
21+ func TestNotNil (t * testing.T ) {
22+ t .Run ("Passed" , func (t * testing.T ) {
23+ msg := verify .NotNil (0 )
24+ assertPassed (t , msg )
25+ })
26+ t .Run ("Failed" , func (t * testing.T ) {
27+ var err error
28+ msg := verify .NotNil (err )
29+ assertFailed (t , msg , "value is <nil>" )
30+ })
31+ }
You can’t perform that action at this time.
0 commit comments