forked from extern/nushell
nu-parser + nu-protocol: switch to metric for KB, MB, GB, add KiB, MiB, GiB units (#3035)
fixes inconsistency with formatting/rendering which uses standard Rust byte_unit https://en.wikipedia.org/wiki/Byte#Multiple-byte_units
This commit is contained in:
@ -332,6 +332,9 @@ fn parse_unit(lite_arg: &Spanned<String>) -> (SpannedExpression, Option<ParseErr
|
||||
(Unit::Gigabyte, vec!["gb", "GB", "Gb", "gB"]),
|
||||
(Unit::Terabyte, vec!["tb", "TB", "Tb", "tB"]),
|
||||
(Unit::Petabyte, vec!["pb", "PB", "Pb", "pB"]),
|
||||
(Unit::Kibibyte, vec!["KiB", "kib", "kiB", "Kib"]),
|
||||
(Unit::Mebibyte, vec!["MiB", "mib", "miB", "Mib"]),
|
||||
(Unit::Gibibyte, vec!["GiB", "gib", "giB", "Gib"]),
|
||||
(Unit::Nanosecond, vec!["ns"]),
|
||||
(Unit::Microsecond, vec!["us"]),
|
||||
(Unit::Millisecond, vec!["ms"]),
|
||||
@ -2215,6 +2218,41 @@ fn unit_parse_byte_units() -> Result<(), ParseError> {
|
||||
value: 27,
|
||||
unit: Unit::Petabyte,
|
||||
},
|
||||
TestCase {
|
||||
string: String::from("10kib"),
|
||||
value: 10,
|
||||
unit: Unit::Kibibyte,
|
||||
},
|
||||
TestCase {
|
||||
string: String::from("123KiB"),
|
||||
value: 123,
|
||||
unit: Unit::Kibibyte,
|
||||
},
|
||||
TestCase {
|
||||
string: String::from("24kiB"),
|
||||
value: 24,
|
||||
unit: Unit::Kibibyte,
|
||||
},
|
||||
TestCase {
|
||||
string: String::from("10mib"),
|
||||
value: 10,
|
||||
unit: Unit::Mebibyte,
|
||||
},
|
||||
TestCase {
|
||||
string: String::from("123MiB"),
|
||||
value: 123,
|
||||
unit: Unit::Mebibyte,
|
||||
},
|
||||
TestCase {
|
||||
string: String::from("10gib"),
|
||||
value: 10,
|
||||
unit: Unit::Gibibyte,
|
||||
},
|
||||
TestCase {
|
||||
string: String::from("123GiB"),
|
||||
value: 123,
|
||||
unit: Unit::Gibibyte,
|
||||
},
|
||||
];
|
||||
|
||||
for case in cases.iter() {
|
||||
|
Reference in New Issue
Block a user