Variable loop - Fixes #1566 (#1577)

* Variable loop wip

* Variable loop wip

* Variable loop wip

* Variable loop wip

* Fixed variable operator to work like jq
This commit is contained in:
Mike Farah
2023-02-28 16:40:38 +11:00
committed by GitHub
parent cb27444e54
commit 62d167c141
12 changed files with 112 additions and 31 deletions
+18 -2
View File
@@ -8,7 +8,7 @@ var variableOperatorScenarios = []expressionScenario{
{
skipDoc: true,
document: `{}`,
expression: `.a.b as $foo`,
expression: `.a.b as $foo | .`,
expected: []string{
"D0, P[], (doc)::{}\n",
},
@@ -16,7 +16,7 @@ var variableOperatorScenarios = []expressionScenario{
{
document: "a: [cat]",
skipDoc: true,
expression: "(.[] | {.name: .}) as $item",
expression: "(.[] | {.name: .}) as $item | .",
expectedError: `cannot index array with 'name' (strconv.ParseInt: parsing "name": invalid syntax)`,
},
{
@@ -36,6 +36,22 @@ var variableOperatorScenarios = []expressionScenario{
"D0, P[1], (!!str)::dog\n",
},
},
{
skipDoc: true,
document: `[1, 2]`,
expression: `.[] | . as $f | select($f == 2)`,
expected: []string{
"D0, P[1], (!!int)::2\n",
},
},
{
skipDoc: true,
document: `[1, 2]`,
expression: `[.[] | . as $f | $f + 1]`,
expected: []string{
"D0, P[], (!!seq)::- 2\n- 3\n",
},
},
{
description: "Using variables as a lookup",
subdescription: "Example taken from [jq](https://stedolan.github.io/jq/manual/#Variable/SymbolicBindingOperator:...as$identifier|...)",