github.com/go4org/go4@v0.0.0-20200104003542-c7e774b10ea0/reflectutil/reflectutil_test.go (about) 1 // Copyright 2016 The Go Authors. 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 reflectutil 6 7 import ( 8 "reflect" 9 "testing" 10 ) 11 12 func TestHasPointers(t *testing.T) { 13 tests := []struct { 14 val interface{} 15 want bool 16 }{ 17 {false, false}, 18 {int(1), false}, 19 {int8(1), false}, 20 {int16(1), false}, 21 {int32(1), false}, 22 {int64(1), false}, 23 {uint(1), false}, 24 {uint8(1), false}, 25 {uint16(1), false}, 26 {uint32(1), false}, 27 {uint64(1), false}, 28 {uintptr(1), false}, 29 {float32(1.0), false}, 30 {float64(1.0), false}, 31 {complex64(1.0i), false}, 32 {complex128(1.0i), false}, 33 34 {[...]int{1, 2}, false}, 35 {[...]*int{nil, nil}, true}, 36 37 {make(chan bool), true}, 38 39 {TestHasPointers, true}, 40 41 {map[string]string{"foo": "bar"}, true}, 42 43 {new(int), true}, 44 45 {[]int{1, 2}, true}, 46 47 {"foo", true}, 48 49 {struct{}{}, false}, 50 {struct{ int }{0}, false}, 51 {struct { 52 a int 53 b bool 54 }{0, false}, false}, 55 {struct { 56 a int 57 b string 58 }{0, ""}, true}, 59 {struct{ *int }{nil}, true}, 60 {struct { 61 a *int 62 b int 63 }{nil, 0}, true}, 64 } 65 for i, tt := range tests { 66 got := hasPointers(reflect.TypeOf(tt.val)) 67 if got != tt.want { 68 t.Errorf("%d. hasPointers(%T) = %v; want %v", i, tt.val, got, tt.want) 69 } 70 } 71 }