Skip to content

Commit

Permalink
Add test for complex value
Browse files Browse the repository at this point in the history
  • Loading branch information
pietern committed Oct 29, 2024
1 parent 71b2da2 commit 0662b84
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions libs/dyn/jsonsaver/saver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,36 @@ func TestMarshalSequence(t *testing.T) {
require.NoError(t, err)
require.JSONEq(t, `["value1","value2"]`, string(b))
}

func TestMarshalComplex(t *testing.T) {
map1 := dyn.NewMapping()
map1.Set(dyn.V("str1"), dyn.V("value1"))
map1.Set(dyn.V("str2"), dyn.V("value2"))

seq1 := []dyn.Value{}
seq1 = append(seq1, dyn.V("value1"))
seq1 = append(seq1, dyn.V("value2"))

root := dyn.NewMapping()
root.Set(dyn.V("map1"), dyn.V(map1))
root.Set(dyn.V("seq1"), dyn.V(seq1))

// Marshal without indent.
b, err := Marshal(dyn.V(root))
require.NoError(t, err)
require.Equal(t, `{"map1":{"str1":"value1","str2":"value2"},"seq1":["value1","value2"]}`+"\n", string(b))

// Marshal with indent.
b, err = MarshalIndent(dyn.V(root), "", " ")
require.NoError(t, err)
require.Equal(t, `{
"map1": {
"str1": "value1",
"str2": "value2"
},
"seq1": [
"value1",
"value2"
]
}`+"\n", string(b))
}

0 comments on commit 0662b84

Please sign in to comment.