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