Skip to content

Commit 771c047

Browse files
horazontdjc
authored andcommitted
Use Formatter::pad (instead of write_str) for Weekdays
That way, width, alignment and fill from the format string are respected. Fixes #1620.
1 parent d8a177e commit 771c047

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/weekday.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl Weekday {
171171

172172
impl fmt::Display for Weekday {
173173
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
174-
f.write_str(match *self {
174+
f.pad(match *self {
175175
Weekday::Mon => "Mon",
176176
Weekday::Tue => "Tue",
177177
Weekday::Wed => "Wed",
@@ -331,6 +331,16 @@ mod tests {
331331
}
332332
}
333333

334+
#[test]
335+
fn test_formatting_alignment() {
336+
// No exhaustive testing here as we just delegate the
337+
// implementation to Formatter::pad. Just some basic smoke
338+
// testing to ensure that it's in fact being done.
339+
assert_eq!(format!("{:x>7}", Weekday::Mon), "xxxxMon");
340+
assert_eq!(format!("{:^7}", Weekday::Mon), " Mon ");
341+
assert_eq!(format!("{:Z<7}", Weekday::Mon), "MonZZZZ");
342+
}
343+
334344
#[test]
335345
#[cfg(feature = "serde")]
336346
fn test_serde_serialize() {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy