1
0
mirror of https://github.com/danog/strum.git synced 2024-11-30 04:28:59 +01:00

Fix Display macro to handle fill/align

This commit is contained in:
root 2020-05-23 22:33:23 +00:00
parent a20ee16d6b
commit 740e62cda3
2 changed files with 9 additions and 1 deletions

View File

@ -47,7 +47,7 @@ pub fn display_inner(ast: &syn::DeriveInput) -> TokenStream {
Named(..) => quote! { {..} }, Named(..) => quote! { {..} },
}; };
arms.push(quote! { #name::#ident #params => f.write_str(#output) }); arms.push(quote! { #name::#ident #params => f.pad(#output) });
} }
if arms.len() < variants.len() { if arms.len() < variants.len() {

View File

@ -19,6 +19,14 @@ fn to_blue_string() {
assert_eq!(String::from("blue"), format!("{}", Color::Blue { hue: 0 })); assert_eq!(String::from("blue"), format!("{}", Color::Blue { hue: 0 }));
} }
#[test]
fn test_formatters() {
assert_eq!(String::from(" blue"), format!("{:>6}", Color::Blue { hue: 0 }));
assert_eq!(String::from("blue "), format!("{:<6}", Color::Blue { hue: 0 }));
assert_eq!(String::from(" blue "), format!("{:^6}", Color::Blue { hue: 0 }));
assert_eq!(String::from("bl"), format!("{:.2}", Color::Blue { hue: 0 }));
}
#[test] #[test]
fn to_yellow_string() { fn to_yellow_string() {
assert_eq!(String::from("yellow"), format!("{}", Color::Yellow)); assert_eq!(String::from("yellow"), format!("{}", Color::Yellow));