From c09513803a355dd7333d0b58bfa3d8640a14dd16 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Fri, 9 Oct 2020 11:37:47 +1100 Subject: [PATCH] wip --- pkg/yqlib/treeops/data_tree_navigator.go | 7 ++--- pkg/yqlib/treeops/data_tree_navigator_test.go | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/pkg/yqlib/treeops/data_tree_navigator.go b/pkg/yqlib/treeops/data_tree_navigator.go index 4bfa873a..bee49863 100644 --- a/pkg/yqlib/treeops/data_tree_navigator.go +++ b/pkg/yqlib/treeops/data_tree_navigator.go @@ -34,8 +34,9 @@ func (d *dataTreeNavigator) traverse(matchingNodes []*CandidateNode, pathNode *P return newMatchingNodes, nil } -func (d *dataTreeNavigator) setFunction(op OperationType, lhs []*CandidateNode, rhs []*CandidateNode) ([]*CandidateNode, error) { - return append(lhs, rhs...), nil +func (d *dataTreeNavigator) setFunction(op OperationType, lhs []*CandidateNode, rhs []*CandidateNode) []*CandidateNode { + + return append(lhs, rhs...) } func (d *dataTreeNavigator) GetMatchingNodes(matchingNodes []*CandidateNode, pathNode *PathTreeNode) ([]*CandidateNode, error) { @@ -61,7 +62,7 @@ func (d *dataTreeNavigator) GetMatchingNodes(matchingNodes []*CandidateNode, pat if err != nil { return nil, err } - return d.setFunction(pathNode.PathElement.OperationType, lhs, rhs) + return d.setFunction(pathNode.PathElement.OperationType, lhs, rhs), nil // case Equals: // lhs, err = d.GetMatchingNodes(matchingNodes, pathNode.Lhs) // if err != nil { diff --git a/pkg/yqlib/treeops/data_tree_navigator_test.go b/pkg/yqlib/treeops/data_tree_navigator_test.go index 30742de6..73414224 100644 --- a/pkg/yqlib/treeops/data_tree_navigator_test.go +++ b/pkg/yqlib/treeops/data_tree_navigator_test.go @@ -223,3 +223,29 @@ func TestDataTreeNavigatorOrSimpleWithDepth(t *testing.T) { ` 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)) +}