mirror of
https://github.com/LeopoldArkham/humansize
synced 2025-02-16 20:18:24 +00:00
Add tests
This commit is contained in:
parent
3c18dfb312
commit
cc8878d122
1 changed files with 94 additions and 0 deletions
|
@ -65,4 +65,98 @@ fn test_sizes() {
|
|||
"-5.50 KB"
|
||||
);
|
||||
assert_eq!((5500).file_size(&semi_custom_options7).unwrap(), "5.50 KB");
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn use_custom_option_struct_twice() {
|
||||
let options = file_size_opts::FileSizeOpts {
|
||||
long_units: true,
|
||||
..file_size_opts::DECIMAL
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
1500.file_size(&options).unwrap(),
|
||||
"1.50 Kilobyte",
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
2500.file_size(&options).unwrap(),
|
||||
"2.50 Kilobytes",
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn pluralization_works() {
|
||||
let options = file_size_opts::FileSizeOpts {
|
||||
long_units: true,
|
||||
decimal_zeroes: 2,
|
||||
..file_size_opts::DECIMAL
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
1.file_size(&options).unwrap(),
|
||||
"1.00 Byte",
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
1000.file_size(&options).unwrap(),
|
||||
"1.00 Kilobyte",
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
1000000.file_size(&options).unwrap(),
|
||||
"1.00 Megabyte",
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
1000000000.file_size(&options).unwrap(),
|
||||
"1.00 Gigabyte",
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
1000000000000_i64.file_size(&options).unwrap(),
|
||||
"1.00 Terabyte",
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
1000000000000000_i64.file_size(&options).unwrap(),
|
||||
"1.00 Petabyte",
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
1000000000000000000_i64.file_size(&options).unwrap(),
|
||||
"1.00 Exabyte",
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn max_value_decimal() {
|
||||
let options = file_size_opts::FileSizeOpts {
|
||||
long_units: true,
|
||||
decimal_places: 7,
|
||||
..file_size_opts::DECIMAL
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
(std::u64::MAX).file_size(&options).unwrap(),
|
||||
"18.4467441 Exabytes",
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn max_value_binary() {
|
||||
let options = file_size_opts::FileSizeOpts {
|
||||
long_units: true,
|
||||
decimal_places: 7,
|
||||
..file_size_opts::BINARY
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
(std::u64::MAX).file_size(&options).unwrap(),
|
||||
"16 Exbibytes",
|
||||
);
|
||||
}
|
Loading…
Add table
Reference in a new issue