From 3c9f41b197dc81c49cb5f34fab950eca0c037fb2 Mon Sep 17 00:00:00 2001 From: Alexandr Mayorskiy Date: Tue, 14 Jul 2020 17:27:06 +0300 Subject: [PATCH] add test with nested marshaler interface --- Makefile | 38 ++++++++++++++++++++------------------ tests/basic_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index ec37cc4..c527340 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/tests/basic_test.go b/tests/basic_test.go index 11013c8..e18e515 100644 --- a/tests/basic_test.go +++ b/tests/basic_test.go @@ -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