mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-07 02:48:27 +08:00
Added flag to fix #2110
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user