mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-10 16:55:40 +00:00
add tests
This commit is contained in:
parent
b554a5b6b3
commit
c5919c4d8f
@ -1 +1,18 @@
|
|||||||
|
|
||||||
|
## Filter array
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- 3
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq 'filter(. < 3)' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
```
|
||||||
|
|
||||||
|
|||||||
@ -6,43 +6,39 @@ import (
|
|||||||
|
|
||||||
var filterOperatorScenarios = []expressionScenario{
|
var filterOperatorScenarios = []expressionScenario{
|
||||||
{
|
{
|
||||||
skipDoc: true,
|
description: "Filter array",
|
||||||
document: `[1,2,3]`,
|
document: `[1,2,3]`,
|
||||||
document2: `[1, 2]`,
|
|
||||||
expression: `filter(. < 3)`,
|
expression: `filter(. < 3)`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!seq)::[2, 3, 4]\n",
|
"D0, P[], (!!seq)::- 1\n",
|
||||||
"D0, P[], (!!seq)::[1, 2]\n",
|
"D0, P[], (!!seq)::- 2\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
/*
|
|
||||||
{
|
{
|
||||||
description: "Map array",
|
skipDoc: true,
|
||||||
document: `[1,2,3]`,
|
document: `[1,2,3]`,
|
||||||
expression: `map(. + 1)`,
|
expression: `filter(. > 1)`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!seq)::[2, 3, 4]\n",
|
"D0, P[], (!!seq)::- 2\n",
|
||||||
|
"D0, P[], (!!seq)::- 3\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
document: `{a: 1, b: 2, c: 3}`,
|
description: "Filter array to empty",
|
||||||
document2: `{x: 10, y: 20, z: 30}`,
|
document: `[1,2,3]`,
|
||||||
expression: `map_values(. + 1)`,
|
expression: `filter(. > 4)`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (doc)::{a: 2, b: 3, c: 4}\n",
|
|
||||||
"D0, P[], (doc)::{x: 11, y: 21, z: 31}\n",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Map object values",
|
skipDoc: true,
|
||||||
document: `{a: 1, b: 2, c: 3}`,
|
description: "Filter empty array",
|
||||||
expression: `map_values(. + 1)`,
|
document: `[]`,
|
||||||
|
expression: `filter(. > 1)`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (doc)::{a: 2, b: 3, c: 4}\n",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterOperatorScenarios(t *testing.T) {
|
func TestFilterOperatorScenarios(t *testing.T) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user