Skip to content

Commit 5e142fd

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

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
@@ -135,6 +135,18 @@ fn test_df_trailing_zeros() {
135135
.stdout_does_not_match(&Regex::new("\\s[1-9][A-Z]").unwrap());
136136
}
137137

138+
#[test]
139+
fn test_df_rounding() {
140+
use regex::Regex;
141+
142+
new_ucmd!()
143+
.arg("-H")
144+
.arg("--output=size,used")
145+
.arg("--total")
146+
.succeeds()
147+
.stdout_does_not_match(&Regex::new("\\s\\d{3}\\.\\d[A-Z]").unwrap());
148+
}
149+
138150
#[test]
139151
fn test_df_output_overridden() {
140152
let expected = if cfg!(target_os = "macos") {

0 commit comments

Comments
 (0)