map_key_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // +build go1.15
  2. // remove these tests temporarily until https://github.com/golang/go/issues/38105 and
  3. // https://github.com/golang/go/issues/38940 is fixed
  4. package test
  5. import (
  6. "encoding"
  7. "strings"
  8. )
  9. func init() {
  10. testCases = append(testCases,
  11. (*map[stringKeyType]string)(nil),
  12. (*map[structKeyType]string)(nil),
  13. )
  14. }
  15. type stringKeyType string
  16. func (k stringKeyType) MarshalText() ([]byte, error) {
  17. return []byte("MANUAL__" + k), nil
  18. }
  19. func (k *stringKeyType) UnmarshalText(text []byte) error {
  20. *k = stringKeyType(strings.TrimPrefix(string(text), "MANUAL__"))
  21. return nil
  22. }
  23. var _ encoding.TextMarshaler = stringKeyType("")
  24. var _ encoding.TextUnmarshaler = new(stringKeyType)
  25. type structKeyType struct {
  26. X string
  27. }
  28. func (k structKeyType) MarshalText() ([]byte, error) {
  29. return []byte("MANUAL__" + k.X), nil
  30. }
  31. func (k *structKeyType) UnmarshalText(text []byte) error {
  32. k.X = strings.TrimPrefix(string(text), "MANUAL__")
  33. return nil
  34. }
  35. var _ encoding.TextMarshaler = structKeyType{}
  36. var _ encoding.TextUnmarshaler = &structKeyType{}