Added nested traversal examples

This commit is contained in:
Mike Farah 2021-06-10 08:31:26 +10:00
parent b6e2a96ead
commit 78af68f436
2 changed files with 47 additions and 0 deletions

View File

@ -63,6 +63,22 @@ will output
frog
```
## Multiple special characters
Given a sample.yml file of:
```yaml
a:
"key.withdots":
"another.key": apple
```
then
```bash
yq eval '.a["key.withdots"]["another.key"]' sample.yml
```
will output
```yaml
apple
```
## Keys with spaces
Use quotes with brackets around path elements with special characters
@ -211,6 +227,21 @@ will output
1
```
## Traversing nested arrays by index
Given a sample.yml file of:
```yaml
- []
- - cat
```
then
```bash
yq eval '.[1][0]' sample.yml
```
will output
```yaml
cat
```
## Maps with numeric keys
Given a sample.yml file of:
```yaml

View File

@ -77,6 +77,14 @@ var traversePathOperatorScenarios = []expressionScenario{
"D0, P[{}], (!!str)::frog\n",
},
},
{
description: "Multiple special characters",
document: `a: {"key.withdots": {"another.key": apple}}`,
expression: `.a["key.withdots"]["another.key"]`,
expected: []string{
"D0, P[a key.withdots another.key], (!!str)::apple\n",
},
},
{
description: "Keys with spaces",
subdescription: "Use quotes with brackets around path elements with special characters",
@ -244,6 +252,14 @@ var traversePathOperatorScenarios = []expressionScenario{
"D0, P[0], (!!int)::1\n",
},
},
{
description: "Traversing nested arrays by index",
document: `[[], [cat]]`,
expression: `.[1][0]`,
expected: []string{
"D0, P[1 0], (!!str)::cat\n",
},
},
{
description: "Maps with numeric keys",
document: `{2: cat}`,