mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-02 18:41:39 +00:00
Merge anchor traversing: add test for aliased sequence, cleanup
This commit is contained in:
parent
162ea5437c
commit
c3782799c5
@ -293,9 +293,10 @@ func doTraverseMap(newMatches *orderedmap.OrderedMap, node *CandidateNode, wante
|
||||
}
|
||||
|
||||
func traverseMergeAnchor(newMatches *orderedmap.OrderedMap, value *CandidateNode, wantedKey string, prefs traversePreferences, splat bool) error {
|
||||
if value.Kind == AliasNode {
|
||||
value = value.Alias
|
||||
}
|
||||
switch value.Kind {
|
||||
case AliasNode:
|
||||
return traverseMergeAnchor(newMatches, value.Alias, wantedKey, prefs, splat)
|
||||
case MappingNode:
|
||||
return doTraverseMap(newMatches, value, wantedKey, prefs, splat)
|
||||
case SequenceNode:
|
||||
@ -313,10 +314,10 @@ func traverseMergeAnchor(newMatches *orderedmap.OrderedMap, value *CandidateNode
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got %v", value.Tag)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func traverseArray(candidate *CandidateNode, operation *Operation, prefs traversePreferences) (*list.List, error) {
|
||||
|
||||
@ -365,7 +365,7 @@ var traversePathOperatorScenarios = []expressionScenario{
|
||||
"D0, P[0], (!!null)::null\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
{ // Merge anchor with inline map
|
||||
skipDoc: true,
|
||||
document: `{<<: {a: 42}}`,
|
||||
expression: `.a`,
|
||||
@ -373,7 +373,7 @@ var traversePathOperatorScenarios = []expressionScenario{
|
||||
"D0, P[<< a], (!!int)::42\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
{ // Merge anchor with sequence with inline map
|
||||
skipDoc: true,
|
||||
document: `{<<: [{a: 42}]}`,
|
||||
expression: `.a`,
|
||||
@ -381,6 +381,14 @@ var traversePathOperatorScenarios = []expressionScenario{
|
||||
"D0, P[<< 0 a], (!!int)::42\n",
|
||||
},
|
||||
},
|
||||
{ // Merge anchor with aliased sequence with inline map
|
||||
skipDoc: true,
|
||||
document: `{s: &s [{a: 42}], m: {<<: *s}}`,
|
||||
expression: `.m.a`,
|
||||
expected: []string{
|
||||
"D0, P[s 0 a], (!!int)::42\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: mergeDocSample,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user