Debian Codegraph @

.cargo/vendor/syn/tests/test_parse_quote.rs

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