slice_string_test.go 385 B

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