mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Fixed #1048
This commit is contained in:
parent
2d7c63e4e4
commit
84ddf1862f
@ -1,5 +1,7 @@
|
||||
package yqlib
|
||||
|
||||
import "container/list"
|
||||
|
||||
func unionOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
|
||||
log.Debug("unionOperator")
|
||||
log.Debug("context: %v", NodesToString(context.MatchingNodes))
|
||||
@ -18,19 +20,25 @@ func unionOperator(d *dataTreeNavigator, context Context, expressionNode *Expres
|
||||
log.Debug("lhs: %v", lhs.ToString())
|
||||
log.Debug("rhs: %v", rhs.ToString())
|
||||
|
||||
results := lhs.ChildContext(list.New())
|
||||
for el := lhs.MatchingNodes.Front(); el != nil; el = el.Next() {
|
||||
node := el.Value.(*CandidateNode)
|
||||
results.MatchingNodes.PushBack(node)
|
||||
}
|
||||
|
||||
// this can happen when both expressions modify the context
|
||||
// instead of creating their own.
|
||||
/// (.foo = "bar"), (.thing = "cat")
|
||||
|
||||
if rhs.MatchingNodes != lhs.MatchingNodes {
|
||||
|
||||
for el := rhs.MatchingNodes.Front(); el != nil; el = el.Next() {
|
||||
node := el.Value.(*CandidateNode)
|
||||
log.Debug("processing %v", NodeToString(node))
|
||||
|
||||
lhs.MatchingNodes.PushBack(node)
|
||||
results.MatchingNodes.PushBack(node)
|
||||
}
|
||||
}
|
||||
log.Debug("all together: %v", lhs.ToString())
|
||||
return lhs, nil
|
||||
log.Debug("and lets print it out")
|
||||
log.Debug("all together: %v", results.ToString())
|
||||
return results, nil
|
||||
}
|
||||
|
@ -13,6 +13,14 @@ var unionOperatorScenarios = []expressionScenario{
|
||||
"D0, P[], (doc)::{}\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
description: "clone test",
|
||||
expression: `"abc" as $a | [$a, "cat"]`,
|
||||
expected: []string{
|
||||
"D0, P[], (!!seq)::- abc\n- cat\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
expression: `(.foo = "bar"), (.toe = "jam")`,
|
||||
|
Loading…
Reference in New Issue
Block a user