Skip to content

Commit b1ce8cb

Browse files
committed
veqryn/marshal-json: add nil tests
1 parent d749f5e commit b1ce8cb

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

v2/metadata_test.go

+26-6
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ func TestMetadataAddNil(t *testing.T) {
120120
var nilMap map[string]interface{}
121121
md.AddStruct("nilmap", nilMap)
122122

123+
var nilSlice []interface{}
124+
md.AddStruct("nilSlice", nilSlice)
125+
123126
var nilError _testError
124127
md.AddStruct("error", nilError)
125128

@@ -138,6 +141,18 @@ func TestMetadataAddNil(t *testing.T) {
138141
var marshalFullPtr = &_textMarshaller{}
139142
md.AddStruct("marshalFullPtr", marshalFullPtr)
140143

144+
var nullJsonMarshaller json.RawMessage
145+
md.AddStruct("nullJsonMarshaller", nullJsonMarshaller)
146+
147+
var fullJsonMarshaller = &json.RawMessage{}
148+
md.AddStruct("fullJsonMarshaller", fullJsonMarshaller)
149+
150+
var nilBytes []byte
151+
md.AddStruct("nilBytes", nilBytes)
152+
153+
var emptyBytes = []byte{}
154+
md.AddStruct("emptyBytes", emptyBytes)
155+
141156
if !reflect.DeepEqual(md, MetaData{
142157
"map": {
143158
"data": map[string]interface{}{
@@ -146,12 +161,17 @@ func TestMetadataAddNil(t *testing.T) {
146161
},
147162
"nilmap": map[string]interface{}{},
148163
"Extra data": {
149-
"error": "errorstr",
150-
"errorNilPtr": "<nil>",
151-
"timeUnset": "0001-01-01T00:00:00Z",
152-
"durationUnset": "0s",
153-
"marshalFullPtr": "marshalled text",
154-
"marshalNilPtr": "<nil>",
164+
"nilSlice": []interface{}{},
165+
"error": "errorstr",
166+
"errorNilPtr": "<nil>",
167+
"timeUnset": "0001-01-01T00:00:00Z",
168+
"durationUnset": "0s",
169+
"marshalFullPtr": "marshalled text",
170+
"marshalNilPtr": "<nil>",
171+
"nullJsonMarshaller": "null",
172+
"fullJsonMarshaller": "",
173+
"nilBytes": "",
174+
"emptyBytes": "",
155175
},
156176
}) {
157177
t.Errorf("metadata.AddStruct didn't work: %#v", md)

0 commit comments

Comments
 (0)