Added SETPATH operator

This commit is contained in:
Mike Farah
2022-10-05 14:12:08 +11:00
parent 7f4c8e1c78
commit da3f3b93b4
6 changed files with 174 additions and 1 deletions
+30
View File
@@ -63,6 +63,36 @@ var pathOperatorScenarios = []expressionScenario{
"D0, P[a 2], (!!seq)::- path:\n - a\n - 2\n value: frog\n",
},
},
{
description: "Set path",
document: `{a: {b: cat}}`,
expression: `setpath(["a", "b"]; "things")`,
expected: []string{
"D0, P[], (doc)::{a: {b: things}}\n",
},
},
{
description: "Set on empty document",
expression: `setpath(["a", "b"]; "things")`,
expected: []string{
"D0, P[], ()::a:\n b: things\n",
},
},
{
description: "Set array path",
document: `a: [cat, frog]`,
expression: `setpath(["a", 0]; "things")`,
expected: []string{
"D0, P[], (doc)::a: [things, frog]\n",
},
},
{
description: "Set array path empty",
expression: `setpath(["a", 0]; "things")`,
expected: []string{
"D0, P[], ()::a:\n - things\n",
},
},
}
func TestPathOperatorsScenarios(t *testing.T) {