mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-07 14:25:38 +00:00
Compare commits
1 Commits
62826bcd04
...
322af57199
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
322af57199 |
@ -273,7 +273,7 @@ will output
|
|||||||
100
|
100
|
||||||
```
|
```
|
||||||
|
|
||||||
## First element with no filter from array
|
## First element with no RHS from array
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
```yaml
|
```yaml
|
||||||
- 10
|
- 10
|
||||||
@ -289,7 +289,7 @@ will output
|
|||||||
10
|
10
|
||||||
```
|
```
|
||||||
|
|
||||||
## First element with no filter from array of maps
|
## First element with no RHS from array of maps
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
```yaml
|
```yaml
|
||||||
- a: 10
|
- a: 10
|
||||||
@ -304,3 +304,42 @@ will output
|
|||||||
a: 10
|
a: 10
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## No RHS on empty array returns nothing
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
[]
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq 'first' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
## No RHS on scalar returns nothing
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
hello
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq 'first' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
## No RHS on null returns nothing
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
null
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq 'first' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
|||||||
@ -139,8 +139,9 @@ var firstOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[1], (!!int)::100\n",
|
"D0, P[1], (!!int)::100\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// New tests for no RHS (return first child)
|
||||||
{
|
{
|
||||||
description: "First element with no filter from array",
|
description: "First element with no RHS from array",
|
||||||
document: "[10, 100, 1]",
|
document: "[10, 100, 1]",
|
||||||
expression: `first`,
|
expression: `first`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
@ -148,7 +149,7 @@ var firstOperatorScenarios = []expressionScenario{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "First element with no filter from array of maps",
|
description: "First element with no RHS from array of maps",
|
||||||
document: "[{a: 10},{a: 100}]",
|
document: "[{a: 10},{a: 100}]",
|
||||||
expression: `first`,
|
expression: `first`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
@ -156,22 +157,19 @@ var firstOperatorScenarios = []expressionScenario{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "No filter on empty array returns nothing",
|
description: "No RHS on empty array returns nothing",
|
||||||
skipDoc: true,
|
|
||||||
document: "[]",
|
document: "[]",
|
||||||
expression: `first`,
|
expression: `first`,
|
||||||
expected: []string{},
|
expected: []string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "No filter on scalar returns nothing",
|
description: "No RHS on scalar returns nothing",
|
||||||
skipDoc: true,
|
|
||||||
document: "hello",
|
document: "hello",
|
||||||
expression: `first`,
|
expression: `first`,
|
||||||
expected: []string{},
|
expected: []string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "No filter on null returns nothing",
|
description: "No RHS on null returns nothing",
|
||||||
skipDoc: true,
|
|
||||||
document: "null",
|
document: "null",
|
||||||
expression: `first`,
|
expression: `first`,
|
||||||
expected: []string{},
|
expected: []string{},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user