github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/reflect2/test/map_elem_array_test.go (about) 1 package test 2 3 import ( 4 "testing" 5 "github.com/v2pro/plz/reflect2" 6 ) 7 8 func Test_map_elem_array(t *testing.T) { 9 t.Run("SetIndex", testOp(func(api reflect2.API) interface{} { 10 obj := map[int][2]*int{} 11 valType := api.TypeOf(obj).(reflect2.MapType) 12 valType.SetIndex(obj, 2, [2]*int{(*int)(reflect2.PtrOf(1)), (*int)(reflect2.PtrOf(2))}) 13 valType.SetIndex(obj, 3, [2]*int{(*int)(reflect2.PtrOf(3)), (*int)(reflect2.PtrOf(4))}) 14 return obj 15 })) 16 t.Run("SetIndex zero length array", testOp(func(api reflect2.API) interface{} { 17 obj := map[int][0]*int{} 18 valType := api.TypeOf(obj).(reflect2.MapType) 19 valType.SetIndex(obj, 2, [0]*int{}) 20 valType.SetIndex(obj, 3, [0]*int{}) 21 return obj 22 })) 23 t.Run("SetIndex single ptr array", testOp(func(api reflect2.API) interface{} { 24 obj := map[int][1]*int{} 25 valType := api.TypeOf(obj).(reflect2.MapType) 26 valType.SetIndex(obj, 2, [1]*int{(*int)(reflect2.PtrOf(1))}) 27 valType.SetIndex(obj, 3, [1]*int{}) 28 return obj 29 })) 30 t.Run("SetIndex single chan array", testOp(func(api reflect2.API) interface{} { 31 obj := map[int][1]chan int{} 32 valType := api.TypeOf(obj).(reflect2.MapType) 33 valType.SetIndex(obj, 2, [1]chan int{}) 34 valType.SetIndex(obj, 3, [1]chan int{}) 35 return obj 36 })) 37 t.Run("SetIndex single func array", testOp(func(api reflect2.API) interface{} { 38 obj := map[int][1]func(){} 39 valType := api.TypeOf(obj).(reflect2.MapType) 40 valType.SetIndex(obj, 2, [1]func(){}) 41 valType.SetIndex(obj, 3, [1]func(){}) 42 return obj 43 })) 44 }