Skip to content

Commit 02162ab

Browse files
committed
df: fix formatting, add test case and fix linting
1 parent 83b06da commit 02162ab

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

src/uu/df/src/blocks.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ pub(crate) fn read_block_size(matches: &ArgMatches) -> Result<BlockSize, ParseSi
191191
}
192192
}
193193

194-
195194
impl fmt::Display for BlockSize {
196195
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
197196
match self {

src/uu/df/src/table.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,13 @@ impl<'a> RowFormatter<'a> {
311311
bytes_column.bytes
312312
};
313313
to_magnitude_and_suffix(size.into(), SuffixType::HumanReadable(h), true)
314-
}else {
314+
} else {
315315
match &self.options.block_size {
316-
/// if it has a suffix, append it to the size (but not on the 'total' row)
316+
// if it has a suffix, append it to the size (but not on the 'total' row)
317317
BlockSize::PrefixedBytes(_, suffix) if !self.is_total_row => {
318-
format!("{}{}", size, suffix)
318+
format!("{size}{suffix}")
319319
}
320-
/// else, just print the raw number as before
320+
// else, just print the raw number as before
321321
_ => size.to_string(),
322322
}
323323
};
@@ -332,11 +332,11 @@ impl<'a> RowFormatter<'a> {
332332
to_magnitude_and_suffix(size, SuffixType::HumanReadable(h), true)
333333
} else {
334334
match &self.options.block_size {
335-
/// if it has a suffix, append it to the size (but not on the 'total' row)
335+
// if it has a suffix, append it to the size (but not on the 'total' row)
336336
BlockSize::PrefixedBytes(_, suffix) if !self.is_total_row => {
337-
format!("{}{}", size, suffix)
337+
format!("{size}{suffix}")
338338
}
339-
/// else, just print the raw number as before
339+
// else, just print the raw number as before
340340
_ => size.to_string(),
341341
}
342342
};

tests/by-util/test_df.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,18 +1172,26 @@ fn test_blocksize_output_suffix() {
11721172
}
11731173

11741174
let val_m = get_size_value(&["-BM"]);
1175-
assert!(val_m.ends_with('M'), "Expected suffix 'M', got: {}", val_m);
1175+
assert!(val_m.ends_with('M'), "Expected suffix 'M', got: {val_m}");
11761176

11771177
let val_k = get_size_value(&["-BK"]);
1178-
assert!(val_k.ends_with('K'), "Expected suffix 'K', got: {}", val_k);
1178+
assert!(val_k.ends_with('K'), "Expected suffix 'K', got: {val_k}");
11791179

11801180
let val_mega = get_size_value(&["-m"]);
1181-
assert!(!val_mega.ends_with('M'), "Expected NO suffix 'M' for -m, got: {}", val_mega);
1181+
assert!(
1182+
!val_mega.ends_with('M'),
1183+
"Expected NO suffix 'M' for -m, got: {val_mega}"
1184+
);
11821185

11831186
let val_kilo = get_size_value(&["-k"]);
1184-
assert!(!val_kilo.ends_with('K'), "Expected NO suffix 'K' for -k, got: {}", val_kilo);
1187+
assert!(
1188+
!val_kilo.ends_with('K'),
1189+
"Expected NO suffix 'K' for -k, got: {val_kilo}"
1190+
);
11851191

11861192
let val_numeric = get_size_value(&["-B", "1048576"]);
1187-
assert!(!val_numeric.ends_with('M'), "Expected NO suffix 'M' for numeric blocks, got: {}", val_numeric);
1193+
assert!(
1194+
!val_numeric.ends_with('M'),
1195+
"Expected NO suffix 'M' for numeric blocks, got: {val_numeric}"
1196+
);
11881197
}
1189-

0 commit comments

Comments
 (0)