Length (and some other operators) should not include head/foot comments #1231

This commit is contained in:
Mike Farah
2022-05-31 16:28:53 +10:00
parent 70403375d7
commit 8d3be1a23c
15 changed files with 122 additions and 25 deletions
+18
View File
@@ -62,6 +62,15 @@ var entriesOperatorScenarios = []expressionScenario{
"D0, P[], (!!map)::KEY_c: 1\nKEY_d: 2\n",
},
},
{
skipDoc: true,
document: `[{a: 1, b: 2}, {c: 1, d: 2}]`,
expression: `.[] | with_entries(.key |= "KEY_" + .)`,
expected: []string{
"D0, P[], (!!map)::KEY_a: 1\nKEY_b: 2\n",
"D0, P[], (!!map)::KEY_c: 1\nKEY_d: 2\n",
},
},
{
description: "Use with_entries to filter the map",
document: `{a: { b: bird }, c: { d: dog }}`,
@@ -70,6 +79,15 @@ var entriesOperatorScenarios = []expressionScenario{
"D0, P[], (!!map)::a: {b: bird}\n",
},
},
{
description: "Use with_entries to filter the map; head comment",
skipDoc: true,
document: "# abc\n{a: { b: bird }, c: { d: dog }}\n# xyz",
expression: `with_entries(select(.value | has("b")))`,
expected: []string{
"D0, P[], (!!map)::# abc\na: {b: bird}\n# xyz\n",
},
},
}
func TestEntriesOperatorScenarios(t *testing.T) {