Updated orderednavigablemap

This commit is contained in:
Trial97
2021-10-25 10:48:29 +03:00
committed by Dan Christian Bogos
parent a541e45313
commit 69fb71d2cf
2 changed files with 42 additions and 0 deletions

View File

@@ -67,6 +67,11 @@ func (onm *OrderedNavigableMap) Empty() bool {
func (onm *OrderedNavigableMap) removeRef(path string) {
for idxPath, slcIdx := range onm.orderRef { //remove the references from order
if strings.HasPrefix(idxPath, path) {
if lp := len(path); len(idxPath) > lp &&
idxPath[lp] != NestingSep[0] &&
idxPath[lp] != IdxStart[0] {
continue
}
for _, el := range slcIdx {
onm.orderIdx.Remove(el)
}

View File

@@ -948,3 +948,40 @@ func TestOrderedNavigableMapCompose(t *testing.T) {
t.Error(err)
}
}
func TestOrderedNavigableMapSet2(t *testing.T) {
nm := NewOrderedNavigableMap()
if err := nm.SetAsSlice(&FullPath{
PathSlice: []string{"Field"},
Path: "Field",
}, []*DataNode{NewLeafNode("1001")}); err != nil {
t.Error(err)
}
if err := nm.SetAsSlice(&FullPath{
PathSlice: []string{"Field1"},
Path: "Field1",
}, []*DataNode{NewLeafNode("1002")}); err != nil {
t.Error(err)
}
if err := nm.SetAsSlice(&FullPath{
PathSlice: []string{"Field"},
Path: "Field",
}, []*DataNode{NewLeafNode("1001")}); err != nil {
t.Error(err)
}
nMap := &DataNode{Type: NMMapType, Map: map[string]*DataNode{
"Field1": {Type: NMSliceType, Slice: []*DataNode{NewLeafNode("1002")}},
"Field": {Type: NMSliceType, Slice: []*DataNode{NewLeafNode("1001")}},
}}
order := [][]string{{"Field1", "0"}, {"Field", "0"}}
if !reflect.DeepEqual(nm.nm, nMap) {
t.Errorf("Expected %s ,received: %s", ToJSON(nMap), ToJSON(nm.nm))
}
if !reflect.DeepEqual(nm.GetOrder(), order) {
t.Errorf("Expected %s ,received: %s", order, nm.GetOrder())
}
}