Skip to content

Commit c81c450

Browse files
committed
tests/df: test trailing zeros
1 parent f03c452 commit c81c450

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

src/uu/df/src/blocks.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,28 +242,45 @@ mod tests {
242242
use crate::blocks::{BlockSize, SuffixType, to_magnitude_and_suffix};
243243

244244
#[test]
245-
fn test_to_magnitude_and_suffix_powers_of_1024() {
245+
fn test_to_magnitude_and_suffix_add_tracing_zero() {
246246
assert_eq!(to_magnitude_and_suffix(1024, SuffixType::Iec, true), "1.0K");
247+
assert_eq!(to_magnitude_and_suffix(2048, SuffixType::Iec, true), "2.0K");
247248
assert_eq!(to_magnitude_and_suffix(10240, SuffixType::Iec, true), "10K");
249+
250+
assert_eq!(to_magnitude_and_suffix(1024, SuffixType::Iec, false), "1K");
251+
assert_eq!(to_magnitude_and_suffix(2048, SuffixType::Iec, false), "2K");
252+
assert_eq!(
253+
to_magnitude_and_suffix(10240, SuffixType::Iec, false),
254+
"10K"
255+
);
256+
}
257+
258+
#[test]
259+
fn test_to_magnitude_and_suffix_powers_of_1024() {
260+
assert_eq!(to_magnitude_and_suffix(1024, SuffixType::Iec, false), "1K");
261+
assert_eq!(
262+
to_magnitude_and_suffix(10240, SuffixType::Iec, false),
263+
"10K"
264+
);
248265
assert_eq!(to_magnitude_and_suffix(2048, SuffixType::Iec, false), "2K");
249266
assert_eq!(
250267
to_magnitude_and_suffix(1024 * 40, SuffixType::Iec, false),
251268
"40K"
252269
);
253270
assert_eq!(
254-
to_magnitude_and_suffix(1024 * 1024, SuffixType::Iec, true),
255-
"1.0M"
271+
to_magnitude_and_suffix(1024 * 1024, SuffixType::Iec, false),
272+
"1M"
256273
);
257274
assert_eq!(
258-
to_magnitude_and_suffix(2 * 1024 * 1024, SuffixType::Iec, true),
259-
"2.0M"
275+
to_magnitude_and_suffix(2 * 1024 * 1024, SuffixType::Iec, false),
276+
"2M"
260277
);
261278
assert_eq!(
262-
to_magnitude_and_suffix(1024 * 1024 * 1024, SuffixType::Iec, true),
263-
"1.0G"
279+
to_magnitude_and_suffix(1024 * 1024 * 1024, SuffixType::Iec, false),
280+
"1G"
264281
);
265282
assert_eq!(
266-
to_magnitude_and_suffix(34 * 1024 * 1024 * 1024, SuffixType::Iec, true),
283+
to_magnitude_and_suffix(34 * 1024 * 1024 * 1024, SuffixType::Iec, false),
267284
"34G"
268285
);
269286
}

tests/by-util/test_df.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ fn test_df_follows_symlinks() {
139139
);
140140
}
141141

142+
#[test]
143+
fn test_df_trailing_zeros() {
144+
use regex::Regex;
145+
146+
new_ucmd!()
147+
.arg("-h")
148+
.arg("--output=size,used")
149+
.arg("--total")
150+
.succeeds()
151+
.stdout_does_not_match(&Regex::new("\\s[1-9][A-Z]").unwrap());
152+
}
153+
142154
#[test]
143155
fn test_df_output_overridden() {
144156
let expected = if cfg!(target_os = "macos") {

0 commit comments

Comments
 (0)