github.com/Accefy/pop@v0.0.0-20230428174248-e9f677eab5b9/associations/association_test.go (about)

     1  package associations
     2  
     3  import (
     4  	"database/sql"
     5  	"fmt"
     6  	"github.com/gobuffalo/nulls"
     7  	"github.com/gofrs/uuid"
     8  	"github.com/stretchr/testify/assert"
     9  	"testing"
    10  )
    11  
    12  func Test_IsZeroOfUnderlyingType(t *testing.T) {
    13  	for k, tc := range []struct {
    14  		in   interface{}
    15  		zero bool
    16  	}{
    17  		{in: nil, zero: true},
    18  		{in: 0, zero: true},
    19  		{in: 1, zero: false},
    20  		{in: false, zero: true},
    21  		{in: "", zero: true},
    22  		{in: interface{}(nil), zero: true},
    23  		{in: uuid.NullUUID{}, zero: true},
    24  		{in: uuid.UUID{}, zero: true},
    25  		{in: uuid.NullUUID{Valid: true}, zero: false},
    26  		{in: nulls.Int{}, zero: true},
    27  		{in: nulls.String{}, zero: true},
    28  		{in: nulls.Bool{}, zero: true},
    29  		{in: nulls.Float64{}, zero: true},
    30  		{in: sql.NullString{}, zero: true},
    31  		{in: sql.NullString{Valid: true}, zero: false},
    32  	} {
    33  		t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) {
    34  			assert.EqualValues(t, tc.zero, IsZeroOfUnderlyingType(tc.in))
    35  		})
    36  	}
    37  }