sort_by works on maps

This commit is contained in:
Mike Farah
2025-01-22 14:36:50 +11:00
parent 1508f1fd5f
commit f202d06d82
8 changed files with 116 additions and 35 deletions
+18
View File
@@ -84,6 +84,24 @@ var sortByOperatorScenarios = []expressionScenario{
"D0, P[], (!!map)::cool: [{a: banana}, {b: banana}, {c: banana}]\n",
},
},
{
description: "Sort a map",
subdescription: "Sorting a map, by default this will sort by the values",
document: "y: b\nz: a\nx: c\n",
expression: `sort`,
expected: []string{
"D0, P[], (!!map)::z: a\ny: b\nx: c\n",
},
},
{
description: "Sort a map by keys",
subdescription: "Use sort_by to sort a map using a custom function",
document: "Y: b\nz: a\nx: c\n",
expression: `sort_by(key | downcase)`,
expected: []string{
"D0, P[], (!!map)::x: c\nY: b\nz: a\n",
},
},
{
description: "Sort is stable",
subdescription: "Note the order of the elements in unchanged when equal in sorting.",