From 6334c0a320471ea282ca8eab07407214a35b53b0 Mon Sep 17 00:00:00 2001 From: "Nicolas S. Dade" Date: Tue, 6 Mar 2018 13:23:15 -0800 Subject: [PATCH] add unit test of embedded types which generates broken code which cannot be compile --- Makefile | 4 +++- tests/basic_test.go | 1 + tests/embedded_type.go | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/embedded_type.go diff --git a/Makefile b/Makefile index f877ab2..7823499 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,8 @@ generate: root build .root/src/$(PKG)/tests/data.go \ .root/src/$(PKG)/tests/omitempty.go \ .root/src/$(PKG)/tests/nothing.go \ - .root/src/$(PKG)/tests/named_type.go + .root/src/$(PKG)/tests/named_type.go \ + .root/src/$(PKG)/tests/embedded_type.go .root/bin/easyjson -all .root/src/$(PKG)/tests/data.go .root/bin/easyjson -all .root/src/$(PKG)/tests/nothing.go @@ -33,6 +34,7 @@ generate: root build .root/bin/easyjson -build_tags=use_easyjson .root/src/$(PKG)/benchmark/data.go .root/bin/easyjson .root/src/$(PKG)/tests/nested_easy.go .root/bin/easyjson .root/src/$(PKG)/tests/named_type.go + .root/bin/easyjson .root/src/$(PKG)/tests/embedded_type.go test: generate root go test \ diff --git a/tests/basic_test.go b/tests/basic_test.go index 0186784..511e43a 100644 --- a/tests/basic_test.go +++ b/tests/basic_test.go @@ -38,6 +38,7 @@ var testCases = []struct { {&IntsValue, IntsString}, {&mapStringStringValue, mapStringStringString}, {&namedTypeValue, namedTypeValueString}, + {&embeddedTypeValue, embeddedTypeValueString}, {&mapMyIntStringValue, mapMyIntStringValueString}, {&mapIntStringValue, mapIntStringValueString}, {&mapInt32StringValue, mapInt32StringValueString}, diff --git a/tests/embedded_type.go b/tests/embedded_type.go new file mode 100644 index 0000000..66470b6 --- /dev/null +++ b/tests/embedded_type.go @@ -0,0 +1,24 @@ +package tests + +//easyjson:json +type EmbeddedType struct { + EmbeddedInnerType + Inner struct { + EmbeddedInnerType + } + Field2 int +} + +type EmbeddedInnerType struct { + Field1 int +} + +var embeddedTypeValue EmbeddedType + +func init() { + embeddedTypeValue.Field1 = 1 + embeddedTypeValue.Field2 = 2 + embeddedTypeValue.Inner.Field1 = 3 +} + +var embeddedTypeValueString = `{"Inner":{"Field1":3},"Field2":2,"Field1":1}`