1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
extern crate human_format;
use human_format::*;
#[test]
fn should_allow_use_of_si_scale_implicitly() {
assert_eq!(Formatter::new()
.format(1000 as f64),
"1.00 k");
}
#[test]
fn should_allow_explicit_decimals() {
assert_eq!(Formatter::new()
.with_decimals(1)
.format(1000 as f64),
"1.0 k");
}
#[test]
fn should_allow_explicit_separator() {
assert_eq!(Formatter::new()
.with_separator(" - ")
.format(1000 as f64),
"1.00 - k");
}
#[test]
fn should_allow_use_of_si_scale_explicitly() {
assert_eq!(Formatter::new()
.with_scales(Scales::SI())
.format(1000 as f64),
"1.00 k");
}
#[test]
fn should_allow_use_of_binary_scale_explicitly() {
assert_eq!(Formatter::new()
.with_scales(Scales::Binary())
.format(1024 as f64),
"1.00 Ki");
}
#[test]
fn should_allow_use_of_binary_units_explicitly() {
assert_eq!(Formatter::new()
.with_scales(Scales::Binary())
.with_units("B")
.format(102400 as f64),
"100.00 KiB");
}
#[test]
fn should_output_10_24MiB() {
assert_eq!(Formatter::new()
.with_scales(Scales::Binary())
.with_units("B")
.format(1024.0 * 1024.0 as f64),
"1.00 MiB");
}
#[test]
fn should_allow_explicit_suffix_and_unit() {
assert_eq!(Formatter::new()
.with_suffix("k")
.with_units("m")
.format(1024 as f64),
"1.02 km");
}
#[test]
fn should_allow_use_of_explicit_scale() {
let mut scales = Scales::new();
scales
.with_base(1024)
.with_suffixes(vec!["","Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"]);
assert_eq!(Formatter::new()
.with_scales(scales)
.with_units("B")
.format(1024 as f64),
"1.00 KiB");
}
#[test]
fn should_allow_parsing_to_f64() {
assert_eq!(Formatter::new()
.parse("1.00 k"), 1000.0);
}
#[test]
fn should_allow_parsing_binary_values_to_f64() {
assert_eq!(Formatter::new()
.with_scales(Scales::Binary())
.parse("1.00 Ki"), 1024.0);
}
#[test]
fn should_allow_parsing_binary_values_with_units_to_f64() {
assert_eq!(Formatter::new()
.with_scales(Scales::Binary())
.with_units("B")
.parse("1.00 KiB"), 1024.0);
}
|