This repository has been archived by the owner on Feb 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package verify | ||
|
||
import "fmt" | ||
|
||
// Nil tests if provided interface value is nil. | ||
// Use it only for interfaces. | ||
// For structs and pointers use Obj(got).Zero(). | ||
func Nil(v interface{}) FailureMessage { | ||
if v == nil { | ||
return "" | ||
} | ||
return FailureMessage(fmt.Sprintf("value is not nil\ngot: %+v", v)) | ||
} | ||
|
||
// NotNil tests if provided interface is not nil. | ||
// Use it only for interfaces. | ||
// For structs and pointers use Obj(got).NonZero(). | ||
func NotNil(v any) FailureMessage { | ||
if v != nil { | ||
return "" | ||
} | ||
return "value is <nil>" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package verify_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/fluentassert/verify" | ||
) | ||
|
||
func TestNil(t *testing.T) { | ||
t.Run("Passed", func(t *testing.T) { | ||
var err error | ||
msg := verify.Nil(err) | ||
assertPassed(t, msg) | ||
}) | ||
t.Run("Failed", func(t *testing.T) { | ||
msg := verify.Nil(0) | ||
assertFailed(t, msg, "value is not nil") | ||
}) | ||
} | ||
|
||
func TestNotNil(t *testing.T) { | ||
t.Run("Passed", func(t *testing.T) { | ||
msg := verify.NotNil(0) | ||
assertPassed(t, msg) | ||
}) | ||
t.Run("Failed", func(t *testing.T) { | ||
var err error | ||
msg := verify.NotNil(err) | ||
assertFailed(t, msg, "value is <nil>") | ||
}) | ||
} |