aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r--crates/ra_hir_ty/src/tests/patterns.rs82
-rw-r--r--crates/ra_hir_ty/src/tests/regression.rs2
2 files changed, 84 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/ra_hir_ty/src/tests/patterns.rs
index 8fa296137..f937426bd 100644
--- a/crates/ra_hir_ty/src/tests/patterns.rs
+++ b/crates/ra_hir_ty/src/tests/patterns.rs
@@ -271,6 +271,63 @@ fn test() {
271} 271}
272 272
273#[test] 273#[test]
274fn infer_pattern_match_string_literal() {
275 assert_snapshot!(
276 infer_with_mismatches(r#"
277fn test() {
278 let s: &str = "hello";
279 match s {
280 "hello" => {}
281 _ => {}
282 }
283}
284"#, true),
285 @r###"
286 10..98 '{ ... } }': ()
287 20..21 's': &str
288 30..37 '"hello"': &str
289 43..96 'match ... }': ()
290 49..50 's': &str
291 61..68 '"hello"': &str
292 61..68 '"hello"': &str
293 72..74 '{}': ()
294 83..84 '_': &str
295 88..90 '{}': ()
296 "###
297 );
298}
299
300#[test]
301fn infer_pattern_match_or() {
302 assert_snapshot!(
303 infer_with_mismatches(r#"
304fn test() {
305 let s: &str = "hello";
306 match s {
307 "hello" | "world" => {}
308 _ => {}
309 }
310}
311"#, true),
312 @r###"
313 10..108 '{ ... } }': ()
314 20..21 's': &str
315 30..37 '"hello"': &str
316 43..106 'match ... }': ()
317 49..50 's': &str
318 61..68 '"hello"': &str
319 61..68 '"hello"': &str
320 61..78 '"hello...world"': &str
321 71..78 '"world"': &str
322 71..78 '"world"': &str
323 82..84 '{}': ()
324 93..94 '_': &str
325 98..100 '{}': ()
326 "###
327 );
328}
329
330#[test]
274fn infer_pattern_match_arr() { 331fn infer_pattern_match_arr() {
275 assert_snapshot!( 332 assert_snapshot!(
276 infer(r#" 333 infer(r#"
@@ -570,3 +627,28 @@ fn test() {
570 "### 627 "###
571 ); 628 );
572} 629}
630
631#[test]
632fn slice_tail_pattern() {
633 assert_snapshot!(
634 infer(r#"
635fn foo(params: &[i32]) {
636 match params {
637 [head, tail @ ..] => {
638 }
639 }
640}
641"#),
642 @r###"
643 7..13 'params': &[i32]
644 23..92 '{ ... } }': ()
645 29..90 'match ... }': ()
646 35..41 'params': &[i32]
647 52..69 '[head,... @ ..]': [i32]
648 53..57 'head': &i32
649 59..68 'tail @ ..': &[i32]
650 66..68 '..': [i32]
651 73..84 '{ }': ()
652 "###
653 );
654}
diff --git a/crates/ra_hir_ty/src/tests/regression.rs b/crates/ra_hir_ty/src/tests/regression.rs
index eedaa27ba..aa37326df 100644
--- a/crates/ra_hir_ty/src/tests/regression.rs
+++ b/crates/ra_hir_ty/src/tests/regression.rs
@@ -500,6 +500,8 @@ fn foo(params: &[usize]) {
500 31..78 'match ... }': () 500 31..78 'match ... }': ()
501 37..43 'params': &[usize] 501 37..43 'params': &[usize]
502 54..66 '[ps @ .., _]': [usize] 502 54..66 '[ps @ .., _]': [usize]
503 55..62 'ps @ ..': &[usize]
504 60..62 '..': [usize]
503 64..65 '_': usize 505 64..65 '_': usize
504 70..72 '{}': () 506 70..72 '{}': ()
505 "### 507 "###