Skip to content

Commit

Permalink
marshals nil slices/arrays like expected and equivalent to json.marshal
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenCK committed May 9, 2023
1 parent b117113 commit f402553
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sheriff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit f402553

Please sign in to comment.