diff --git a/src/weekday.rs b/src/weekday.rs index f41b5845cf..5c62ea3ed9 100644 --- a/src/weekday.rs +++ b/src/weekday.rs @@ -171,7 +171,7 @@ impl Weekday { impl fmt::Display for Weekday { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(match *self { + f.pad(match *self { Weekday::Mon => "Mon", Weekday::Tue => "Tue", Weekday::Wed => "Wed", @@ -331,6 +331,16 @@ mod tests { } } + #[test] + fn test_formatting_alignment() { + // No exhaustive testing here as we just delegate the + // implementation to Formatter::pad. Just some basic smoke + // testing to ensure that it's in fact being done. + assert_eq!(format!("{:x>7}", Weekday::Mon), "xxxxMon"); + assert_eq!(format!("{:^7}", Weekday::Mon), " Mon "); + assert_eq!(format!("{:Z<7}", Weekday::Mon), "MonZZZZ"); + } + #[test] #[cfg(feature = "serde")] fn test_serde_serialize() {