mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
array equals!
This commit is contained in:
parent
d7716551cf
commit
93aaa8ccee
@ -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:
|
||||
|
@ -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 == "+" {
|
||||
|
Loading…
Reference in New Issue
Block a user