|
|
@ -55,7 +55,7 @@ fn push_literal(frag: &mut Vec<Fragment>, unescaped_literal: &str) -> Result<(),
|
|
|
|
/// Parses the display hint (e.g. the `ipv4` in `{:ipv4}`).
|
|
|
|
/// Parses the display hint (e.g. the `ipv4` in `{:ipv4}`).
|
|
|
|
fn parse_display_hint(s: &str) -> Result<DisplayHint, String> {
|
|
|
|
fn parse_display_hint(s: &str) -> Result<DisplayHint, String> {
|
|
|
|
Ok(match s {
|
|
|
|
Ok(match s {
|
|
|
|
"x" => DisplayHint::LowerHex,
|
|
|
|
"p" | "x" => DisplayHint::LowerHex,
|
|
|
|
"X" => DisplayHint::UpperHex,
|
|
|
|
"X" => DisplayHint::UpperHex,
|
|
|
|
"i" => DisplayHint::Ip,
|
|
|
|
"i" => DisplayHint::Ip,
|
|
|
|
"mac" => DisplayHint::LowerMac,
|
|
|
|
"mac" => DisplayHint::LowerMac,
|
|
|
@ -145,7 +145,7 @@ mod test {
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
fn test_parse() {
|
|
|
|
fn test_parse() {
|
|
|
|
assert_eq!(
|
|
|
|
assert_eq!(
|
|
|
|
parse("foo {} bar {:x} test {:X} ayy {:i} lmao {{}} {{something}}"),
|
|
|
|
parse("foo {} bar {:x} test {:X} ayy {:i} lmao {{}} {{something}} {:p}"),
|
|
|
|
Ok(vec![
|
|
|
|
Ok(vec![
|
|
|
|
Fragment::Literal("foo ".into()),
|
|
|
|
Fragment::Literal("foo ".into()),
|
|
|
|
Fragment::Parameter(Parameter {
|
|
|
|
Fragment::Parameter(Parameter {
|
|
|
@ -164,6 +164,9 @@ mod test {
|
|
|
|
hint: DisplayHint::Ip
|
|
|
|
hint: DisplayHint::Ip
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
Fragment::Literal(" lmao {} {something} ".into()),
|
|
|
|
Fragment::Literal(" lmao {} {something} ".into()),
|
|
|
|
|
|
|
|
Fragment::Parameter(Parameter {
|
|
|
|
|
|
|
|
hint: DisplayHint::LowerHex
|
|
|
|
|
|
|
|
}),
|
|
|
|
])
|
|
|
|
])
|
|
|
|
);
|
|
|
|
);
|
|
|
|
assert!(parse("foo {:}").is_err());
|
|
|
|
assert!(parse("foo {:}").is_err());
|
|
|
|