add test with nested marshaler interface

This commit is contained in:
Alexandr Mayorskiy
2020-07-14 17:27:21 +03:00
parent 2cb8c451eb
commit 3c9f41b197
2 changed files with 47 additions and 18 deletions
+20 -18
View File
@@ -26,30 +26,32 @@ generate: build
./tests/members_unescaped.go \
./tests/intern.go \
./tests/nocopy.go \
./tests/escaping.go
bin/easyjson -all \
./tests/data.go \
./tests/nothing.go \
./tests/errors.go \
./tests/html.go \
./tests/type_declaration_skip.go
bin/easyjson \
./tests/nested_easy.go \
./tests/named_type.go \
./tests/custom_map_key_type.go \
./tests/embedded_type.go \
./tests/reference_to_pointer.go \
./tests/key_marshaler_map.go \
./tests/unknown_fields.go \
./tests/type_declaration.go \
./tests/members_escaped.go \
./tests/intern.go \
./tests/nocopy.go \
./tests/escaping.go \
bin/easyjson -all ./tests/data.go
bin/easyjson -all ./tests/nothing.go
bin/easyjson -all ./tests/errors.go
bin/easyjson -all ./tests/html.go
./tests/nested_marshaler.go
bin/easyjson -snake_case ./tests/snake.go
bin/easyjson -omit_empty ./tests/omitempty.go
bin/easyjson -build_tags=use_easyjson -disable_members_unescape ./benchmark/data.go
bin/easyjson ./tests/nested_easy.go
bin/easyjson ./tests/named_type.go
bin/easyjson ./tests/custom_map_key_type.go
bin/easyjson ./tests/embedded_type.go
bin/easyjson ./tests/reference_to_pointer.go
bin/easyjson ./tests/key_marshaler_map.go
bin/easyjson -disallow_unknown_fields ./tests/disallow_unknown.go
bin/easyjson ./tests/unknown_fields.go
bin/easyjson ./tests/type_declaration.go
bin/easyjson -all ./tests/type_declaration_skip.go
bin/easyjson ./tests/members_escaped.go
bin/easyjson -disable_members_unescape ./tests/members_unescaped.go
bin/easyjson ./tests/intern.go
bin/easyjson ./tests/nocopy.go
bin/easyjson ./tests/escaping.go
test: generate
go test \
+27
View File
@@ -231,6 +231,33 @@ func TestNestedEasyJsonMarshal(t *testing.T) {
}
}
func TestNestedMarshaler(t *testing.T) {
s := NestedMarshaler{
Value: &StructWithMarshaler{
Value: 5,
},
Value2: 10,
}
data, err := s.MarshalJSON()
if err != nil {
t.Errorf("Can't marshal NestedMarshaler: %s", err)
}
s2 := NestedMarshaler {
Value: &StructWithMarshaler{},
}
err = s2.UnmarshalJSON(data)
if err != nil {
t.Errorf("Can't unmarshal NestedMarshaler: %s", err)
}
if !reflect.DeepEqual(s2, s) {
t.Errorf("easyjson.Unmarshal() = %#v; want %#v", s2, s)
}
}
func TestUnmarshalStructWithEmbeddedPtrStruct(t *testing.T) {
var s = StructWithInterface{Field2: &EmbeddedStruct{}}
var err error