Added flag to fix #2110

This commit is contained in:
Mike Farah
2025-07-14 16:26:26 +10:00
parent b9d9e2fbad
commit 6e8cc00030
4 changed files with 63 additions and 1 deletions
@@ -53,7 +53,54 @@ foobar:
thing: foobar_thing
`
var explodeWhenKeysExistDocument = `objects:
- &circle
name: circle
shape: round
- name: ellipse
!!merge <<: *circle
- !!merge <<: *circle
name: egg
`
var explodeWhenKeysExistLegacy = `D0, P[], (!!map)::objects:
- name: circle
shape: round
- name: circle
shape: round
- shape: round
name: egg
`
var explodeWhenKeysExistExpected = `D0, P[], (!!map)::objects:
- name: circle
shape: round
- name: ellipse
shape: round
- shape: round
name: egg
`
var fixedAnchorOperatorScenarios = []expressionScenario{
{
skipDoc: true,
description: "merge anchor after existing keys",
subdescription: "legacy: overrides existing keys",
document: explodeWhenKeysExistDocument,
expression: "explode(.)",
expected: []string{explodeWhenKeysExistExpected},
},
}
var anchorOperatorScenarios = []expressionScenario{
{
skipDoc: true,
description: "merge anchor after existing keys",
subdescription: "legacy: overrides existing keys",
document: explodeWhenKeysExistDocument,
expression: "explode(.)",
expected: []string{explodeWhenKeysExistLegacy},
},
{
skipDoc: true,
description: "merge anchor not map",
@@ -291,3 +338,11 @@ func TestAnchorAliasOperatorScenarios(t *testing.T) {
}
documentOperatorScenarios(t, "anchor-and-alias-operators", anchorOperatorScenarios)
}
func TestAnchorAliasOperatorAlignedToSpecScenarios(t *testing.T) {
ConfiguredYamlPreferences.FixMergeAnchorToSpec = true
for _, tt := range fixedAnchorOperatorScenarios {
testScenario(t, &tt)
}
ConfiguredYamlPreferences.FixMergeAnchorToSpec = false
}