From a5b8ef6cb111151837673639e3491d63c501d438 Mon Sep 17 00:00:00 2001 From: Steven WdV Date: Wed, 16 Jul 2025 17:56:56 +0200 Subject: [PATCH] Add some tests regarding override behavior. The one in fixedTraversePathOperatorScenarios still fails --- pkg/yqlib/operator_anchors_aliases_test.go | 31 +++++++++++++++++++++- pkg/yqlib/operator_traverse_path_test.go | 22 +++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/pkg/yqlib/operator_anchors_aliases_test.go b/pkg/yqlib/operator_anchors_aliases_test.go index 5f6dfacc..ec6dcda8 100644 --- a/pkg/yqlib/operator_anchors_aliases_test.go +++ b/pkg/yqlib/operator_anchors_aliases_test.go @@ -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) { diff --git a/pkg/yqlib/operator_traverse_path_test.go b/pkg/yqlib/operator_traverse_path_test.go index fadbf819..58ae6263 100644 --- a/pkg/yqlib/operator_traverse_path_test.go +++ b/pkg/yqlib/operator_traverse_path_test.go @@ -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) {