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

View File

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