Skip to content

Commit

Permalink
added test cases for slices.Map (for #655)
Browse files Browse the repository at this point in the history
  • Loading branch information
sio4 committed Sep 18, 2022
1 parent 32ad898 commit d832768
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions slices/map_test.go
Expand Up @@ -25,6 +25,31 @@ func Test_Map_MarshalJSON(t *testing.T) {
r.Equal([]byte(`{"a":"b"}`), b)
}

func Test_Map_UnmarshalJSON(t *testing.T) {
r := require.New(t)

m := Map{}
err := json.Unmarshal([]byte(`{"a":"b"}`), &m)
r.NoError(err)
r.Equal("b", m["a"])
}

// for the next test case
type Ship struct {
Name string
Crew Map `json:"crew"`
}

func Test_Map_UnmarshalJSON_Nested(t *testing.T) {
r := require.New(t)

p := &Ship{}
err := json.Unmarshal([]byte(`{"crew":{"captain":"Han", "navigator":"Chewie"}}`), p)
r.NoError(err)
r.Equal("Han", p.Crew["captain"])
r.Equal("Chewie", p.Crew["navigator"])
}

func Test_Map_UnMarshalJSON_uninitialized_map_does_not_panic(t *testing.T) {
r := require.New(t)

Expand Down

0 comments on commit d832768

Please sign in to comment.