| package test |
| |
| import ( |
| "encoding" |
| "strings" |
| ) |
| |
| func init() { |
| testCases = append(testCases, |
| (*map[stringKeyType]string)(nil), |
| (*map[structKeyType]string)(nil), |
| ) |
| } |
| |
| type stringKeyType string |
| |
| func (k stringKeyType) MarshalText() ([]byte, error) { |
| return []byte("MANUAL__" + k), nil |
| } |
| |
| func (k *stringKeyType) UnmarshalText(text []byte) error { |
| *k = stringKeyType(strings.TrimPrefix(string(text), "MANUAL__")) |
| return nil |
| } |
| |
| var _ encoding.TextMarshaler = stringKeyType("") |
| var _ encoding.TextUnmarshaler = new(stringKeyType) |
| |
| type structKeyType struct { |
| X string |
| } |
| |
| func (k structKeyType) MarshalText() ([]byte, error) { |
| return []byte("MANUAL__" + k.X), nil |
| } |
| |
| func (k *structKeyType) UnmarshalText(text []byte) error { |
| k.X = strings.TrimPrefix(string(text), "MANUAL__") |
| return nil |
| } |
| |
| var _ encoding.TextMarshaler = structKeyType{} |
| var _ encoding.TextUnmarshaler = &structKeyType{} |