mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Use insta for ty tests
This commit is contained in:
parent
0d2cb60f93
commit
a252110616
29 changed files with 159 additions and 55 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -718,6 +718,7 @@ dependencies = [
|
|||
"arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"flexi_logger 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"insta 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -19,3 +19,4 @@ test_utils = { path = "../test_utils" }
|
|||
|
||||
[dev-dependencies]
|
||||
flexi_logger = "0.10.0"
|
||||
insta = "0.1.4"
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
Created: 2019-01-21T21:48:20.662863951+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[11; 37) '{ l... {}; }': ()
|
||||
[20; 21) 'x': ()
|
||||
[24; 34) 'if true {}': ()
|
||||
[27; 31) 'true': bool
|
||||
[32; 34) '{}': ()
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.662863969+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[11; 89) '{ ... } }': ()
|
||||
[17; 21) 'X {}': [unknown]
|
||||
[27; 87) 'match ... }': ()
|
||||
|
@ -6,3 +10,4 @@
|
|||
[56; 58) '()': ()
|
||||
[68; 74) 'A::Y()': [unknown]
|
||||
[78; 80) '()': ()
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.662935249+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[68; 262) '{ ... d; }': ()
|
||||
[78; 79) 'e': E
|
||||
[82; 95) 'E::A { x: 3 }': E
|
||||
|
@ -20,3 +24,4 @@
|
|||
[237; 248) 'E::A { .. }': E
|
||||
[251; 252) 'e': E
|
||||
[258; 259) 'd': &E
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.662961921+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[9; 10) 'x': &str
|
||||
[18; 19) 'y': isize
|
||||
[28; 293) '{ ... []; }': ()
|
||||
|
@ -50,3 +54,4 @@
|
|||
[260; 263) '"b"': &str
|
||||
[275; 276) 'x': [u8]
|
||||
[288; 290) '[]': [u8]
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.662902243+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[14; 15) 'x': u32
|
||||
[22; 24) '{}': ()
|
||||
[78; 231) '{ ...t &c }': &mut &f64
|
||||
|
@ -18,3 +22,4 @@
|
|||
[222; 229) '&mut &c': &mut &f64
|
||||
[227; 229) '&c': &f64
|
||||
[228; 229) 'c': f64
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.662874226+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[9; 10) 'a': u32
|
||||
[17; 18) 'b': isize
|
||||
[27; 28) 'c': !
|
||||
|
@ -11,3 +15,4 @@
|
|||
[88; 94) '1isize': isize
|
||||
[100; 106) '"test"': &str
|
||||
[112; 118) '1.0f32': f32
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.662972146+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[6; 7) 'x': bool
|
||||
[22; 34) '{ 0i32 }': i32
|
||||
[28; 32) '0i32': i32
|
||||
|
@ -44,3 +48,4 @@
|
|||
[341; 344) 'ten': usize
|
||||
[341; 348) 'ten < 3': bool
|
||||
[347; 348) '3': usize
|
||||
|
9
crates/ra_hir/src/ty/snapshots/tests__infer_enum.snap
Normal file
9
crates/ra_hir/src/ty/snapshots/tests__infer_enum.snap
Normal file
|
@ -0,0 +1,9 @@
|
|||
Created: 2019-01-21T21:48:20.662949719+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[48; 82) '{ E:...:V2; }': ()
|
||||
[52; 70) 'E::V1 ...d: 1 }': E
|
||||
[67; 68) '1': u32
|
||||
[74; 79) 'E::V2': E
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.671554939+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[44; 45) 'a': A
|
||||
[50; 213) '{ ...5.b; }': ()
|
||||
[60; 62) 'a1': A
|
||||
|
@ -41,3 +45,4 @@
|
|||
[256; 260) 'a1.b': B
|
||||
[266; 268) 'a2': *mut A
|
||||
[266; 270) 'a2.b': B
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.669112954+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[10; 11) 't': [unknown]
|
||||
[21; 26) '{ t }': [unknown]
|
||||
[23; 24) 't': [unknown]
|
||||
|
@ -12,3 +16,4 @@
|
|||
[90; 92) 'id': fn(T) -> T
|
||||
[90; 95) 'id(1)': T
|
||||
[93; 94) '1': T
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.672467086+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[53; 57) 'self': A<[unknown]>
|
||||
[65; 87) '{ ... }': [unknown]
|
||||
[75; 79) 'self': A<[unknown]>
|
||||
|
@ -27,3 +31,4 @@
|
|||
[244; 245) 'z': T
|
||||
[254; 255) 'b': A<T>
|
||||
[254; 259) 'b.x()': i128
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.683908196+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[79; 81) 'a1': A<u32>
|
||||
[91; 92) 'o': Option<u64>
|
||||
[107; 244) '{ ... }; }': ()
|
||||
|
@ -15,3 +19,4 @@
|
|||
[217; 218) 't': u64
|
||||
[228; 229) '_': Option<u64>
|
||||
[233; 234) '1': u64
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.670255659+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[32; 36) 'self': A
|
||||
[38; 39) 'x': u32
|
||||
[53; 55) '{}': ()
|
||||
|
@ -16,3 +20,4 @@
|
|||
[187; 188) 'a': A
|
||||
[187; 195) 'a.bar(1)': i64
|
||||
[193; 194) '1': u64
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.666406651+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[11; 71) '{ ...= b; }': ()
|
||||
[21; 22) 'a': isize
|
||||
[25; 31) '1isize': isize
|
||||
|
@ -5,3 +9,4 @@
|
|||
[52; 53) '1': usize
|
||||
[63; 64) 'c': usize
|
||||
[67; 68) 'b': usize
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.666200994+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[11; 201) '{ ...o"#; }': ()
|
||||
[17; 21) '5i32': i32
|
||||
[27; 34) '"hello"': &str
|
||||
|
@ -10,3 +14,4 @@
|
|||
[104; 108) 'true': bool
|
||||
[114; 182) 'r#" ... "#': &str
|
||||
[188; 198) 'br#"yolo"#': &[u8]
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.671399345+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[15; 20) '{ 1 }': u32
|
||||
[17; 18) '1': u32
|
||||
[48; 53) '{ 1 }': u32
|
||||
|
@ -7,3 +11,4 @@
|
|||
[73; 76) 'a()': u32
|
||||
[82; 86) 'b::c': fn() -> u32
|
||||
[82; 88) 'b::c()': u32
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.677661229+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[9; 10) 'x': &i32
|
||||
[18; 369) '{ ...o_x; }': ()
|
||||
[28; 29) 'y': &i32
|
||||
|
@ -45,3 +49,4 @@
|
|||
[339; 340) 'x': &i32
|
||||
[350; 351) 'k': &mut &i32
|
||||
[354; 366) 'mut_ref_to_x': &mut &i32
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.674183006+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[9; 10) 'a': &u32
|
||||
[18; 19) 'b': &mut u32
|
||||
[31; 32) 'c': *const u32
|
||||
|
@ -21,3 +25,4 @@
|
|||
[138; 139) 'd': *mut u32
|
||||
[145; 147) '*d': u32
|
||||
[146; 147) 'd': *mut u32
|
||||
|
|
@ -1,6 +1,11 @@
|
|||
Created: 2019-01-21T21:50:17.870325361+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[34; 38) 'self': &S
|
||||
[40; 61) '{ ... }': ()
|
||||
[50; 54) 'self': &S
|
||||
[75; 79) 'self': &S
|
||||
[88; 109) '{ ... }': ()
|
||||
[98; 102) 'self': &S
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.677495622+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[72; 154) '{ ...a.c; }': ()
|
||||
[82; 83) 'c': [unknown]
|
||||
[86; 87) 'C': [unknown]
|
||||
|
@ -14,3 +18,4 @@
|
|||
[139; 142) 'a.b': B
|
||||
[148; 149) 'a': A
|
||||
[148; 151) 'a.c': C
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.678274444+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[36; 38) 'a1': A<u32>
|
||||
[48; 49) 'i': i32
|
||||
[56; 147) '{ ...3.x; }': ()
|
||||
|
@ -13,3 +17,4 @@
|
|||
[131; 132) '1': i128
|
||||
[140; 142) 'a3': A<i128>
|
||||
[140; 144) 'a3.x': i128
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.676903109+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[9; 10) 'x': &str
|
||||
[18; 19) 'y': isize
|
||||
[28; 170) '{ ...d"); }': ()
|
||||
|
@ -25,3 +29,4 @@
|
|||
[159; 167) '(e, "d")': ((i32, &str), &str)
|
||||
[160; 161) 'e': (i32, &str)
|
||||
[163; 166) '"d"': &str
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Created: 2019-01-21T21:48:20.676213204+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[27; 28) 'x': SomeType
|
||||
[40; 197) '{ ...lo"; }': ()
|
||||
[50; 51) 'b': bool
|
||||
|
@ -26,3 +30,4 @@
|
|||
[179; 180) 'x': SomeType
|
||||
[186; 194) '-"hello"': [unknown]
|
||||
[187; 194) '"hello"': &str
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
Created: 2019-01-21T21:48:20.676654355+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_hir/src/ty/tests.rs
|
||||
|
||||
[20; 21) 'x': X
|
||||
[26; 47) '{ ...eld; }': ()
|
||||
[32; 33) 'x': X
|
||||
[32; 44) 'x.some_field': [unknown]
|
||||
|
|
@ -1,11 +1,8 @@
|
|||
use std::sync::Arc;
|
||||
use std::fmt::Write;
|
||||
use std::path::{PathBuf, Path};
|
||||
use std::fs;
|
||||
|
||||
use ra_db::{SyntaxDatabase, salsa::Database};
|
||||
use ra_syntax::ast::{self, AstNode};
|
||||
use test_utils::{project_dir, assert_eq_text, read_text};
|
||||
|
||||
use crate::{
|
||||
source_binder,
|
||||
|
@ -13,14 +10,13 @@ use crate::{
|
|||
};
|
||||
|
||||
// These tests compare the inference results for all expressions in a file
|
||||
// against snapshots of the expected results. If you change something and these
|
||||
// tests fail expectedly, you can update the comparison files by deleting them
|
||||
// and running the tests again. Similarly, to add a new test, just write the
|
||||
// test here in the same pattern and it will automatically write the snapshot.
|
||||
// against snapshots of the expected results using insta. Run the tests with
|
||||
// INSTA_UPDATE=1 to update the snapshots.
|
||||
|
||||
#[test]
|
||||
fn infer_basics() {
|
||||
check_inference(
|
||||
"infer_basics",
|
||||
r#"
|
||||
fn test(a: u32, b: isize, c: !, d: &str) {
|
||||
a;
|
||||
|
@ -32,13 +28,13 @@ fn test(a: u32, b: isize, c: !, d: &str) {
|
|||
"test";
|
||||
1.0f32;
|
||||
}"#,
|
||||
"basics.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_let() {
|
||||
check_inference(
|
||||
"infer_let",
|
||||
r#"
|
||||
fn test() {
|
||||
let a = 1isize;
|
||||
|
@ -46,13 +42,13 @@ fn test() {
|
|||
let c = b;
|
||||
}
|
||||
}"#,
|
||||
"let.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_paths() {
|
||||
check_inference(
|
||||
"infer_paths",
|
||||
r#"
|
||||
fn a() -> u32 { 1 }
|
||||
|
||||
|
@ -65,13 +61,13 @@ fn test() {
|
|||
b::c();
|
||||
}
|
||||
}"#,
|
||||
"paths.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_struct() {
|
||||
check_inference(
|
||||
"infer_struct",
|
||||
r#"
|
||||
struct A {
|
||||
b: B,
|
||||
|
@ -88,13 +84,13 @@ fn test() {
|
|||
a.c;
|
||||
}
|
||||
"#,
|
||||
"struct.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_enum() {
|
||||
check_inference(
|
||||
"infer_enum",
|
||||
r#"
|
||||
enum E {
|
||||
V1 { field: u32 },
|
||||
|
@ -104,13 +100,13 @@ fn test() {
|
|||
E::V1 { field: 1 };
|
||||
E::V2;
|
||||
}"#,
|
||||
"enum.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_refs() {
|
||||
check_inference(
|
||||
"infer_refs",
|
||||
r#"
|
||||
fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) {
|
||||
a;
|
||||
|
@ -126,13 +122,13 @@ fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) {
|
|||
*d;
|
||||
}
|
||||
"#,
|
||||
"refs_and_ptrs.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_literals() {
|
||||
check_inference(
|
||||
"infer_literals",
|
||||
r##"
|
||||
fn test() {
|
||||
5i32;
|
||||
|
@ -152,13 +148,13 @@ fn test() {
|
|||
br#"yolo"#;
|
||||
}
|
||||
"##,
|
||||
"literals.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_unary_op() {
|
||||
check_inference(
|
||||
"infer_unary_op",
|
||||
r#"
|
||||
enum SomeType {}
|
||||
|
||||
|
@ -175,13 +171,13 @@ fn test(x: SomeType) {
|
|||
-"hello";
|
||||
}
|
||||
"#,
|
||||
"unary_op.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_backwards() {
|
||||
check_inference(
|
||||
"infer_backwards",
|
||||
r#"
|
||||
fn takes_u32(x: u32) {}
|
||||
|
||||
|
@ -196,13 +192,13 @@ fn test() -> &mut &f64 {
|
|||
&mut &c
|
||||
}
|
||||
"#,
|
||||
"backwards.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_self() {
|
||||
check_inference(
|
||||
"infer_self",
|
||||
r#"
|
||||
struct S;
|
||||
|
||||
|
@ -215,13 +211,13 @@ impl S {
|
|||
}
|
||||
}
|
||||
"#,
|
||||
"self.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_binary_op() {
|
||||
check_inference(
|
||||
"infer_binary_op",
|
||||
r#"
|
||||
fn f(x: bool) -> i32 {
|
||||
0i32
|
||||
|
@ -242,13 +238,13 @@ fn test() -> bool {
|
|||
ten < 3
|
||||
}
|
||||
"#,
|
||||
"binary_op.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_field_autoderef() {
|
||||
check_inference(
|
||||
"infer_field_autoderef",
|
||||
r#"
|
||||
struct A {
|
||||
b: B,
|
||||
|
@ -273,25 +269,25 @@ fn test2(a1: *const A, a2: *mut A) {
|
|||
a2.b;
|
||||
}
|
||||
"#,
|
||||
"field_autoderef.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_bug_484() {
|
||||
fn bug_484() {
|
||||
check_inference(
|
||||
"bug_484",
|
||||
r#"
|
||||
fn test() {
|
||||
let x = if true {};
|
||||
}
|
||||
"#,
|
||||
"bug_484.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_inherent_method() {
|
||||
check_inference(
|
||||
"infer_inherent_method",
|
||||
r#"
|
||||
struct A;
|
||||
|
||||
|
@ -311,13 +307,13 @@ fn test(a: A) {
|
|||
a.bar(1);
|
||||
}
|
||||
"#,
|
||||
"inherent_method.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_tuple() {
|
||||
check_inference(
|
||||
"infer_tuple",
|
||||
r#"
|
||||
fn test(x: &str, y: isize) {
|
||||
let a: (u32, &str) = (1, "a");
|
||||
|
@ -328,13 +324,13 @@ fn test(x: &str, y: isize) {
|
|||
let f = (e, "d");
|
||||
}
|
||||
"#,
|
||||
"tuple.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_array() {
|
||||
check_inference(
|
||||
"infer_array",
|
||||
r#"
|
||||
fn test(x: &str, y: isize) {
|
||||
let a = [x];
|
||||
|
@ -354,13 +350,13 @@ fn test(x: &str, y: isize) {
|
|||
let x: [u8; 0] = [];
|
||||
}
|
||||
"#,
|
||||
"array.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_pattern() {
|
||||
check_inference(
|
||||
"infer_pattern",
|
||||
r#"
|
||||
fn test(x: &i32) {
|
||||
let y = x;
|
||||
|
@ -384,13 +380,13 @@ fn test(x: &i32) {
|
|||
let k = mut_ref_to_x;
|
||||
}
|
||||
"#,
|
||||
"pattern.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_adt_pattern() {
|
||||
check_inference(
|
||||
"infer_adt_pattern",
|
||||
r#"
|
||||
enum E {
|
||||
A { x: usize },
|
||||
|
@ -414,13 +410,13 @@ fn test() {
|
|||
d;
|
||||
}
|
||||
"#,
|
||||
"adt_pattern.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_struct_generics() {
|
||||
check_inference(
|
||||
"infer_struct_generics",
|
||||
r#"
|
||||
struct A<T> {
|
||||
x: T,
|
||||
|
@ -434,13 +430,13 @@ fn test(a1: A<u32>, i: i32) {
|
|||
a3.x;
|
||||
}
|
||||
"#,
|
||||
"struct_generics.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_generics_in_patterns() {
|
||||
check_inference(
|
||||
"infer_generics_in_patterns",
|
||||
r#"
|
||||
struct A<T> {
|
||||
x: T,
|
||||
|
@ -460,13 +456,13 @@ fn test(a1: A<u32>, o: Option<u64>) {
|
|||
};
|
||||
}
|
||||
"#,
|
||||
"generics_in_patterns.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_function_generics() {
|
||||
check_inference(
|
||||
"infer_function_generics",
|
||||
r#"
|
||||
fn id<T>(t: T) -> T { t }
|
||||
|
||||
|
@ -476,13 +472,13 @@ fn test() {
|
|||
let x: u64 = id(1);
|
||||
}
|
||||
"#,
|
||||
"function_generics.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_generic_chain() {
|
||||
check_inference(
|
||||
"infer_generic_chain",
|
||||
r#"
|
||||
struct A<T> {
|
||||
x: T,
|
||||
|
@ -503,13 +499,13 @@ fn test() -> i128 {
|
|||
b.x()
|
||||
}
|
||||
"#,
|
||||
"generic_chain.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_panic_on_field_of_enum() {
|
||||
check_inference(
|
||||
"no_panic_on_field_of_enum",
|
||||
r#"
|
||||
enum X {}
|
||||
|
||||
|
@ -517,13 +513,13 @@ fn test(x: X) {
|
|||
x.some_field;
|
||||
}
|
||||
"#,
|
||||
"no_panic_on_field_of_enum.txt",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bug_585() {
|
||||
check_inference(
|
||||
"bug_585",
|
||||
r#"
|
||||
fn test() {
|
||||
X {};
|
||||
|
@ -533,7 +529,6 @@ fn test() {
|
|||
}
|
||||
}
|
||||
"#,
|
||||
"bug_585.txt",
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -581,19 +576,10 @@ fn infer(content: &str) -> String {
|
|||
acc
|
||||
}
|
||||
|
||||
fn check_inference(content: &str, data_file: impl AsRef<Path>) {
|
||||
let data_file_path = test_data_dir().join(data_file);
|
||||
fn check_inference(name: &str, content: &str) {
|
||||
let result = infer(content);
|
||||
|
||||
if !data_file_path.exists() {
|
||||
println!("File with expected result doesn't exist, creating...\n");
|
||||
println!("{}\n{}", content, result);
|
||||
fs::write(&data_file_path, &result).unwrap();
|
||||
panic!("File {:?} with expected result was created", data_file_path);
|
||||
}
|
||||
|
||||
let expected = read_text(&data_file_path);
|
||||
assert_eq_text!(&expected, &result);
|
||||
insta::assert_snapshot_matches!(&name, &result);
|
||||
}
|
||||
|
||||
fn ellipsize(mut text: String, max_len: usize) -> String {
|
||||
|
@ -614,10 +600,6 @@ fn ellipsize(mut text: String, max_len: usize) -> String {
|
|||
text
|
||||
}
|
||||
|
||||
fn test_data_dir() -> PathBuf {
|
||||
project_dir().join("crates/ra_hir/src/ty/tests/data")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
|
||||
let (mut db, pos) = MockDatabase::with_position(
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
[48; 82) '{ E:...:V2; }': ()
|
||||
[52; 70) 'E::V1 ...d: 1 }': E
|
||||
[67; 68) '1': u32
|
||||
[74; 79) 'E::V2': E
|
|
@ -1,4 +0,0 @@
|
|||
[20; 21) 'x': X
|
||||
[26; 47) '{ ...eld; }': ()
|
||||
[32; 33) 'x': X
|
||||
[32; 44) 'x.some_field': [unknown]
|
Loading…
Reference in a new issue