Added is_key operator

This commit is contained in:
Mike Farah
2022-09-30 10:27:35 +10:00
parent 3dd5f0c80c
commit 55a7fdfd8a
5 changed files with 90 additions and 0 deletions
+34
View File
@@ -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) {