Debian Codegraph @

third_party/rust/syn/tests/test_meta.rs

raw
1 #![allow(
2 clippy::needless_lifetimes,
3 clippy::shadow_unrelated,
4 clippy::too_many_lines,
5 clippy::uninlined_format_args
6 )]
7
8 #[macro_use]
9 mod macros;
10
11 use syn::{Meta, MetaList, MetaNameValue};
12
13 #[test]
14 fn test_parse_meta_item_word() {
15 let input = "hello";
16
17 snapshot!(input as Meta, @r#"
18 Meta::Path {
19 segments: [
20 PathSegment {
21 ident: "hello",
22 },
23 ],
24 }
25 "#);
26 }
27
28 #[test]
29 fn test_parse_meta_name_value() {
30 let input = "foo = 5";
31 let (inner, meta) = (input, input);
32
33 snapshot!(inner as MetaNameValue, @r#"
34 MetaNameValue {
35 path: Path {
36 segments: [
37 PathSegment {
38 ident: "foo",
39 },
40 ],
41 },
42 value: Expr::Lit {
43 lit: 5,
44 },
45 }
46 "#);
47
48 snapshot!(meta as Meta, @r#"
49 Meta::NameValue {
50 path: Path {
51 segments: [
52 PathSegment {
53 ident: "foo",
54 },
55 ],
56 },
57 value: Expr::Lit {
58 lit: 5,
59 },
60 }
61 "#);
62
63 assert_eq!(meta, Meta::NameValue(inner));
64 }
65
66 #[test]
67 fn test_parse_meta_item_list_lit() {
68 let input = "foo(5)";
69 let (inner, meta) = (input, input);
70
71 snapshot!(inner as MetaList, @r#"
72 MetaList {
73 path: Path {
74 segments: [
75 PathSegment {
76 ident: "foo",
77 },
78 ],
79 },
80 delimiter: MacroDelimiter::Paren,
81 tokens: TokenStream(`5`),
82 }
83 "#);
84
85 snapshot!(meta as Meta, @r#"
86 Meta::List {
87 path: Path {
88 segments: [
89 PathSegment {
90 ident: "foo",
91 },
92 ],
93 },
94 delimiter: MacroDelimiter::Paren,
95 tokens: TokenStream(`5`),
96 }
97 "#);
98
99 assert_eq!(meta, Meta::List(inner));
100 }
101
102 #[test]
103 fn test_parse_meta_item_multiple() {
104 let input = "foo(word, name = 5, list(name2 = 6), word2)";
105 let (inner, meta) = (input, input);
106
107 snapshot!(inner as MetaList, @r#"
108 MetaList {
109 path: Path {
110 segments: [
111 PathSegment {
112 ident: "foo",
113 },
114 ],
115 },
116 delimiter: MacroDelimiter::Paren,
117 tokens: TokenStream(`word , name = 5 , list (name2 = 6) , word2`),
118 }
119 "#);
120
121 snapshot!(meta as Meta, @r#"
122 Meta::List {
123 path: Path {
124 segments: [
125 PathSegment {
126 ident: "foo",
127 },
128 ],
129 },
130 delimiter: MacroDelimiter::Paren,
131 tokens: TokenStream(`word , name = 5 , list (name2 = 6) , word2`),
132 }
133 "#);
134
135 assert_eq!(meta, Meta::List(inner));
136 }
137
138 #[test]
139 fn test_parse_path() {
140 let input = "::serde::Serialize";
141 snapshot!(input as Meta, @r#"
142 Meta::Path {
143 leading_colon: Some,
144 segments: [
145 PathSegment {
146 ident: "serde",
147 },
148 Token![::],
149 PathSegment {
150 ident: "Serialize",
151 },
152 ],
153 }
154 "#);
155 }