array equals!

This commit is contained in:
Mike Farah 2020-10-09 16:43:43 +11:00
parent d7716551cf
commit 93aaa8ccee
2 changed files with 32 additions and 5 deletions

View File

@ -359,6 +359,37 @@ func TestDataTreeNavigatorEquals(t *testing.T) {
test.AssertResult(t, expected, resultsToString(results))
}
func TestDataTreeNavigatorArrayEquals(t *testing.T) {
nodes := readDoc(t, `- { b: apple, animal: rabbit }
- { b: banana, animal: cat }
- { b: corn, animal: dog }`)
path, errPath := treeCreator.ParsePath("(b == apple or animal == dog)")
if errPath != nil {
t.Error(errPath)
}
results, errNav := treeNavigator.GetMatchingNodes(nodes, path)
if errNav != nil {
t.Error(errNav)
}
expected := `
-- Node --
Document 0, path: [0]
Tag: !!map, Kind: MappingNode, Anchor:
{b: apple, animal: rabbit}
-- Node --
Document 0, path: [2]
Tag: !!map, Kind: MappingNode, Anchor:
{b: corn, animal: dog}
`
test.AssertResult(t, expected, resultsToString(results))
}
func TestDataTreeNavigatorEqualsTrickey(t *testing.T) {
nodes := readDoc(t, `a:

View File

@ -51,7 +51,7 @@ func (t *traverser) traverseMap(candidate *CandidateNode, pathNode *PathElement)
func (t *traverser) traverseArray(candidate *CandidateNode, pathNode *PathElement) ([]*CandidateNode, error) {
log.Debug("pathNode Value %v", pathNode.Value)
if pathNode.Value == "[*]" {
if pathNode.Value == "[*]" || pathNode.Value == "*" {
var contents = candidate.Node.Content
var newMatches = make([]*CandidateNode, len(contents))
@ -92,10 +92,6 @@ func (t *traverser) Traverse(matchingNode *CandidateNode, pathNode *PathElement)
case yaml.SequenceNode:
log.Debug("its a sequence of %v things!", len(value.Content))
return t.traverseArray(matchingNode, pathNode)
// switch head := head.(type) {
// case int64:
// return n.recurseArray(value, head, head, tail, pathStack)
// default:
// if head == "+" {