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 (#95)

This commit is contained in:
Peter Glotfelty 2020-06-12 13:54:51 -07:00 committed by GitHub
parent a20ee16d6b
commit 95645cac52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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! { {..} },
};
arms.push(quote! { #name::#ident #params => f.write_str(#output) });
arms.push(quote! { #name::#ident #params => f.pad(#output) });
}
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 }));
}
#[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]
fn to_yellow_string() {
assert_eq!(String::from("yellow"), format!("{}", Color::Yellow));