github.com/searKing/golang/go@v1.2.74/reflect/object_test.go (about) 1 // Copyright 2020 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package reflect 6 7 import ( 8 "testing" 9 "time" 10 ) 11 12 type inputObject struct { 13 a interface{} 14 expect bool 15 } 16 17 func TestValueIsNilObject(t *testing.T) { 18 var nilTime *time.Time 19 ins := []inputObject{ 20 { 21 a: nil, 22 expect: true, 23 }, 24 { 25 a: true, 26 expect: false, 27 }, 28 { 29 a: 0, 30 expect: false, 31 }, 32 { 33 a: "", 34 expect: false, 35 }, 36 { 37 a: time.Now(), 38 expect: false, 39 }, 40 { 41 a: nilTime, 42 expect: true, 43 }, 44 } 45 for idx, in := range ins { 46 if IsNilObject(in.a) != in.expect { 47 t.Errorf("#%d expect %t", idx, in.expect) 48 } 49 } 50 }