Skip to content

Commit

Permalink
Update append array docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed Jul 7, 2021
1 parent ce3e347 commit 542efd8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
26 changes: 26 additions & 0 deletions pkg/yqlib/doc/Add.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions pkg/yqlib/operator_add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: `{}`,
Expand Down Expand Up @@ -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: {} }`,
Expand Down

0 comments on commit 542efd8

Please sign in to comment.