aboutsummaryrefslogtreecommitdiff
path: root/crates/completion/src/render/macro_.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/completion/src/render/macro_.rs')
-rw-r--r--crates/completion/src/render/macro_.rs90
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)]
119mod 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
131use foo::<|>;
132//- /foo/lib.rs crate:foo
133#[macro_export]
134macro_rules frobnicate { () => () }
135"#,
136 r#"
137use foo::frobnicate;
138"#,
139 );
140
141 check_edit(
142 "frobnicate!",
143 r#"
144macro_rules frobnicate { () => () }
145fn main() { frob<|>!(); }
146"#,
147 r#"
148macro_rules frobnicate { () => () }
149fn 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/// ```
167macro_rules! vec { () => {} }
168
169fn 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/// ```
180macro_rules! vec { () => {} }
181
182fn 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 };`
193macro_rules! foo { () => {} }
194fn main() { <|> }
195"#,
196 r#"
197/// Foo
198///
199/// Don't call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`,
200/// call as `let _=foo! { hello world };`
201macro_rules! foo { () => {} }
202fn main() { foo! {$0} }
203"#,
204 )
205 }
206}