1 use darling::FromDeriveInput;
2 use syn::{parse_quote, Ident, LitStr, Path};
3 
4 #[derive(Debug, FromDeriveInput)]
5 #[darling(supports(struct_unit), attributes(bar))]
6 pub struct Bar {
7     pub ident: Ident,
8     pub st: Path,
9     pub file: LitStr,
10 }
11 
12 /// Per [#96](https://github.com/TedDriggs/darling/issues/96), make sure that an
13 /// attribute which isn't a valid meta gets an error.
14 /// Properties can be split across multiple attributes; this test ensures that one
15 /// non-meta attribute does not interfere with the parsing of other, well-formed attributes.
16 #[test]
non_meta_attribute_does_not_block_others()17 fn non_meta_attribute_does_not_block_others() {
18     let di = parse_quote! {
19         #[derive(Bar)]
20         #[bar(st = RocketEngine: Debug)]
21         #[bar(file = "motors/example_6.csv")]
22         pub struct EstesC6;
23     };
24 
25     let errors: darling::Error = Bar::from_derive_input(&di).unwrap_err().flatten();
26     // The number of errors here is 2:
27     // - The parsing error caused by a where-clause body where it doesn't belong
28     // - The missing `st` value because the parsing failure blocked that attribute from
29     //   being read.
30     assert_eq!(2, errors.len());
31 }
32