mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated orderednavigablemap
This commit is contained in:
committed by
Dan Christian Bogos
parent
a541e45313
commit
69fb71d2cf
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user