github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/reflect2/test/map_elem_struct_test.go (about) 1 package test 2 3 import ( 4 "testing" 5 "github.com/v2pro/plz/reflect2" 6 "time" 7 ) 8 9 func Test_map_elem_struct(t *testing.T) { 10 t.Run("SetIndex", testOp(func(api reflect2.API) interface{} { 11 obj := map[int]time.Time{} 12 valType := api.TypeOf(obj).(reflect2.MapType) 13 valType.SetIndex(obj, 2, time.Time{}) 14 valType.SetIndex(obj, 3, time.Time{}) 15 return obj 16 })) 17 t.Run("SetIndex single ptr struct", testOp(func(api reflect2.API) interface{} { 18 type TestObject struct { 19 Field1 *int 20 } 21 obj := map[int]TestObject{} 22 valType := api.TypeOf(obj).(reflect2.MapType) 23 valType.SetIndex(obj, 2, TestObject{}) 24 valType.SetIndex(obj, 3, TestObject{}) 25 return obj 26 })) 27 t.Run("SetIndex single map struct", testOp(func(api reflect2.API) interface{} { 28 type TestObject struct { 29 Field1 map[int]int 30 } 31 obj := map[int]TestObject{} 32 valType := api.TypeOf(obj).(reflect2.MapType) 33 valType.SetIndex(obj, 2, TestObject{}) 34 valType.SetIndex(obj, 3, TestObject{}) 35 return obj 36 })) 37 t.Run("SetIndex single chan struct", testOp(func(api reflect2.API) interface{} { 38 type TestObject struct { 39 Field1 chan int 40 } 41 obj := map[int]TestObject{} 42 valType := api.TypeOf(obj).(reflect2.MapType) 43 valType.SetIndex(obj, 2, TestObject{}) 44 valType.SetIndex(obj, 3, TestObject{}) 45 return obj 46 })) 47 t.Run("SetIndex single func struct", testOp(func(api reflect2.API) interface{} { 48 type TestObject struct { 49 Field1 func() 50 } 51 obj := map[int]TestObject{} 52 valType := api.TypeOf(obj).(reflect2.MapType) 53 valType.SetIndex(obj, 2, TestObject{}) 54 valType.SetIndex(obj, 3, TestObject{}) 55 return obj 56 })) 57 }