This commit is contained in:
Mike Farah 2020-10-09 11:37:47 +11:00
parent f95226e267
commit c09513803a
2 changed files with 30 additions and 3 deletions

View File

@ -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 {

View File

@ -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))
}