mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
implement sort --stable
Made a new function sort_by(lines, compare_fns), which accepts a list of compare_fns and calls lines.sort_by() with a closure that calls each compare_fn in turn until one returns something other than equal. Default behavior ensures that String::cmp is the last element in the compare_fns list (referred to as 'last resort' sorting by man sort). Passing --stable (-s) turns this behaviour off. Test cases provided for `sort --month` and `sort --month --stable`.
This commit is contained in:
parent
bb1e0540a3
commit
6751d2c708
6 changed files with 66 additions and 6 deletions
3
tests/fixtures/sort/month_default.expected
vendored
3
tests/fixtures/sort/month_default.expected
vendored
|
@ -3,5 +3,8 @@ Jan Lorem ipsum dolor sit amet
|
|||
mar laboris nisi ut aliquip ex ea
|
||||
May sed do eiusmod tempor incididunt
|
||||
JUN nostrud exercitation ullamco
|
||||
Jul 1 should remain 2,1,3
|
||||
Jul 2 these three lines
|
||||
Jul 3 if --stable is provided
|
||||
Oct ut labore et dolore magna aliqua
|
||||
Dec consectetur adipiscing elit
|
||||
|
|
3
tests/fixtures/sort/month_default.txt
vendored
3
tests/fixtures/sort/month_default.txt
vendored
|
@ -5,3 +5,6 @@ Oct ut labore et dolore magna aliqua
|
|||
N/A Ut enim ad minim veniam, quis
|
||||
JUN nostrud exercitation ullamco
|
||||
mar laboris nisi ut aliquip ex ea
|
||||
Jul 2 these three lines
|
||||
Jul 1 should remain 2,1,3
|
||||
Jul 3 if --stable is provided
|
||||
|
|
10
tests/fixtures/sort/month_stable.expected
vendored
Normal file
10
tests/fixtures/sort/month_stable.expected
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
N/A Ut enim ad minim veniam, quis
|
||||
Jan Lorem ipsum dolor sit amet
|
||||
mar laboris nisi ut aliquip ex ea
|
||||
May sed do eiusmod tempor incididunt
|
||||
JUN nostrud exercitation ullamco
|
||||
Jul 2 these three lines
|
||||
Jul 1 should remain 2,1,3
|
||||
Jul 3 if --stable is provided
|
||||
Oct ut labore et dolore magna aliqua
|
||||
Dec consectetur adipiscing elit
|
10
tests/fixtures/sort/month_stable.txt
vendored
Normal file
10
tests/fixtures/sort/month_stable.txt
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
Jan Lorem ipsum dolor sit amet
|
||||
Dec consectetur adipiscing elit
|
||||
May sed do eiusmod tempor incididunt
|
||||
Oct ut labore et dolore magna aliqua
|
||||
N/A Ut enim ad minim veniam, quis
|
||||
JUN nostrud exercitation ullamco
|
||||
mar laboris nisi ut aliquip ex ea
|
||||
Jul 2 these three lines
|
||||
Jul 1 should remain 2,1,3
|
||||
Jul 3 if --stable is provided
|
Loading…
Add table
Add a link
Reference in a new issue