mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
[tests] added tests for key text marshaler
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -52,6 +52,7 @@ var testCases = []struct {
|
||||
{&intArrayStructValue, intArrayStructValueString},
|
||||
{&myUInt8SliceValue, myUInt8SliceString},
|
||||
{&myUInt8ArrayValue, myUInt8ArrayString},
|
||||
{&mapWithEncodingMarshaler, mapWithEncodingMarshalerString},
|
||||
}
|
||||
|
||||
func TestMarshal(t *testing.T) {
|
||||
|
||||
@@ -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"}`
|
||||
Reference in New Issue
Block a user