mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-07 02:48:27 +08:00
sort_by works on maps
This commit is contained in:
@@ -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.",
|
||||
|
||||
Reference in New Issue
Block a user