2020-10-17 11:10:47 +00:00
|
|
|
package treeops
|
|
|
|
|
|
|
|
import (
|
2020-10-18 00:31:36 +00:00
|
|
|
"fmt"
|
2020-10-17 11:10:47 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/mikefarah/yq/v3/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
type expressionScenario struct {
|
|
|
|
document string
|
|
|
|
expression string
|
|
|
|
expected []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func testScenario(t *testing.T, s *expressionScenario) {
|
|
|
|
|
|
|
|
nodes := readDoc(t, s.document)
|
|
|
|
path, errPath := treeCreator.ParsePath(s.expression)
|
|
|
|
if errPath != nil {
|
|
|
|
t.Error(errPath)
|
2020-10-17 11:58:18 +00:00
|
|
|
return
|
2020-10-17 11:10:47 +00:00
|
|
|
}
|
|
|
|
results, errNav := treeNavigator.GetMatchingNodes(nodes, path)
|
|
|
|
|
|
|
|
if errNav != nil {
|
|
|
|
t.Error(errNav)
|
2020-10-17 11:58:18 +00:00
|
|
|
return
|
2020-10-17 11:10:47 +00:00
|
|
|
}
|
2020-10-18 00:31:36 +00:00
|
|
|
test.AssertResultComplexWithContext(t, s.expected, resultsToString(results), fmt.Sprintf("exp: %v\ndoc: %v", s.expression, s.document))
|
2020-10-17 11:10:47 +00:00
|
|
|
}
|