fieldoptions_test.go 553 B

12345678910111213141516171819202122232425262728293031
  1. package mapping
  2. import (
  3. "reflect"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. type Bar struct {
  8. Val string `json:"val"`
  9. }
  10. func TestFieldOptionOptionalDep(t *testing.T) {
  11. var bar Bar
  12. rt := reflect.TypeOf(bar)
  13. for i := 0; i < rt.NumField(); i++ {
  14. field := rt.Field(i)
  15. val, opt, err := parseKeyAndOptions(jsonTagKey, field)
  16. assert.Equal(t, "val", val)
  17. assert.Nil(t, opt)
  18. assert.Nil(t, err)
  19. }
  20. // check nil working
  21. var o *fieldOptions
  22. check := func(o *fieldOptions) {
  23. assert.Equal(t, 0, len(o.optionalDep()))
  24. }
  25. check(o)
  26. }