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