From d8327680d3d5d7b7990f0bcdca4d79a5cb34d4f9 Mon Sep 17 00:00:00 2001 From: Yonghwan SO Date: Sun, 18 Sep 2022 10:25:00 +0900 Subject: [PATCH] added test cases for slices.Map (for #655) --- slices/map_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/slices/map_test.go b/slices/map_test.go index f18dc418..fae7ef71 100644 --- a/slices/map_test.go +++ b/slices/map_test.go @@ -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)