Add tests for byte pretty-printing

This commit is contained in:
Vinícius R. Miguel 2021-04-06 03:08:44 -03:00
parent 1b9faab96a
commit 42b139f1a5

View File

@ -26,7 +26,7 @@ where
}
#[cfg(test)]
mod tests {
mod argparsing {
use super::{make_dummy_files};
use crate::cli;
use crate::cli::Command;
@ -103,6 +103,77 @@ mod tests {
}
}
#[cfg(test)]
mod byte_pretty_printing {
use crate::bytes::Bytes;
#[test]
fn bytes () {
assert_eq!(
&format!("{}", Bytes::new(234)),
"234.00 B"
);
assert_eq!(
&format!("{}", Bytes::new(999)),
"999.00 B"
);
}
#[test]
fn kilobytes () {
assert_eq!(
&format!("{}", Bytes::new(2234)),
"2.23 kB"
);
assert_eq!(
&format!("{}", Bytes::new(62500)),
"62.50 kB"
);
assert_eq!(
&format!("{}", Bytes::new(329990)),
"329.99 kB"
);
}
#[test]
fn megabytes () {
assert_eq!(
&format!("{}", Bytes::new(2750000)),
"2.75 MB"
);
assert_eq!(
&format!("{}", Bytes::new(55000000)),
"55.00 MB"
);
assert_eq!(
&format!("{}", Bytes::new(987654321)),
"987.65 MB"
);
}
#[test]
fn gigabytes () {
assert_eq!(
&format!("{}", Bytes::new(5280000000)),
"5.28 GB"
);
assert_eq!(
&format!("{}", Bytes::new(95200000000)),
"95.20 GB"
);
assert_eq!(
&format!("{}", Bytes::new(302000000000)),
"302.00 GB"
);
}
}
// #[cfg(test)]
// mod cli {
// use super::*;