mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-14 15:18:06 +00:00
wip
This commit is contained in:
parent
f95226e267
commit
c09513803a
@ -34,8 +34,9 @@ func (d *dataTreeNavigator) traverse(matchingNodes []*CandidateNode, pathNode *P
|
|||||||
return newMatchingNodes, nil
|
return newMatchingNodes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dataTreeNavigator) setFunction(op OperationType, lhs []*CandidateNode, rhs []*CandidateNode) ([]*CandidateNode, error) {
|
func (d *dataTreeNavigator) setFunction(op OperationType, lhs []*CandidateNode, rhs []*CandidateNode) []*CandidateNode {
|
||||||
return append(lhs, rhs...), nil
|
|
||||||
|
return append(lhs, rhs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dataTreeNavigator) GetMatchingNodes(matchingNodes []*CandidateNode, pathNode *PathTreeNode) ([]*CandidateNode, error) {
|
func (d *dataTreeNavigator) GetMatchingNodes(matchingNodes []*CandidateNode, pathNode *PathTreeNode) ([]*CandidateNode, error) {
|
||||||
@ -61,7 +62,7 @@ func (d *dataTreeNavigator) GetMatchingNodes(matchingNodes []*CandidateNode, pat
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return d.setFunction(pathNode.PathElement.OperationType, lhs, rhs)
|
return d.setFunction(pathNode.PathElement.OperationType, lhs, rhs), nil
|
||||||
// case Equals:
|
// case Equals:
|
||||||
// lhs, err = d.GetMatchingNodes(matchingNodes, pathNode.Lhs)
|
// lhs, err = d.GetMatchingNodes(matchingNodes, pathNode.Lhs)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
|
@ -223,3 +223,29 @@ func TestDataTreeNavigatorOrSimpleWithDepth(t *testing.T) {
|
|||||||
`
|
`
|
||||||
test.AssertResult(t, expected, resultsToString(results))
|
test.AssertResult(t, expected, resultsToString(results))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDataTreeNavigatorOrDeDupes(t *testing.T) {
|
||||||
|
|
||||||
|
nodes := readDoc(t, `a:
|
||||||
|
cat: apple
|
||||||
|
mad: things`)
|
||||||
|
|
||||||
|
path, errPath := treeCreator.ParsePath("a.(cat or cat)")
|
||||||
|
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