Can use expressions in slice #1419

This commit is contained in:
Mike Farah
2022-11-10 18:03:18 +11:00
parent af7e36bd47
commit 04847502bf
8 changed files with 189 additions and 138 deletions
+9
View File
@@ -37,6 +37,15 @@ var sliceArrayScenarios = []expressionScenario{
"D0, P[], (!!seq)::- dog\n- frog\n",
},
},
{
description: "Inserting into the middle of an array",
subdescription: "using an expression to find the index",
document: `[cat, dog, frog, cow]`,
expression: `(.[] | select(. == "dog") | key + 1) as $pos | .[0:($pos)] + ["rabbit"] + .[$pos:]`,
expected: []string{
"D0, P[], (!!seq)::- cat\n- dog\n- rabbit\n- frog\n- cow\n",
},
},
{
skipDoc: true,
document: `[[cat, dog, frog, cow], [apple, banana, grape, mango]]`,