[tests] added tests for key text marshaler
Aleksandr Petrukhin
5 years ago
25 | 25 |
.root/src/$(PKG)/tests/named_type.go \
|
26 | 26 |
.root/src/$(PKG)/tests/custom_map_key_type.go \
|
27 | 27 |
.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 \
|
29 | 29 |
|
30 | 30 |
.root/bin/easyjson -all .root/src/$(PKG)/tests/data.go
|
31 | 31 |
.root/bin/easyjson -all .root/src/$(PKG)/tests/nothing.go
|
|
38 | 38 |
.root/bin/easyjson .root/src/$(PKG)/tests/custom_map_key_type.go
|
39 | 39 |
.root/bin/easyjson .root/src/$(PKG)/tests/embedded_type.go
|
40 | 40 |
.root/bin/easyjson .root/src/$(PKG)/tests/reference_to_pointer.go
|
|
41 |
.root/bin/easyjson .root/src/$(PKG)/tests/key_marshaler_map.go
|
41 | 42 |
.root/bin/easyjson -disallow_unknown_fields .root/src/$(PKG)/tests/disallow_unknown.go
|
42 | 43 |
|
43 | 44 |
test: generate root
|
51 | 51 |
{&intArrayStructValue, intArrayStructValueString},
|
52 | 52 |
{&myUInt8SliceValue, myUInt8SliceString},
|
53 | 53 |
{&myUInt8ArrayValue, myUInt8ArrayString},
|
|
54 |
{&mapWithEncodingMarshaler, mapWithEncodingMarshalerString},
|
54 | 55 |
}
|
55 | 56 |
|
56 | 57 |
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"}`
|