diff options
Diffstat (limited to 'crates/completion/src/render/macro_.rs')
-rw-r--r-- | crates/completion/src/render/macro_.rs | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/crates/completion/src/render/macro_.rs b/crates/completion/src/render/macro_.rs index 0ad8c03b3..6df121c66 100644 --- a/crates/completion/src/render/macro_.rs +++ b/crates/completion/src/render/macro_.rs | |||
@@ -114,3 +114,93 @@ fn guess_macro_braces(macro_name: &str, docs: &str) -> (&'static str, &'static s | |||
114 | .unwrap(); | 114 | .unwrap(); |
115 | (*bra, *ket) | 115 | (*bra, *ket) |
116 | } | 116 | } |
117 | |||
118 | #[cfg(test)] | ||
119 | mod tests { | ||
120 | use test_utils::mark; | ||
121 | |||
122 | use crate::test_utils::check_edit; | ||
123 | |||
124 | #[test] | ||
125 | fn dont_insert_macro_call_parens_unncessary() { | ||
126 | mark::check!(dont_insert_macro_call_parens_unncessary); | ||
127 | check_edit( | ||
128 | "frobnicate!", | ||
129 | r#" | ||
130 | //- /main.rs crate:main deps:foo | ||
131 | use foo::<|>; | ||
132 | //- /foo/lib.rs crate:foo | ||
133 | #[macro_export] | ||
134 | macro_rules frobnicate { () => () } | ||
135 | "#, | ||
136 | r#" | ||
137 | use foo::frobnicate; | ||
138 | "#, | ||
139 | ); | ||
140 | |||
141 | check_edit( | ||
142 | "frobnicate!", | ||
143 | r#" | ||
144 | macro_rules frobnicate { () => () } | ||
145 | fn main() { frob<|>!(); } | ||
146 | "#, | ||
147 | r#" | ||
148 | macro_rules frobnicate { () => () } | ||
149 | fn main() { frobnicate!(); } | ||
150 | "#, | ||
151 | ); | ||
152 | } | ||
153 | |||
154 | #[test] | ||
155 | fn guesses_macro_braces() { | ||
156 | check_edit( | ||
157 | "vec!", | ||
158 | r#" | ||
159 | /// Creates a [`Vec`] containing the arguments. | ||
160 | /// | ||
161 | /// ``` | ||
162 | /// let v = vec![1, 2, 3]; | ||
163 | /// assert_eq!(v[0], 1); | ||
164 | /// assert_eq!(v[1], 2); | ||
165 | /// assert_eq!(v[2], 3); | ||
166 | /// ``` | ||
167 | macro_rules! vec { () => {} } | ||
168 | |||
169 | fn fn main() { v<|> } | ||
170 | "#, | ||
171 | r#" | ||
172 | /// Creates a [`Vec`] containing the arguments. | ||
173 | /// | ||
174 | /// ``` | ||
175 | /// let v = vec![1, 2, 3]; | ||
176 | /// assert_eq!(v[0], 1); | ||
177 | /// assert_eq!(v[1], 2); | ||
178 | /// assert_eq!(v[2], 3); | ||
179 | /// ``` | ||
180 | macro_rules! vec { () => {} } | ||
181 | |||
182 | fn fn main() { vec![$0] } | ||
183 | "#, | ||
184 | ); | ||
185 | |||
186 | check_edit( | ||
187 | "foo!", | ||
188 | r#" | ||
189 | /// Foo | ||
190 | /// | ||
191 | /// Don't call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`, | ||
192 | /// call as `let _=foo! { hello world };` | ||
193 | macro_rules! foo { () => {} } | ||
194 | fn main() { <|> } | ||
195 | "#, | ||
196 | r#" | ||
197 | /// Foo | ||
198 | /// | ||
199 | /// Don't call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`, | ||
200 | /// call as `let _=foo! { hello world };` | ||
201 | macro_rules! foo { () => {} } | ||
202 | fn main() { foo! {$0} } | ||
203 | "#, | ||
204 | ) | ||
205 | } | ||
206 | } | ||