diff --git a/src/uu/df/src/table.rs b/src/uu/df/src/table.rs index 76aa28eac87..63a135831fc 100644 --- a/src/uu/df/src/table.rs +++ b/src/uu/df/src/table.rs @@ -432,12 +432,21 @@ 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 => write!(f, "{: { + if is_last_col { + // no trailing spaces in last column + write!(f, "{}", elem)?; + } else { + write!(f, "{: write!(f, "{:>width$}", elem, width = self.widths[i])?, } - if col_iter.peek().is_some() { + if !is_last_col { // column separator write!(f, " ")?; } diff --git a/tests/by-util/test_df.rs b/tests/by-util/test_df.rs index 78f35306298..62f6e26331f 100644 --- a/tests/by-util/test_df.rs +++ b/tests/by-util/test_df.rs @@ -742,7 +742,7 @@ fn test_output_selects_columns() { .args(&["--output=source"]) .succeeds() .stdout_move_str(); - assert_eq!(output.lines().next().unwrap().trim_end(), "Filesystem"); + assert_eq!(output.lines().next().unwrap(), "Filesystem"); let output = new_ucmd!() .args(&["--output=source,target"]) @@ -801,7 +801,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, "-"); } } @@ -821,7 +821,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] @@ -858,5 +858,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"); }