Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions mutations.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ func (m Map) Merge(merge Map) Map {
// MergeHere blends the specified map with this map and returns the current map.
//
// Keys that appear in both will be selected from the specified map. The original map
// will be modified. This method requires that
// the wrapped object be a map[string]any
// will be modified in place. The receiver must be non-nil; calling MergeHere on a
// nil Map panics. This method requires that the wrapped object be a map[string]any
func (m Map) MergeHere(merge Map) Map {
if m == nil {
panic("objx: MergeHere called on nil Map")
}
maps.Copy(m, merge)
return m
}
Expand Down
12 changes: 12 additions & 0 deletions mutations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ func TestTransformKeys(t *testing.T) {
}, r)
}

func TestMergeHere_NilMap(t *testing.T) {
var m objx.Map
for _, merge := range []objx.Map{{"a": 1}, nil} {
func() {
defer func() {
assert.Equal(t, "objx: MergeHere called on nil Map", recover())
}()
m.MergeHere(merge)
}()
}
}

func keyToUpper(s string, v any) (string, any) {
return strings.ToUpper(s), v
}