slice_bytes_test.go 417 B

123456789101112131415161718
  1. package tests
  2. import (
  3. "github.com/modern-go/reflect2"
  4. "testing"
  5. )
  6. func Test_slice_bytes(t *testing.T) {
  7. t.Run("SetIndex", testOp(func(api reflect2.API) interface{} {
  8. obj := [][]byte{[]byte("hello"), []byte("world")}
  9. valType := api.TypeOf(obj).(reflect2.SliceType)
  10. elem1 := []byte("hi")
  11. valType.SetIndex(&obj, 0, &elem1)
  12. elem2 := []byte("there")
  13. valType.SetIndex(&obj, 1, &elem2)
  14. return obj
  15. }))
  16. }