map_elem_array_test.go 1.5 KB

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