1 //! In case of bad input, parsing should fail. The error should have locations set in derived implementations.
2 
3 // The use of fields in debug print commands does not count as "used",
4 // which causes the fields to trigger an unwanted dead code warning.
5 #![allow(dead_code)]
6 
7 use darling::{FromDeriveInput, FromMeta};
8 use syn::parse_quote;
9 
10 #[derive(Debug, FromMeta)]
11 struct Dolor {
12     #[darling(rename = "amet")]
13     sit: bool,
14     world: bool,
15 }
16 
17 #[derive(Debug, FromDeriveInput)]
18 #[darling(from_ident, attributes(hello))]
19 struct Lorem {
20     ident: syn::Ident,
21     ipsum: Dolor,
22 }
23 
24 impl From<syn::Ident> for Lorem {
from(ident: syn::Ident) -> Self25     fn from(ident: syn::Ident) -> Self {
26         Lorem {
27             ident,
28             ipsum: Dolor {
29                 sit: false,
30                 world: true,
31             },
32         }
33     }
34 }
35 
36 #[test]
parsing_fail()37 fn parsing_fail() {
38     let di = parse_quote! {
39         #[hello(ipsum(amet = "yes", world = false))]
40         pub struct Foo;
41     };
42 
43     println!("{}", Lorem::from_derive_input(&di).unwrap_err());
44 }
45 
46 #[test]
missing_field()47 fn missing_field() {
48     let di = parse_quote! {
49         #[hello(ipsum(amet = true))]
50         pub struct Foo;
51     };
52 
53     println!("{}", Lorem::from_derive_input(&di).unwrap_err());
54 }
55