github.com/searKing/golang/go@v1.2.117/reflect/walk_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 "reflect" 9 "testing" 10 ) 11 12 type output struct { 13 a *bool `json:"MemberA"` 14 b bool 15 c []bool 16 expect bool 17 } 18 type input struct { 19 a bool 20 b bool 21 c []bool 22 expect bool 23 output output 24 } 25 26 func TestWalkStruct(t *testing.T) { 27 var a input 28 var b input 29 if reflect.TypeOf(a) == reflect.TypeOf(b) { 30 t.Logf("typ of a == typ of b") 31 } 32 33 Walk(reflect.TypeOf(input{}), true, func(s reflect.Type, sf reflect.StructField) (stop bool) { 34 t.Logf("typ:%v StructField:%v", s, sf) 35 return false 36 }) 37 } 38 39 func TestWalkBool(t *testing.T) { 40 var a bool 41 var b bool 42 if reflect.TypeOf(a) == reflect.TypeOf(b) { 43 t.Logf("typ of a == typ of b") 44 } 45 Walk(reflect.TypeOf(bool(false)), false, func(s reflect.Type, sf reflect.StructField) (stop bool) { 46 t.Logf("typ:%v StructField:%v", s, sf) 47 return false 48 }) 49 }