Merge pull request #3442 from uutils/revert-3423-remove_trailing_spaces_in_rightmost_column

Revert "df: remove trailing spaces in rightmost column"
This commit is contained in:
Sylvestre Ledru 2022-04-25 08:13:10 +02:00 committed by GitHub
commit 91ccdb6479
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 15 deletions

View file

@ -401,21 +401,12 @@ impl fmt::Display for Table {
while let Some(row) = row_iter.next() {
let mut col_iter = row.iter().enumerate().peekable();
while let Some((i, elem)) = col_iter.next() {
let is_last_col = col_iter.peek().is_none();
match self.alignments[i] {
Alignment::Left => {
if is_last_col {
// no trailing spaces in last column
write!(f, "{}", elem)?;
} else {
write!(f, "{:<width$}", elem, width = self.widths[i])?;
}
}
Alignment::Left => write!(f, "{:<width$}", elem, width = self.widths[i])?,
Alignment::Right => write!(f, "{:>width$}", elem, width = self.widths[i])?,
}
if !is_last_col {
if col_iter.peek().is_some() {
// column separator
write!(f, " ")?;
}

View file

@ -425,7 +425,7 @@ fn test_output_selects_columns() {
.args(&["--output=source"])
.succeeds()
.stdout_move_str();
assert_eq!(output.lines().next().unwrap(), "Filesystem");
assert_eq!(output.lines().next().unwrap().trim_end(), "Filesystem");
let output = new_ucmd!()
.args(&["--output=source,target"])
@ -484,7 +484,7 @@ fn test_output_file_all_filesystems() {
let mut lines = output.lines();
assert_eq!(lines.next().unwrap(), "File");
for line in lines {
assert_eq!(line, "-");
assert_eq!(line, "- ");
}
}
@ -503,7 +503,7 @@ fn test_output_file_specific_files() {
.succeeds()
.stdout_move_str();
let actual: Vec<&str> = output.lines().collect();
assert_eq!(actual, vec!["File", "a", "b", "c"]);
assert_eq!(actual, vec!["File", "a ", "b ", "c "]);
}
#[test]
@ -538,5 +538,5 @@ fn test_nonexistent_file() {
.args(&["--output=file", "does-not-exist", "."])
.fails()
.stderr_is("df: does-not-exist: No such file or directory\n")
.stdout_is("File\n.\n");
.stdout_is("File\n. \n");
}