1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #1968 from alstolten/feat2

ls: Implements extension sorting
This commit is contained in:
Sylvestre Ledru 2021-04-26 09:03:06 +02:00 committed by GitHub
commit 7dcc8c2960
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 81 additions and 2 deletions

View file

@ -1696,3 +1696,53 @@ fn test_ls_deref_command_line_dir() {
assert!(!result.stdout_str().ends_with("sym_dir"));
}
#[test]
fn test_ls_sort_extension() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
for filename in &[
"file1",
"file2",
"anotherFile",
".hidden",
".file.1",
".file.2",
"file.1",
"file.2",
"anotherFile.1",
"anotherFile.2",
"file.ext",
"file.debug",
"anotherFile.ext",
"anotherFile.debug",
] {
at.touch(filename);
}
let expected = vec![
".",
"..",
".hidden",
"anotherFile",
"file1",
"file2",
".file.1",
"anotherFile.1",
"file.1",
".file.2",
"anotherFile.2",
"file.2",
"anotherFile.debug",
"file.debug",
"anotherFile.ext",
"file.ext",
"", // because of '\n' at the end of the output
];
let result = scene.ucmd().arg("-1aX").run();
assert_eq!(result.stdout_str().split('\n').collect::<Vec<_>>(), expected,);
let result = scene.ucmd().arg("-1a").arg("--sort=extension").run();
assert_eq!(result.stdout_str().split('\n').collect::<Vec<_>>(), expected,);
}