generated from PlexSheep/rs-base
add parser for all formats #13
|
@ -217,7 +217,7 @@ impl Format {
|
|||
///
|
||||
/// The number is assumed to be base-10 by default, it is parsed as a different
|
||||
/// [Format](format::Format) if the number is prefixed with the [prefix](format::FormatOptions::prefix),
|
||||
/// case insensitive. So if the user inputs `0b1100` then this is parsed as
|
||||
/// case sensitive. So if the user inputs `0b1100` then this is parsed as
|
||||
/// [Binary](format::Format::Bin) and so on.
|
||||
///
|
||||
/// # Example
|
||||
|
|
|
@ -198,3 +198,35 @@ fn set_format_checker() {
|
|||
options.set_format(Format::Base64);
|
||||
assert_eq!(options.format(), Format::Base64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parser_dec() {
|
||||
assert_eq!(numf_parser("1337").unwrap(), 1337);
|
||||
assert_eq!(numf_parser("0d1337").unwrap(), 1337);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parser_bin() {
|
||||
assert_eq!(numf_parser("0b11001").unwrap(), 0b11001);
|
||||
assert_eq!(numf_parser("0b11001").unwrap(), 0b11001);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parser_hex() {
|
||||
assert_eq!(numf_parser("0xdeadbeef").unwrap(), 0xdeadbeef);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parser_oct() {
|
||||
assert_eq!(numf_parser("0o771171").unwrap(), 0o771171);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parser_b64() {
|
||||
assert_eq!(numf_parser("0sQUFCQg==").unwrap(), 0x41414242);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parser_b32() {
|
||||
assert_eq!(numf_parser("IFAUEQQ=").unwrap(), 0x41414242);
|
||||
}
|
||||
|
|
Reference in New Issue