Can specify parent levels #1970

This commit is contained in:
Mike Farah
2024-03-12 10:49:26 +11:00
parent 9e9cb65ec0
commit 8a07e3da3d
4 changed files with 97 additions and 4 deletions
+17
View File
@@ -21,6 +21,23 @@ var parentOperatorScenarios = []expressionScenario{
"D0, P[b], (!!map)::{fruit: banana, name: sam}\n",
},
},
{
description: "N-th parent",
subdescription: "You can optionally supply the number of levels to go up for the parent, the default being 1.",
document: "a:\n b:\n c: cat\n",
expression: `.a.b.c | parent(2)`,
expected: []string{
"D0, P[a], (!!map)::b:\n c: cat\n",
},
},
{
description: "N-th parent - another level",
document: "a:\n b:\n c: cat\n",
expression: `.a.b.c | parent(3)`,
expected: []string{
"D0, P[], (!!map)::a:\n b:\n c: cat\n",
},
},
{
description: "No parent",
document: `{}`,