mirror of
https://github.com/nushell/nushell.git
synced 2025-04-11 06:48:31 +02:00
add TiB and PiB (#3257)
This commit is contained in:
parent
1c941557c3
commit
4c09716ad8
@ -341,6 +341,8 @@ fn parse_unit(lite_arg: &Spanned<String>) -> (SpannedExpression, Option<ParseErr
|
|||||||
(Unit::Kibibyte, "KIB", Some((Unit::Byte, 1024))),
|
(Unit::Kibibyte, "KIB", Some((Unit::Byte, 1024))),
|
||||||
(Unit::Mebibyte, "MIB", Some((Unit::Kibibyte, 1024))),
|
(Unit::Mebibyte, "MIB", Some((Unit::Kibibyte, 1024))),
|
||||||
(Unit::Gibibyte, "GIB", Some((Unit::Mebibyte, 1024))),
|
(Unit::Gibibyte, "GIB", Some((Unit::Mebibyte, 1024))),
|
||||||
|
(Unit::Tebibyte, "TIB", Some((Unit::Gibibyte, 1024))),
|
||||||
|
(Unit::Pebibyte, "PIB", Some((Unit::Tebibyte, 1024))),
|
||||||
(Unit::Byte, "B", None),
|
(Unit::Byte, "B", None),
|
||||||
(Unit::Nanosecond, "NS", None),
|
(Unit::Nanosecond, "NS", None),
|
||||||
(Unit::Microsecond, "US", Some((Unit::Nanosecond, 1000))),
|
(Unit::Microsecond, "US", Some((Unit::Nanosecond, 1000))),
|
||||||
@ -2179,6 +2181,26 @@ fn unit_parse_byte_units() {
|
|||||||
value: 123,
|
value: 123,
|
||||||
unit: Unit::Gibibyte,
|
unit: Unit::Gibibyte,
|
||||||
},
|
},
|
||||||
|
TestCase {
|
||||||
|
string: String::from("10tib"),
|
||||||
|
value: 10,
|
||||||
|
unit: Unit::Tebibyte,
|
||||||
|
},
|
||||||
|
TestCase {
|
||||||
|
string: String::from("123TiB"),
|
||||||
|
value: 123,
|
||||||
|
unit: Unit::Tebibyte,
|
||||||
|
},
|
||||||
|
TestCase {
|
||||||
|
string: String::from("10pib"),
|
||||||
|
value: 10,
|
||||||
|
unit: Unit::Pebibyte,
|
||||||
|
},
|
||||||
|
TestCase {
|
||||||
|
string: String::from("123PiB"),
|
||||||
|
value: 123,
|
||||||
|
unit: Unit::Pebibyte,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
for case in cases.iter() {
|
for case in cases.iter() {
|
||||||
|
@ -356,6 +356,8 @@ pub enum Unit {
|
|||||||
Kibibyte,
|
Kibibyte,
|
||||||
Mebibyte,
|
Mebibyte,
|
||||||
Gibibyte,
|
Gibibyte,
|
||||||
|
Tebibyte,
|
||||||
|
Pebibyte,
|
||||||
|
|
||||||
// Duration units
|
// Duration units
|
||||||
Nanosecond,
|
Nanosecond,
|
||||||
@ -546,6 +548,8 @@ impl Unit {
|
|||||||
Unit::Kibibyte => "KiB",
|
Unit::Kibibyte => "KiB",
|
||||||
Unit::Mebibyte => "MiB",
|
Unit::Mebibyte => "MiB",
|
||||||
Unit::Gibibyte => "GiB",
|
Unit::Gibibyte => "GiB",
|
||||||
|
Unit::Tebibyte => "TiB",
|
||||||
|
Unit::Pebibyte => "PiB",
|
||||||
Unit::Nanosecond => "ns",
|
Unit::Nanosecond => "ns",
|
||||||
Unit::Microsecond => "us",
|
Unit::Microsecond => "us",
|
||||||
Unit::Millisecond => "ms",
|
Unit::Millisecond => "ms",
|
||||||
@ -575,6 +579,10 @@ impl Unit {
|
|||||||
Unit::Kibibyte => filesize(convert_number_to_u64(&size) * 1024),
|
Unit::Kibibyte => filesize(convert_number_to_u64(&size) * 1024),
|
||||||
Unit::Mebibyte => filesize(convert_number_to_u64(&size) * 1024 * 1024),
|
Unit::Mebibyte => filesize(convert_number_to_u64(&size) * 1024 * 1024),
|
||||||
Unit::Gibibyte => filesize(convert_number_to_u64(&size) * 1024 * 1024 * 1024),
|
Unit::Gibibyte => filesize(convert_number_to_u64(&size) * 1024 * 1024 * 1024),
|
||||||
|
Unit::Tebibyte => filesize(convert_number_to_u64(&size) * 1024 * 1024 * 1024 * 1024),
|
||||||
|
Unit::Pebibyte => {
|
||||||
|
filesize(convert_number_to_u64(&size) * 1024 * 1024 * 1024 * 1024 * 1024)
|
||||||
|
}
|
||||||
|
|
||||||
Unit::Nanosecond => duration(size.to_bigint().expect("Conversion should never fail.")),
|
Unit::Nanosecond => duration(size.to_bigint().expect("Conversion should never fail.")),
|
||||||
Unit::Microsecond => {
|
Unit::Microsecond => {
|
||||||
|
Loading…
Reference in New Issue
Block a user