From 542efd89288445089deb46a548149ea1b1e4052d Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Wed, 7 Jul 2021 15:36:43 +1000 Subject: [PATCH] Update append array docs --- pkg/yqlib/doc/Add.md | 26 ++++++++++++++++++++++++++ pkg/yqlib/operator_add_test.go | 16 ++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/pkg/yqlib/doc/Add.md b/pkg/yqlib/doc/Add.md index 1c9f3cc1..c6d80669 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 cd478d37..0ffa2934 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: {} }`,