Update append array docs

This commit is contained in:
Mike Farah 2021-07-07 15:36:43 +10:00
parent ce3e347157
commit 542efd8928
2 changed files with 34 additions and 8 deletions

View File

@ -127,6 +127,32 @@ b:
- 4 - 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 ## Relative append
Given a sample.yml file of: Given a sample.yml file of:
```yaml ```yaml

View File

@ -14,14 +14,6 @@ var addOperatorScenarios = []expressionScenario{
"D0, P[1 a], (!!int)::3\n", "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, skipDoc: true,
document: `{}`, document: `{}`,
@ -94,6 +86,14 @@ var addOperatorScenarios = []expressionScenario{
"D0, P[], (doc)::{a: [1, 2, 3, 4], b: [3, 4]}\n", "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", description: "Relative append",
document: `a: { a1: {b: [cat]}, a2: {b: [dog]}, a3: {} }`, document: `a: { a1: {b: [cat]}, a2: {b: [dog]}, a3: {} }`,