Closed Neirpyc closed 2 years ago
Okay, hum I made ugly commits, tried to make it better, made it worse xD Gotta learn a bit more how git works x)
Could we get any feedback on this? I believe this is a bug fix as the current behavior seems unconsistent, and that's a less than 20 lines fix...
thx for the contribution @Neirpyc!
I've checked how testify does this and it seems like we could be comprehensive and also add other types like chan
and map
(ref https://github.com/stretchr/testify/blob/master/assert/assertions.go#L525-L536)
WDYT?
Yes you're right, I didn't think about that.
This should be fixed now :)
Previously, such code would fail:
This is because a nil slice is not a nil pointer. Therefore, to know if an
interface{}
is a nil slice, we can check wether it is a slice or not withreflect.TypeOf(a.src).Kind() == reflect.Slice
. In case it is a slice, we can usereflect.ValueOf(a.src).IsNil()
to know if a slice is nil or not.This PR also adds two test functions
TestIsNilWithSlice
andTestIsNotNilWithSlice
.