Add some tests regarding override behavior.

The one in fixedTraversePathOperatorScenarios still fails
This commit is contained in:
Steven WdV 2025-07-16 17:56:56 +02:00
parent a47e882c8f
commit a5b8ef6cb1
No known key found for this signature in database
2 changed files with 52 additions and 1 deletions

View File

@ -85,11 +85,30 @@ var fixedAnchorOperatorScenarios = []expressionScenario{
{
skipDoc: true,
description: "merge anchor after existing keys",
subdescription: "legacy: overrides existing keys",
subdescription: "Does not override existing keys",
document: explodeWhenKeysExistDocument,
expression: "explode(.)",
expected: []string{explodeWhenKeysExistExpected},
},
// The following tests are the same as below, to verify they still works correctly with the flag:
{
description: "Override",
subdescription: "see https://yaml.org/type/merge.html",
document: specDocument + "- << : [ *BIG, *LEFT, *SMALL ]\n x: 1\n",
expression: ".[4] | explode(.)",
expected: []string{"D0, P[4], (!!map)::r: 10\ny: 2\nx: 1\n"},
},
{
skipDoc: true,
description: "Duplicate keys",
subdescription: "outside merge anchor",
document: `{a: 1, a: 2}`,
expression: `explode(.)`,
expected: []string{
"D0, P[], (!!map)::{a: 1, a: 2}\n",
},
},
}
var anchorOperatorScenarios = []expressionScenario{
@ -407,6 +426,16 @@ var anchorOperatorScenarios = []expressionScenario{
"D0, P[], (!!map)::{a: {b: 42}, c: 42}\n",
},
},
{
skipDoc: true,
description: "Duplicate keys",
subdescription: "outside merge anchor",
document: `{a: 1, a: 2}`,
expression: `explode(.)`,
expected: []string{
"D0, P[], (!!map)::{a: 1, a: 2}\n",
},
},
}
func TestAnchorAliasOperatorScenarios(t *testing.T) {

View File

@ -43,6 +43,18 @@ var fixedTraversePathOperatorScenarios = []expressionScenario{
"D0, P[foobar c], (!!str)::foobar_c\n",
},
},
// The following tests are the same as below, to verify they still works correctly with the flag:
{
skipDoc: true,
description: "Duplicate keys",
subdescription: "outside merge anchor",
document: `{a: 1, a: 2}`,
expression: `.a`,
expected: []string{
"D0, P[a], (!!int)::2\n",
},
},
}
var traversePathOperatorScenarios = []expressionScenario{
@ -590,6 +602,16 @@ var traversePathOperatorScenarios = []expressionScenario{
"D0, P[a 2], (!!str)::c\n",
},
},
{
skipDoc: true,
description: "Duplicate keys",
subdescription: "outside merge anchor",
document: `{a: 1, a: 2}`,
expression: `.a`,
expected: []string{
"D0, P[a], (!!int)::2\n",
},
},
}
func TestTraversePathOperatorScenarios(t *testing.T) {