@@ -59,6 +59,18 @@ fn parser_undefined_placeholder_in_replacement() {
59
59
) ;
60
60
}
61
61
62
+ #[ test]
63
+ fn parse_let_stmt_without_semicolon ( ) {
64
+ assert_eq ! (
65
+ parse_error_text( "let $a = $b ==>> $b" ) ,
66
+ "Parse error: Not a valid Rust expression, type, item, path or pattern"
67
+ ) ;
68
+ assert_eq ! (
69
+ parse_error_text( "let $a = $b; ==>> let $a = 10" ) ,
70
+ "Parse error: Not a valid Rust expression, type, item, path or pattern"
71
+ ) ;
72
+ }
73
+
62
74
/// `code` may optionally contain a cursor marker `<|>`. If it doesn't, then the position will be
63
75
/// the start of the file. If there's a second cursor marker, then we'll return a single range.
64
76
pub ( crate ) fn single_file ( code : & str ) -> ( ide_db:: RootDatabase , FilePosition , Vec < FileRange > ) {
@@ -159,6 +171,52 @@ fn assert_match_failure_reason(pattern: &str, code: &str, snippet: &str, expecte
159
171
assert_eq ! ( reasons, vec![ expected_reason] ) ;
160
172
}
161
173
174
+ #[ test]
175
+ fn ssr_let_stmt_in_macro_match ( ) {
176
+ // FIXME: Matcher::validate_range rejects this even though arguments
177
+ // in a macro call should be matched, see match_nested_method_calls_with_macro_call
178
+
179
+ // assert_matches(
180
+ // "let a = 0",
181
+ // r#"
182
+ // macro_rules! m1 { ($a:stmt) => {$a}; }
183
+ // fn f() {m1!{ let a = 0 };}"#,
184
+ // &["let a = 0"],
185
+ // );
186
+ }
187
+
188
+ #[ test]
189
+ fn ssr_let_stmt_in_fn_match ( ) {
190
+ assert_matches ( "let $a = 10;" , "fn main() { let x = 10; x }" , & [ "let x = 10;" ] ) ;
191
+ assert_matches ( "let $a = $b;" , "fn main() { let x = 10; x }" , & [ "let x = 10;" ] ) ;
192
+ }
193
+
194
+ #[ test]
195
+ fn ssr_block_expr_match ( ) {
196
+ assert_matches ( "{ let $a = $b; }" , "fn main() { let x = 10; }" , & [ "{ let x = 10; }" ] ) ;
197
+ assert_matches ( "{ let $a = $b; $c }" , "fn main() { let x = 10; x }" , & [ "{ let x = 10; x }" ] ) ;
198
+ }
199
+
200
+ #[ test]
201
+ fn ssr_let_stmt_replace ( ) {
202
+ // Pattern and template with trailing semicolon
203
+ assert_ssr_transform (
204
+ "let $a = $b; ==>> let $a = 11;" ,
205
+ "fn main() { let x = 10; x }" ,
206
+ expect ! [ [ "fn main() { let x = 11; x }" ] ] ,
207
+ ) ;
208
+ }
209
+
210
+ #[ test]
211
+ fn ssr_let_stmt_replace_expr ( ) {
212
+ // Trailing semicolon should be dropped from the new expression
213
+ assert_ssr_transform (
214
+ "let $a = $b; ==>> $b" ,
215
+ "fn main() { let x = 10; }" ,
216
+ expect ! [ [ "fn main() { 10 }" ] ] ,
217
+ ) ;
218
+ }
219
+
162
220
#[ test]
163
221
fn ssr_function_to_method ( ) {
164
222
assert_ssr_transform (
0 commit comments