Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added test cases for slices.Map (for #655) #769

Merged
merged 1 commit into from
Sep 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions slices/map_test.go
Original file line number Diff line number Diff line change
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