[tests] added tests for key text marshaler

This commit is contained in:
Aleksandr Petrukhin
2019-04-03 16:59:05 +00:00
parent a0e09156bb
commit 7169726fa7
3 changed files with 23 additions and 1 deletions
+2 -1
View File
@@ -26,7 +26,7 @@ generate: root build
.root/src/$(PKG)/tests/named_type.go \
.root/src/$(PKG)/tests/custom_map_key_type.go \
.root/src/$(PKG)/tests/embedded_type.go \
.root/src/$(PKG)/tests/reference_to_pointer.go
.root/src/$(PKG)/tests/reference_to_pointer.go \
.root/bin/easyjson -all .root/src/$(PKG)/tests/data.go
.root/bin/easyjson -all .root/src/$(PKG)/tests/nothing.go
@@ -39,6 +39,7 @@ generate: root build
.root/bin/easyjson .root/src/$(PKG)/tests/custom_map_key_type.go
.root/bin/easyjson .root/src/$(PKG)/tests/embedded_type.go
.root/bin/easyjson .root/src/$(PKG)/tests/reference_to_pointer.go
.root/bin/easyjson .root/src/$(PKG)/tests/key_marshaler_map.go
.root/bin/easyjson -disallow_unknown_fields .root/src/$(PKG)/tests/disallow_unknown.go
test: generate root
+1
View File
@@ -52,6 +52,7 @@ var testCases = []struct {
{&intArrayStructValue, intArrayStructValueString},
{&myUInt8SliceValue, myUInt8SliceString},
{&myUInt8ArrayValue, myUInt8ArrayString},
{&mapWithEncodingMarshaler, mapWithEncodingMarshalerString},
}
func TestMarshal(t *testing.T) {
+20
View File
@@ -0,0 +1,20 @@
package tests
type KeyWithEncodingMarshaler int
func (f KeyWithEncodingMarshaler) MarshalText() (text []byte, err error) {
return []byte("hello"), nil
}
func (f *KeyWithEncodingMarshaler) UnmarshalText(text []byte) error {
if string(text) == "hello" {
*f = 5
}
return nil
}
//easyjson:json
type KeyWithEncodingMarshalers map[KeyWithEncodingMarshaler]string
var mapWithEncodingMarshaler KeyWithEncodingMarshalers = KeyWithEncodingMarshalers{5: "hello"}
var mapWithEncodingMarshalerString = `{"hello":"hello"}`