github.com/haraldrudell/parl@v0.4.176/is-nil_test.go (about)

     1  /*
     2  © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package parl
     7  
     8  import "testing"
     9  
    10  func TestIsNil(t *testing.T) {
    11  	// t.Logf("is nil: %t", (any)((*int)(nil)) == nil)
    12  	// t.Logf("IsNil: %t", IsNil((*int)(nil)))
    13  	// t.Fail()
    14  
    15  	var p *int
    16  	var i int
    17  	type args struct {
    18  		v any
    19  	}
    20  	tests := []struct {
    21  		name      string
    22  		args      args
    23  		wantIsNil bool
    24  	}{
    25  		{"one", args{1}, false},
    26  		{"zero", args{0}, false},
    27  		{"false", args{false}, false},
    28  		{"nil", args{nil}, true},
    29  		{"typed nil", args{p}, true},
    30  		{"typed non-nil", args{&i}, false},
    31  	}
    32  	for _, tt := range tests {
    33  		t.Run(tt.name, func(t *testing.T) {
    34  			if gotIsNil := IsNil(tt.args.v); gotIsNil != tt.wantIsNil {
    35  				t.Errorf("IsNil() = %v, want %v", gotIsNil, tt.wantIsNil)
    36  			}
    37  		})
    38  	}
    39  }