use super::units::*;
#[test]
fn parse() {
vec![
("base case", "2", Some(2)),
("two ok", concat!("0x18", "X", "21"), Some(0x18 * 21)),
(
"mixed types",
concat!("0x11", "X", "0o22", "X", "2"),
Some(0x11 * 0o22 * 2),
),
("multiple suffixes", concat!("0x13M", "X", "9K"), Some(0x13 * M * 9 * K)),
("bad string", "asjopdajsdomasd", None),
]
.into_iter()
.for_each(|(name, s, want)| {
let got = super::parse(s).ok();
assert_eq!(
want, got,
"{}: want number::parse(\"{}\") = {:?}, but got {:?}",
name, s, want, got
);
})
}
#[test]
fn scaled_part() {
vec![
("hex ok", "0x13", Some(0x13)),
("octal ok", "0o07", Some(0o07)),
("normal ok", "21", Some(21)),
("normal + scaling", "21K", Some(21 * K)),
("hex + scaling", "0x2BM", Some(0x2b * M)),
("octal + scaling", "0o271W", Some(0o271 * BITSIZE)),
("normal plus weird scaling", "28GB", Some(28 * GB)),
("bad hex", "0xx", None),
("bad octal", "0o8", None),
("not a number", "hello", None),
]
.into_iter()
.for_each(|(name, arg, want)| {
let got = super::parse(arg).ok();
assert_eq!(
want, got,
"{}: want number::scaled_part(\"{}\")={:?}, but got {:?}",
name, arg, want, got
);
});
}