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
2 changes: 2 additions & 0 deletions fieldpath/pathelementmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (spev sortedPathElementValues) Less(i, j int) bool {
func (spev sortedPathElementValues) Swap(i, j int) { spev[i], spev[j] = spev[j], spev[i] }

// Insert adds the pathelement and associated value in the map.
// If insert is called twice with the same PathElement, the value is replaced.
func (s *PathElementValueMap) Insert(pe PathElement, v value.Value) {
loc := sort.Search(len(s.members), func(i int) bool {
return !s.members[i].PathElement.Less(pe)
Expand All @@ -62,6 +63,7 @@ func (s *PathElementValueMap) Insert(pe PathElement, v value.Value) {
return
}
if s.members[loc].PathElement.Equals(pe) {
s.members[loc].Value = v
return
}
s.members = append(s.members, pathElementValue{})
Expand Down
7 changes: 7 additions & 0 deletions fieldpath/pathelementmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@ func TestPathElementValueMap(t *testing.T) {
} else if !value.Equals(val, value.NewValueInterface(2)) {
t.Fatalf("Unexpected value found: %#v", val)
}

m.Insert(PathElement{FieldName: strptr("carrot")}, value.NewValueInterface("fork"))
if val, ok := m.Get(PathElement{FieldName: strptr("carrot")}); !ok {
t.Fatal("Missing path-element in map")
} else if !value.Equals(val, value.NewValueInterface("fork")) {
t.Fatalf("Unexpected value found: %#v", val)
}
}