mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-02 15:14:52 +08:00
Added is_key operator
This commit is contained in:
@@ -4,6 +4,32 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var expectedIsKey = `D0, P[], (!!seq)::- p: ""
|
||||
isKey: false
|
||||
tag: '!!map'
|
||||
- p: a
|
||||
isKey: true
|
||||
tag: '!!str'
|
||||
- p: a
|
||||
isKey: false
|
||||
tag: '!!map'
|
||||
- p: a.b
|
||||
isKey: true
|
||||
tag: '!!str'
|
||||
- p: a.b
|
||||
isKey: false
|
||||
tag: '!!seq'
|
||||
- p: a.b.0
|
||||
isKey: false
|
||||
tag: '!!str'
|
||||
- p: a.c
|
||||
isKey: true
|
||||
tag: '!!str'
|
||||
- p: a.c
|
||||
isKey: false
|
||||
tag: '!!str'
|
||||
`
|
||||
|
||||
var keysOperatorScenarios = []expressionScenario{
|
||||
{
|
||||
description: "Map keys",
|
||||
@@ -75,6 +101,14 @@ var keysOperatorScenarios = []expressionScenario{
|
||||
"D0, P[a x], (!!str)::comment on key\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Check node is a key",
|
||||
document: "a: \n b: [cat]\n c: frog\n",
|
||||
expression: `[... | { "p": path | join("."), "isKey": is_key, "tag": tag }]`,
|
||||
expected: []string{
|
||||
expectedIsKey,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestKeysOperatorScenarios(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user