From f4025539959e102d90a06992f6dadcee61477e42 Mon Sep 17 00:00:00 2001 From: "torben.diekmann" Date: Tue, 9 May 2023 11:05:57 +0200 Subject: [PATCH] marshals nil slices/arrays like expected and equivalent to json.marshal --- sheriff_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sheriff_test.go b/sheriff_test.go index d079e4b..f54a3ef 100644 --- a/sheriff_test.go +++ b/sheriff_test.go @@ -743,6 +743,20 @@ func TestMarshal_NilSlice(t *testing.T) { jsonResult, err := json.Marshal(marshalSlice) assert.NoError(t, err) + expect := "null" + + assert.Equal(t, expect, string(jsonResult)) +} + +func TestMarshal_EmptySlice(t *testing.T) { + var stringSlice = []string{} // empty slice + + marshalSlice, err := Marshal(&Options{}, stringSlice) + assert.NoError(t, err) + + jsonResult, err := json.Marshal(marshalSlice) + assert.NoError(t, err) + expect := "[]" assert.Equal(t, expect, string(jsonResult))