pull/232/head
Ernesto Jiménez 2015-11-02 01:41:59 +00:00
parent 8254b8f76b
commit c478a808a1
2 changed files with 10 additions and 0 deletions

View File

@ -358,6 +358,9 @@ func isEmpty(object interface{}) bool {
}
case reflect.Ptr:
{
if objValue.IsNil() {
return true
}
switch object.(type) {
case *time.Time:
return object.(*time.Time).IsZero()

View File

@ -4,6 +4,7 @@ import (
"errors"
"io"
"math"
"os"
"reflect"
"regexp"
"testing"
@ -580,6 +581,9 @@ func TestEmpty(t *testing.T) {
mockT := new(testing.T)
chWithValue := make(chan struct{}, 1)
chWithValue <- struct{}{}
var ti *time.Time
var s *string
var f *os.File
True(t, Empty(mockT, ""), "Empty string is empty")
True(t, Empty(mockT, nil), "Nil is empty")
@ -587,6 +591,9 @@ func TestEmpty(t *testing.T) {
True(t, Empty(mockT, 0), "Zero int value is empty")
True(t, Empty(mockT, false), "False value is empty")
True(t, Empty(mockT, make(chan struct{})), "Channel without values is empty")
True(t, Empty(mockT, s), "Nil string pointer is empty")
True(t, Empty(mockT, f), "Nil os.File pointer is empty")
True(t, Empty(mockT, ti), "Nil time.Time pointer is empty")
False(t, Empty(mockT, "something"), "Non Empty string is not empty")
False(t, Empty(mockT, errors.New("something")), "Non nil object is not empty")