Flag for fixed list merge key traverse override behavior,

and fix traversing map with merge key that would override local key (completes #2110 fix)
This commit is contained in:
Steven WdV
2025-07-16 16:00:16 +02:00
parent 128bf80eed
commit a47e882c8f
6 changed files with 135 additions and 27 deletions
+44 -13
View File
@@ -25,6 +25,26 @@ foobar:
thing: foobar_thing
`
var fixedTraversePathOperatorScenarios = []expressionScenario{
{
description: "Traversing merge anchor lists",
subdescription: "Note that the keys earlier in the merge anchors sequence override later ones",
document: mergeDocSample,
expression: `.foobarList.thing`,
expected: []string{
"D0, P[foo thing], (!!str)::foo_thing\n",
},
},
{
description: "Traversing merge anchors with override",
document: mergeDocSample,
expression: `.foobar.c`,
expected: []string{
"D0, P[foobar c], (!!str)::foobar_c\n",
},
},
}
var traversePathOperatorScenarios = []expressionScenario{
{
skipDoc: true,
@@ -400,9 +420,10 @@ var traversePathOperatorScenarios = []expressionScenario{
},
},
{
description: "Traversing merge anchors with override",
document: mergeDocSample,
expression: `.foobar.c`,
description: "Traversing merge anchors with override",
subdescription: "This is legacy behavior, see --yaml-fix-merge-anchor-to-spec",
document: mergeDocSample,
expression: `.foobar.c`,
expected: []string{
"D0, P[foo c], (!!str)::foo_c\n",
},
@@ -442,12 +463,13 @@ var traversePathOperatorScenarios = []expressionScenario{
},
},
{
description: "Traversing merge anchor lists",
subdescription: "Note that the keys earlier in the merge anchors sequence override later ones",
document: mergeDocSample,
expression: `.foobarList.thing`,
description: "Traversing merge anchor lists",
subdescription: "Note that the later merge anchors override previous, " +
"but this is legacy behavior, see --yaml-fix-merge-anchor-to-spec",
document: mergeDocSample,
expression: `.foobarList.thing`,
expected: []string{
"D0, P[foo thing], (!!str)::foo_thing\n",
"D0, P[bar thing], (!!str)::bar_thing\n",
},
},
{
@@ -467,14 +489,15 @@ var traversePathOperatorScenarios = []expressionScenario{
},
},
{
description: "Splatting merge anchor lists",
document: mergeDocSample,
expression: `.foobarList[]`,
description: "Splatting merge anchor lists",
subdescription: "With legacy override behavior, see --yaml-fix-merge-anchor-to-spec",
document: mergeDocSample,
expression: `.foobarList[]`,
expected: []string{
"D0, P[bar b], (!!str)::bar_b\n",
"D0, P[foo thing], (!!str)::foo_thing\n",
"D0, P[foobarList c], (!!str)::foobarList_c\n",
"D0, P[foo a], (!!str)::foo_a\n",
"D0, P[bar thing], (!!str)::bar_thing\n",
"D0, P[foobarList c], (!!str)::foobarList_c\n",
},
},
{
@@ -575,3 +598,11 @@ func TestTraversePathOperatorScenarios(t *testing.T) {
}
documentOperatorScenarios(t, "traverse-read", traversePathOperatorScenarios)
}
func TestTraversePathOperatorAlignedToSpecScenarios(t *testing.T) {
ConfiguredYamlPreferences.FixMergeAnchorToSpec = true
for _, tt := range fixedTraversePathOperatorScenarios {
testScenario(t, &tt)
}
ConfiguredYamlPreferences.FixMergeAnchorToSpec = false
}