slice_array_test.go 1.1 KB

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