1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

tail: use "parse_size" from uucore

This commit is contained in:
Jan Scheer 2021-05-28 21:12:03 +02:00
parent b1b3475e11
commit 0bf14da490
2 changed files with 16 additions and 144 deletions

View file

@ -1,6 +1,5 @@
extern crate tail;
use self::tail::parse_size;
use crate::common::util::*;
use std::char::from_digit;
use std::io::Write;
@ -236,41 +235,6 @@ fn test_bytes_big() {
}
}
#[test]
fn test_parse_size() {
// No suffix.
assert_eq!(Ok(1234), parse_size("1234"));
// kB is 1000
assert_eq!(Ok(9 * 1000), parse_size("9kB"));
// K is 1024
assert_eq!(Ok(2 * 1024), parse_size("2K"));
let suffixes = [
('M', 2u32),
('G', 3u32),
('T', 4u32),
('P', 5u32),
('E', 6u32),
];
for &(c, exp) in &suffixes {
let s = format!("2{}B", c);
assert_eq!(Ok(2 * (1000 as u64).pow(exp)), parse_size(&s));
let s = format!("2{}", c);
assert_eq!(Ok(2 * (1024 as u64).pow(exp)), parse_size(&s));
}
// Sizes that are too big.
assert!(parse_size("1Z").is_err());
assert!(parse_size("1Y").is_err());
// Bad number
assert!(parse_size("328hdsf3290").is_err());
}
#[test]
fn test_lines_with_size_suffix() {
const FILE: &'static str = "test_lines_with_size_suffix.txt";