mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +00:00
added AND op
This commit is contained in:
parent
a0d940638c
commit
c7ebdda530
@ -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 {
|
||||
|
||||
for el := rhs.Front(); el != nil; el = el.Next() {
|
||||
node := el.Value.(*CandidateNode)
|
||||
lhs.Set(node.getKey(), node)
|
||||
if op == Or {
|
||||
for el := rhs.Front(); el != nil; el = el.Next() {
|
||||
node := el.Value.(*CandidateNode)
|
||||
lhs.Set(node.getKey(), node)
|
||||
}
|
||||
return lhs
|
||||
}
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user