added AND op

This commit is contained in:
Mike Farah 2020-10-09 12:10:46 +11:00
parent a0d940638c
commit c7ebdda530
2 changed files with 42 additions and 4 deletions

View File

@ -42,11 +42,21 @@ func (d *dataTreeNavigator) traverse(matchMap *orderedmap.OrderedMap, pathNode *
func (d *dataTreeNavigator) setFunction(op OperationType, lhs *orderedmap.OrderedMap, rhs *orderedmap.OrderedMap) *orderedmap.OrderedMap {
if op == Or {
for el := rhs.Front(); el != nil; el = el.Next() {
node := el.Value.(*CandidateNode)
lhs.Set(node.getKey(), node)
}
return lhs
}
var matchingNodeMap = orderedmap.NewOrderedMap()
for el := lhs.Front(); el != nil; el = el.Next() {
_, exists := rhs.Get(el.Key)
if exists {
matchingNodeMap.Set(el.Key, el.Value)
}
}
return matchingNodeMap
}

View File

@ -249,3 +249,31 @@ func TestDataTreeNavigatorOrDeDupes(t *testing.T) {
test.AssertResult(t, expected, resultsToString(results))
}
func TestDataTreeNavigatorAnd(t *testing.T) {
nodes := readDoc(t, `a:
cat: apple
pat: apple
cow: apple
mad: things`)
path, errPath := treeCreator.ParsePath("a.(*t and c*)")
if errPath != nil {
t.Error(errPath)
}
results, errNav := treeNavigator.GetMatchingNodes(nodes, path)
if errNav != nil {
t.Error(errNav)
}
expected := `
-- Node --
Document 0, path: [a cat]
Tag: !!str, Kind: ScalarNode, Anchor:
apple
`
test.AssertResult(t, expected, resultsToString(results))
}