Skip to content

Commit

Permalink
Add flag test
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap committed Oct 20, 2024
1 parent 219a55d commit c08932c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flag_slice_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (i *SliceBase[T, C, VC]) Serialize() string {
// Value returns the slice of values set by this flag
func (i *SliceBase[T, C, VC]) Value() []T {
if i.slice == nil {
return []T{}
return nil
}
return *i.slice
}
Expand Down
5 changes: 5 additions & 0 deletions flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3036,4 +3036,9 @@ func TestSliceValuesNil(t *testing.T) {
assert.Equal(t, []int64(nil), NewIntSlice().Value())
assert.Equal(t, []uint64(nil), NewUintSlice().Value())
assert.Equal(t, []string(nil), NewStringSlice().Value())

assert.Equal(t, []float64(nil), (&FloatSlice{}).Value())
assert.Equal(t, []int64(nil), (&IntSlice{}).Value())
assert.Equal(t, []uint64(nil), (&UintSlice{}).Value())
assert.Equal(t, []string(nil), (&StringSlice{}).Value())
}

0 comments on commit c08932c

Please sign in to comment.