Skip to content

Commit 0b6b3c2

Browse files
committed
tests/df: test 3 digit rounding
Signed-off-by: Alexander Bakanovskii <[email protected]>
1 parent 3cae6c6 commit 0b6b3c2

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/uu/df/src/blocks.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,34 @@ mod tests {
243243

244244
use crate::blocks::{BlockSize, SuffixType, to_magnitude_and_suffix};
245245

246+
#[test]
247+
fn test_to_magnitude_and_suffix_rounding() {
248+
assert_eq!(
249+
to_magnitude_and_suffix(999440, SuffixType::Si, true),
250+
"1.0MB"
251+
);
252+
assert_eq!(
253+
to_magnitude_and_suffix(819200, SuffixType::Si, true),
254+
"820kB"
255+
);
256+
assert_eq!(
257+
to_magnitude_and_suffix(819936, SuffixType::Si, true),
258+
"820kB"
259+
);
260+
assert_eq!(
261+
to_magnitude_and_suffix(818400, SuffixType::Si, true),
262+
"819kB"
263+
);
264+
assert_eq!(
265+
to_magnitude_and_suffix(817600, SuffixType::Si, true),
266+
"818kB"
267+
);
268+
assert_eq!(
269+
to_magnitude_and_suffix(817200, SuffixType::Si, true),
270+
"818kB"
271+
);
272+
}
273+
246274
#[test]
247275
fn test_to_magnitude_and_suffix_add_tracing_zero() {
248276
assert_eq!(to_magnitude_and_suffix(1024, SuffixType::Iec, true), "1.0K");

tests/by-util/test_df.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ fn test_df_trailing_zeros() {
151151
.stdout_does_not_match(&Regex::new("\\s[1-9][A-Z]").unwrap());
152152
}
153153

154+
#[test]
155+
fn test_df_rounding() {
156+
use regex::Regex;
157+
158+
new_ucmd!()
159+
.arg("-H")
160+
.arg("--output=size,used")
161+
.arg("--total")
162+
.succeeds()
163+
.stdout_does_not_match(&Regex::new("\\s\\d{3}\\.\\d[A-Z]").unwrap());
164+
}
165+
154166
#[test]
155167
fn test_df_output_overridden() {
156168
let expected = if cfg!(target_os = "macos") {

0 commit comments

Comments
 (0)