Codebase list golang-github-mailru-easyjson / 7169726
[tests] added tests for key text marshaler Aleksandr Petrukhin 5 years ago
3 changed file(s) with 23 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
2525 .root/src/$(PKG)/tests/named_type.go \
2626 .root/src/$(PKG)/tests/custom_map_key_type.go \
2727 .root/src/$(PKG)/tests/embedded_type.go \
28 .root/src/$(PKG)/tests/reference_to_pointer.go
28 .root/src/$(PKG)/tests/reference_to_pointer.go \
2929
3030 .root/bin/easyjson -all .root/src/$(PKG)/tests/data.go
3131 .root/bin/easyjson -all .root/src/$(PKG)/tests/nothing.go
3838 .root/bin/easyjson .root/src/$(PKG)/tests/custom_map_key_type.go
3939 .root/bin/easyjson .root/src/$(PKG)/tests/embedded_type.go
4040 .root/bin/easyjson .root/src/$(PKG)/tests/reference_to_pointer.go
41 .root/bin/easyjson .root/src/$(PKG)/tests/key_marshaler_map.go
4142 .root/bin/easyjson -disallow_unknown_fields .root/src/$(PKG)/tests/disallow_unknown.go
4243
4344 test: generate root
5151 {&intArrayStructValue, intArrayStructValueString},
5252 {&myUInt8SliceValue, myUInt8SliceString},
5353 {&myUInt8ArrayValue, myUInt8ArrayString},
54 {&mapWithEncodingMarshaler, mapWithEncodingMarshalerString},
5455 }
5556
5657 func TestMarshal(t *testing.T) {
0 package tests
1
2 type KeyWithEncodingMarshaler int
3
4 func (f KeyWithEncodingMarshaler) MarshalText() (text []byte, err error) {
5 return []byte("hello"), nil
6 }
7
8 func (f *KeyWithEncodingMarshaler) UnmarshalText(text []byte) error {
9 if string(text) == "hello" {
10 *f = 5
11 }
12 return nil
13 }
14
15 //easyjson:json
16 type KeyWithEncodingMarshalers map[KeyWithEncodingMarshaler]string
17
18 var mapWithEncodingMarshaler KeyWithEncodingMarshalers = KeyWithEncodingMarshalers{5: "hello"}
19 var mapWithEncodingMarshalerString = `{"hello":"hello"}`