Skip to content

Commit

Permalink
add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LukaGiorgadze committed Feb 17, 2025
1 parent ca0921a commit e5a4f42
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
- 🔄 Built-in JSON marshaling/unmarshaling
- 📊 SQL database compatibility
- ✨ Zero dependencies
- 🚀 High performance

## Usage

Expand Down
68 changes: 68 additions & 0 deletions gonull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,3 +793,71 @@ func Test_IsZero(t *testing.T) {
assert.Equal(t, "foo", foo2.Name.Val) // the value was passed, the value is valid
assert.False(t, foo1.ID.IsZero()) // the value is not "zero"
}

func TestNullableScan_Float64(t *testing.T) {
tests := []struct {
name string
value, expected any
Valid bool
Present bool
wantErr bool
}{
{
name: "float64 type",
value: float64(0.25),
expected: float64(0.25),
Valid: true,
Present: true,
},
{
name: "float32 type",
value: float32(0.25),
expected: float64(0.25),
Valid: true,
Present: true,
},
{
name: "[]uint8|[]byte type",
value: []byte("0.25"),
expected: float64(0.25),
Valid: true,
Present: true,
},
{
name: "[]uint8|[]byte type empty",
value: []byte{},
wantErr: true,
Present: true,
},
{
name: "[]uint8|[]byte type non numbers",
value: []byte("not a number"),
wantErr: true,
Present: true,
},
{
name: "unsupported type",
value: []int64{48, 46, 50, 53},
wantErr: true,
Present: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var n Nullable[float64]
err := n.Scan(tt.value)

if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, tt.Valid, n.Valid)
assert.Equal(t, tt.Present, n.Present)
if tt.Valid {
assert.Equal(t, tt.expected, n.Val)
}
}
})
}
}

0 comments on commit e5a4f42

Please sign in to comment.