Debian Codegraph @

type_tests/map_key_test.go

raw
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
5 package test
6
7 import (
8 "encoding"
9 "strings"
10 )
11
12 func init() {
13 testCases = append(testCases,
14 (*map[stringKeyType]string)(nil),
15 (*map[structKeyType]string)(nil),
16 )
17 }
18
19 type stringKeyType string
20
21 func (k stringKeyType) MarshalText() ([]byte, error) {
22 return []byte("MANUAL__" + k), nil
23 }
24
25 func (k *stringKeyType) UnmarshalText(text []byte) error {
26 *k = stringKeyType(strings.TrimPrefix(string(text), "MANUAL__"))
27 return nil
28 }
29
30 var _ encoding.TextMarshaler = stringKeyType("")
31 var _ encoding.TextUnmarshaler = new(stringKeyType)
32
33 type structKeyType struct {
34 X string
35 }
36
37 func (k structKeyType) MarshalText() ([]byte, error) {
38 return []byte("MANUAL__" + k.X), nil
39 }
40
41 func (k *structKeyType) UnmarshalText(text []byte) error {
42 k.X = strings.TrimPrefix(string(text), "MANUAL__")
43 return nil
44 }
45
46 var _ encoding.TextMarshaler = structKeyType{}
47 var _ encoding.TextUnmarshaler = &structKeyType{}