Skip to content

Commit 380b872

Browse files
committed
ssr: Add tests for raw LetStmt matching
1 parent 4e351e8 commit 380b872

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

crates/ssr/src/tests.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,50 @@ fn assert_match_failure_reason(pattern: &str, code: &str, snippet: &str, expecte
159159
assert_eq!(reasons, vec![expected_reason]);
160160
}
161161

162+
#[test]
163+
fn ssr_let_stmt_in_macro_match() {
164+
assert_matches(
165+
"let a = 0",
166+
r#"
167+
macro_rules! m1 { ($a:stmt) => {$a}; }
168+
fn f() {m1!{ let a = 0 };}"#,
169+
// FIXME: Whitespace is not part of the matched block
170+
&["leta=0"],
171+
);
172+
}
173+
174+
#[test]
175+
fn ssr_let_stmt_in_fn_match() {
176+
assert_matches("let $a = 10;", "fn main() { let x = 10; x }", &["let x = 10;"]);
177+
assert_matches("let $a = $b;", "fn main() { let x = 10; x }", &["let x = 10;"]);
178+
}
179+
180+
#[test]
181+
fn ssr_block_expr_match() {
182+
assert_matches("{ let $a = $b; }", "fn main() { let x = 10; }", &["{ let x = 10; }"]);
183+
assert_matches("{ let $a = $b; $c }", "fn main() { let x = 10; x }", &["{ let x = 10; x }"]);
184+
}
185+
186+
#[test]
187+
fn ssr_let_stmt_replace() {
188+
// Pattern and template with trailing semicolon
189+
assert_ssr_transform(
190+
"let $a = $b; ==>> let $a = 11;",
191+
"fn main() { let x = 10; x }",
192+
expect![["fn main() { let x = 11; x }"]],
193+
);
194+
}
195+
196+
#[test]
197+
fn ssr_let_stmt_replace_expr() {
198+
// Trailing semicolon should be dropped from the new expression
199+
assert_ssr_transform(
200+
"let $a = $b; ==>> $b",
201+
"fn main() { let x = 10; }",
202+
expect![["fn main() { 10 }"]],
203+
);
204+
}
205+
162206
#[test]
163207
fn ssr_function_to_method() {
164208
assert_ssr_transform(

0 commit comments

Comments
 (0)