1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 04:27:45 +00:00

Merge pull request #3615 from anastygnome/fork

ls: Remove unnecessary trailing space when using the comma format (-m)
This commit is contained in:
Sylvestre Ledru 2022-06-14 18:12:10 +02:00 committed by GitHub
commit 045c047d20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View file

@ -1874,7 +1874,12 @@ fn display_additional_leading_info(
} else {
"?".to_owned()
};
write!(result, "{} ", pad_left(&s, padding.block_size)).unwrap();
// extra space is insert to align the sizes, as needed for all formats, except for the comma format.
if config.format == Format::Commas {
write!(result, "{} ", s).unwrap();
} else {
write!(result, "{} ", pad_left(&s, padding.block_size)).unwrap();
};
}
Ok(result)
}

View file

@ -803,6 +803,30 @@ fn test_ls_commas() {
}
}
#[test]
fn test_ls_commas_trailing() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch(&at.plus_as_string("test-commas-trailing-2"));
at.touch(&at.plus_as_string("test-commas-trailing-1"));
at.append(
"test-commas-trailing-1",
&(0..2000)
.map(|x| x.to_string())
.collect::<Vec<_>>()
.join("\n"),
);
scene
.ucmd()
.arg("-sm")
.arg("./test-commas-trailing-1")
.arg("./test-commas-trailing-2")
.succeeds()
.stdout_matches(&Regex::new(r"\S$").unwrap()); // matches if there is no whitespace at the end of stdout.
}
#[test]
fn test_ls_long() {
let scene = TestScenario::new(util_name!());