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