diff --git a/Makefile b/Makefile index 18c6687..6bf5fad 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,8 @@ 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/src/$(PKG)/tests/type_declaration.go .root/bin/easyjson -all .root/src/$(PKG)/tests/data.go .root/bin/easyjson -all .root/src/$(PKG)/tests/nothing.go @@ -40,6 +41,7 @@ generate: root build .root/bin/easyjson .root/src/$(PKG)/tests/embedded_type.go .root/bin/easyjson .root/src/$(PKG)/tests/reference_to_pointer.go .root/bin/easyjson -disallow_unknown_fields .root/src/$(PKG)/tests/disallow_unknown.go + .root/bin/easyjson .root/src/$(PKG)/tests/type_declaration.go test: generate root go test \ diff --git a/tests/basic_test.go b/tests/basic_test.go index 3b1cc65..958c0a8 100644 --- a/tests/basic_test.go +++ b/tests/basic_test.go @@ -52,6 +52,9 @@ var testCases = []struct { {&intArrayStructValue, intArrayStructValueString}, {&myUInt8SliceValue, myUInt8SliceString}, {&myUInt8ArrayValue, myUInt8ArrayString}, + {&myGenDeclaredValue, myGenDeclaredString}, + {&myGenDeclaredWithCommentValue, myGenDeclaredWithCommentString}, + {&myTypeDeclaredValue, myTypeDeclaredString}, } func TestMarshal(t *testing.T) { @@ -242,3 +245,22 @@ func TestDisallowUnknown(t *testing.T) { t.Error("want error, got nil") } } + +var testNotGeneratedTypeCases = []interface{}{ + TypeNotDeclared{}, +} + +func TestMethodsNoGenerated(t *testing.T) { + var ok bool + for i, instance := range testNotGeneratedTypeCases { + _, ok = instance.(json.Marshaler) + if ok { + t.Errorf("[%d, %T] Unexpected MarshalJSON()", i, instance) + } + + _, ok = instance.(json.Unmarshaler) + if ok { + t.Errorf("[%d, %T] Unexpected Unmarshaler()", i, instance) + } + } +} diff --git a/tests/type_declaration.go b/tests/type_declaration.go new file mode 100644 index 0000000..e638455 --- /dev/null +++ b/tests/type_declaration.go @@ -0,0 +1,33 @@ +package tests + +//easyjson:json +type ( + GenDeclared1 struct { + Value string + } + + // A gen declared easyjson struct with a comment + GenDeclaredWithComment struct { + Value string + } +) + +type ( + //easyjson:json + TypeDeclared struct { + Value string + } + + TypeNotDeclared struct { + Value string + } +) + +var ( + myGenDeclaredValue = TypeDeclared{Value: "GenDeclared"} + myGenDeclaredString = `{"Value":"GenDeclared"}` + myGenDeclaredWithCommentValue = TypeDeclared{Value: "GenDeclaredWithComment"} + myGenDeclaredWithCommentString = `{"Value":"GenDeclaredWithComment"}` + myTypeDeclaredValue = TypeDeclared{Value: "TypeDeclared"} + myTypeDeclaredString = `{"Value":"TypeDeclared"}` +)