Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ef2f89b5 authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi Committed by Automerger Merge Worker
Browse files

Merge "floss: DisplayAddress: Print leading zero" am: 5cdd5572

parents 6cb52c55 5cdd5572
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -824,7 +824,7 @@ impl RawAddress {
pub struct DisplayAddress<'a>(pub &'a RawAddress);
impl<'a> Display for DisplayAddress<'a> {
    fn fmt(&self, f: &mut Formatter) -> Result {
        write!(f, "xx:xx:xx:xx:{:2X}:{:2X}", &self.0.address[4], &self.0.address[5])
        write!(f, "xx:xx:xx:xx:{:02X}:{:02X}", &self.0.address[4], &self.0.address[5])
    }
}

@@ -1367,4 +1367,24 @@ mod tests {
            });
        }
    }

    #[test]
    fn test_display_address() {
        assert_eq!(
            format!("{}", DisplayAddress(&RawAddress::from_string("00:00:00:00:00:00").unwrap())),
            String::from("xx:xx:xx:xx:00:00")
        );
        assert_eq!(
            format!("{}", DisplayAddress(&RawAddress::from_string("1a:2b:1a:2b:1a:2b").unwrap())),
            String::from("xx:xx:xx:xx:1A:2B")
        );
        assert_eq!(
            format!("{}", DisplayAddress(&RawAddress::from_string("3C:4D:3C:4D:3C:4D").unwrap())),
            String::from("xx:xx:xx:xx:3C:4D")
        );
        assert_eq!(
            format!("{}", DisplayAddress(&RawAddress::from_string("11:35:11:35:11:35").unwrap())),
            String::from("xx:xx:xx:xx:11:35")
        );
    }
}