diff --git a/pkg/yqlib/doc/Add.md b/pkg/yqlib/doc/Add.md index 1c9f3cc123a..c6d806699e8 100644 --- a/pkg/yqlib/doc/Add.md +++ b/pkg/yqlib/doc/Add.md @@ -127,6 +127,32 @@ b: - 4 ``` +## Append another array using += +Given a sample.yml file of: +```yaml +a: + - 1 + - 2 +b: + - 3 + - 4 +``` +then +```bash +yq eval '.a += .b' sample.yml +``` +will output +```yaml +a: + - 1 + - 2 + - 3 + - 4 +b: + - 3 + - 4 +``` + ## Relative append Given a sample.yml file of: ```yaml diff --git a/pkg/yqlib/operator_add_test.go b/pkg/yqlib/operator_add_test.go index cd478d37acf..0ffa2934fe9 100644 --- a/pkg/yqlib/operator_add_test.go +++ b/pkg/yqlib/operator_add_test.go @@ -14,14 +14,6 @@ var addOperatorScenarios = []expressionScenario{ "D0, P[1 a], (!!int)::3\n", }, }, - { - skipDoc: true, - document: "array: [1]\narray2: [2]", - expression: ".array += .array2", - expected: []string{ - "D0, P[], (doc)::array: [1, 2]\narray2: [2]\n", - }, - }, { skipDoc: true, document: `{}`, @@ -94,6 +86,14 @@ var addOperatorScenarios = []expressionScenario{ "D0, P[], (doc)::{a: [1, 2, 3, 4], b: [3, 4]}\n", }, }, + { + description: "Append another array using +=", + document: `{a: [1,2], b: [3,4]}`, + expression: `.a += .b`, + expected: []string{ + "D0, P[], (doc)::{a: [1, 2, 3, 4], b: [3, 4]}\n", + }, + }, { description: "Relative append", document: `a: { a1: {b: [cat]}, a2: {b: [dog]}, a3: {} }`,