1#[macro_use]
2mod macros;
3
4use syn::punctuated::Punctuated;
5use syn::{parse_quote, Attribute, Field, Lit, Pat, Stmt, Token};
6
7#[test]
8fn test_attribute() {
9    let attr: Attribute = parse_quote!(#[test]);
10    snapshot!(attr, @r###"
11    Attribute {
12        style: AttrStyle::Outer,
13        meta: Meta::Path {
14            segments: [
15                PathSegment {
16                    ident: "test",
17                },
18            ],
19        },
20    }
21    "###);
22
23    let attr: Attribute = parse_quote!(#![no_std]);
24    snapshot!(attr, @r###"
25    Attribute {
26        style: AttrStyle::Inner,
27        meta: Meta::Path {
28            segments: [
29                PathSegment {
30                    ident: "no_std",
31                },
32            ],
33        },
34    }
35    "###);
36}
37
38#[test]
39fn test_field() {
40    let field: Field = parse_quote!(pub enabled: bool);
41    snapshot!(field, @r###"
42    Field {
43        vis: Visibility::Public,
44        ident: Some("enabled"),
45        colon_token: Some,
46        ty: Type::Path {
47            path: Path {
48                segments: [
49                    PathSegment {
50                        ident: "bool",
51                    },
52                ],
53            },
54        },
55    }
56    "###);
57
58    let field: Field = parse_quote!(primitive::bool);
59    snapshot!(field, @r###"
60    Field {
61        vis: Visibility::Inherited,
62        ty: Type::Path {
63            path: Path {
64                segments: [
65                    PathSegment {
66                        ident: "primitive",
67                    },
68                    Token![::],
69                    PathSegment {
70                        ident: "bool",
71                    },
72                ],
73            },
74        },
75    }
76    "###);
77}
78
79#[test]
80fn test_pat() {
81    let pat: Pat = parse_quote!(Some(false) | None);
82    snapshot!(&pat, @r###"
83    Pat::Or {
84        cases: [
85            Pat::TupleStruct {
86                path: Path {
87                    segments: [
88                        PathSegment {
89                            ident: "Some",
90                        },
91                    ],
92                },
93                elems: [
94                    Pat::Lit(ExprLit {
95                        lit: Lit::Bool {
96                            value: false,
97                        },
98                    }),
99                ],
100            },
101            Token![|],
102            Pat::Ident {
103                ident: "None",
104            },
105        ],
106    }
107    "###);
108
109    let boxed_pat: Box<Pat> = parse_quote!(Some(false) | None);
110    assert_eq!(*boxed_pat, pat);
111}
112
113#[test]
114fn test_punctuated() {
115    let punctuated: Punctuated<Lit, Token![|]> = parse_quote!(true | true);
116    snapshot!(punctuated, @r###"
117    [
118        Lit::Bool {
119            value: true,
120        },
121        Token![|],
122        Lit::Bool {
123            value: true,
124        },
125    ]
126    "###);
127
128    let punctuated: Punctuated<Lit, Token![|]> = parse_quote!(true | true |);
129    snapshot!(punctuated, @r###"
130    [
131        Lit::Bool {
132            value: true,
133        },
134        Token![|],
135        Lit::Bool {
136            value: true,
137        },
138        Token![|],
139    ]
140    "###);
141}
142
143#[test]
144fn test_vec_stmt() {
145    let stmts: Vec<Stmt> = parse_quote! {
146        let _;
147        true
148    };
149    snapshot!(stmts, @r###"
150    [
151        Stmt::Local {
152            pat: Pat::Wild,
153        },
154        Stmt::Expr(
155            Expr::Lit {
156                lit: Lit::Bool {
157                    value: true,
158                },
159            },
160            None,
161        ),
162    ]
163    "###);
164}
165