Skip to content

Commit

Permalink
Fix Display macro to handle fill/align (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peternator7 committed Jun 12, 2020
1 parent a20ee16 commit 95645ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion strum_macros/src/macros/strings/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 8 additions & 0 deletions strum_tests/tests/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 95645ca

Please sign in to comment.