This repository was archived by the owner on Feb 17, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -60,3 +60,13 @@ func (x FluentObj[T]) Zero() FailureMessage {
6060 }
6161 return FailureMessage ("not a zero value (-want +got):\n " + diff )
6262}
63+
64+ // NonZero tests if the object is a non-zero value.
65+ func (x FluentObj [T ]) NonZero () FailureMessage {
66+ var want T
67+ ok := cmp .Equal (want , x .Got )
68+ if ! ok {
69+ return ""
70+ }
71+ return FailureMessage ("a zero value" )
72+ }
Original file line number Diff line number Diff line change @@ -71,6 +71,24 @@ func TestObj(t *testing.T) {
7171 })
7272 })
7373
74+ t .Run ("NonZero" , func (t * testing.T ) {
75+ t .Run ("Passed" , func (t * testing.T ) {
76+ got := A {Str : "string" }
77+ msg := f .Obj (got ).NonZero ()
78+ assertPassed (t , msg )
79+ })
80+ t .Run ("Failed" , func (t * testing.T ) {
81+ got := A {}
82+ msg := f .Obj (got ).NonZero ()
83+ assertFailed (t , msg , "a zero value" )
84+ })
85+ t .Run ("nil" , func (t * testing.T ) {
86+ var got * A
87+ msg := f .Obj (got ).NonZero ()
88+ assertFailed (t , msg , "a zero value" )
89+ })
90+ })
91+
7492 t .Run ("Check" , func (t * testing.T ) {
7593 t .Run ("Passed" , func (t * testing.T ) {
7694 fn := func (x A ) string {
You can’t perform that action at this time.
0 commit comments