Use insta for ty tests

This commit is contained in:
Florian Diebold 2019-01-21 22:52:35 +01:00
parent 0d2cb60f93
commit a252110616
29 changed files with 159 additions and 55 deletions

1
Cargo.lock generated
View file

@ -718,6 +718,7 @@ dependencies = [
"arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "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)", "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)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -19,3 +19,4 @@ test_utils = { path = "../test_utils" }
[dev-dependencies] [dev-dependencies]
flexi_logger = "0.10.0" flexi_logger = "0.10.0"
insta = "0.1.4"

View file

@ -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... {}; }': () [11; 37) '{ l... {}; }': ()
[20; 21) 'x': () [20; 21) 'x': ()
[24; 34) 'if true {}': () [24; 34) 'if true {}': ()
[27; 31) 'true': bool [27; 31) 'true': bool
[32; 34) '{}': () [32; 34) '{}': ()

View file

@ -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) '{ ... } }': () [11; 89) '{ ... } }': ()
[17; 21) 'X {}': [unknown] [17; 21) 'X {}': [unknown]
[27; 87) 'match ... }': () [27; 87) 'match ... }': ()
@ -6,3 +10,4 @@
[56; 58) '()': () [56; 58) '()': ()
[68; 74) 'A::Y()': [unknown] [68; 74) 'A::Y()': [unknown]
[78; 80) '()': () [78; 80) '()': ()

View file

@ -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; }': () [68; 262) '{ ... d; }': ()
[78; 79) 'e': E [78; 79) 'e': E
[82; 95) 'E::A { x: 3 }': E [82; 95) 'E::A { x: 3 }': E
@ -20,3 +24,4 @@
[237; 248) 'E::A { .. }': E [237; 248) 'E::A { .. }': E
[251; 252) 'e': E [251; 252) 'e': E
[258; 259) 'd': &E [258; 259) 'd': &E

View file

@ -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 [9; 10) 'x': &str
[18; 19) 'y': isize [18; 19) 'y': isize
[28; 293) '{ ... []; }': () [28; 293) '{ ... []; }': ()
@ -50,3 +54,4 @@
[260; 263) '"b"': &str [260; 263) '"b"': &str
[275; 276) 'x': [u8] [275; 276) 'x': [u8]
[288; 290) '[]': [u8] [288; 290) '[]': [u8]

View file

@ -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 [14; 15) 'x': u32
[22; 24) '{}': () [22; 24) '{}': ()
[78; 231) '{ ...t &c }': &mut &f64 [78; 231) '{ ...t &c }': &mut &f64
@ -18,3 +22,4 @@
[222; 229) '&mut &c': &mut &f64 [222; 229) '&mut &c': &mut &f64
[227; 229) '&c': &f64 [227; 229) '&c': &f64
[228; 229) 'c': f64 [228; 229) 'c': f64

View file

@ -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 [9; 10) 'a': u32
[17; 18) 'b': isize [17; 18) 'b': isize
[27; 28) 'c': ! [27; 28) 'c': !
@ -11,3 +15,4 @@
[88; 94) '1isize': isize [88; 94) '1isize': isize
[100; 106) '"test"': &str [100; 106) '"test"': &str
[112; 118) '1.0f32': f32 [112; 118) '1.0f32': f32

View file

@ -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 [6; 7) 'x': bool
[22; 34) '{ 0i32 }': i32 [22; 34) '{ 0i32 }': i32
[28; 32) '0i32': i32 [28; 32) '0i32': i32
@ -44,3 +48,4 @@
[341; 344) 'ten': usize [341; 344) 'ten': usize
[341; 348) 'ten < 3': bool [341; 348) 'ten < 3': bool
[347; 348) '3': usize [347; 348) '3': usize

View 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

View file

@ -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 [44; 45) 'a': A
[50; 213) '{ ...5.b; }': () [50; 213) '{ ...5.b; }': ()
[60; 62) 'a1': A [60; 62) 'a1': A
@ -41,3 +45,4 @@
[256; 260) 'a1.b': B [256; 260) 'a1.b': B
[266; 268) 'a2': *mut A [266; 268) 'a2': *mut A
[266; 270) 'a2.b': B [266; 270) 'a2.b': B

View file

@ -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] [10; 11) 't': [unknown]
[21; 26) '{ t }': [unknown] [21; 26) '{ t }': [unknown]
[23; 24) 't': [unknown] [23; 24) 't': [unknown]
@ -12,3 +16,4 @@
[90; 92) 'id': fn(T) -> T [90; 92) 'id': fn(T) -> T
[90; 95) 'id(1)': T [90; 95) 'id(1)': T
[93; 94) '1': T [93; 94) '1': T

View file

@ -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]> [53; 57) 'self': A<[unknown]>
[65; 87) '{ ... }': [unknown] [65; 87) '{ ... }': [unknown]
[75; 79) 'self': A<[unknown]> [75; 79) 'self': A<[unknown]>
@ -27,3 +31,4 @@
[244; 245) 'z': T [244; 245) 'z': T
[254; 255) 'b': A<T> [254; 255) 'b': A<T>
[254; 259) 'b.x()': i128 [254; 259) 'b.x()': i128

View file

@ -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> [79; 81) 'a1': A<u32>
[91; 92) 'o': Option<u64> [91; 92) 'o': Option<u64>
[107; 244) '{ ... }; }': () [107; 244) '{ ... }; }': ()
@ -15,3 +19,4 @@
[217; 218) 't': u64 [217; 218) 't': u64
[228; 229) '_': Option<u64> [228; 229) '_': Option<u64>
[233; 234) '1': u64 [233; 234) '1': u64

View file

@ -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 [32; 36) 'self': A
[38; 39) 'x': u32 [38; 39) 'x': u32
[53; 55) '{}': () [53; 55) '{}': ()
@ -16,3 +20,4 @@
[187; 188) 'a': A [187; 188) 'a': A
[187; 195) 'a.bar(1)': i64 [187; 195) 'a.bar(1)': i64
[193; 194) '1': u64 [193; 194) '1': u64

View file

@ -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; }': () [11; 71) '{ ...= b; }': ()
[21; 22) 'a': isize [21; 22) 'a': isize
[25; 31) '1isize': isize [25; 31) '1isize': isize
@ -5,3 +9,4 @@
[52; 53) '1': usize [52; 53) '1': usize
[63; 64) 'c': usize [63; 64) 'c': usize
[67; 68) 'b': usize [67; 68) 'b': usize

View file

@ -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"#; }': () [11; 201) '{ ...o"#; }': ()
[17; 21) '5i32': i32 [17; 21) '5i32': i32
[27; 34) '"hello"': &str [27; 34) '"hello"': &str
@ -10,3 +14,4 @@
[104; 108) 'true': bool [104; 108) 'true': bool
[114; 182) 'r#" ... "#': &str [114; 182) 'r#" ... "#': &str
[188; 198) 'br#"yolo"#': &[u8] [188; 198) 'br#"yolo"#': &[u8]

View file

@ -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 [15; 20) '{ 1 }': u32
[17; 18) '1': u32 [17; 18) '1': u32
[48; 53) '{ 1 }': u32 [48; 53) '{ 1 }': u32
@ -7,3 +11,4 @@
[73; 76) 'a()': u32 [73; 76) 'a()': u32
[82; 86) 'b::c': fn() -> u32 [82; 86) 'b::c': fn() -> u32
[82; 88) 'b::c()': u32 [82; 88) 'b::c()': u32

View file

@ -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 [9; 10) 'x': &i32
[18; 369) '{ ...o_x; }': () [18; 369) '{ ...o_x; }': ()
[28; 29) 'y': &i32 [28; 29) 'y': &i32
@ -45,3 +49,4 @@
[339; 340) 'x': &i32 [339; 340) 'x': &i32
[350; 351) 'k': &mut &i32 [350; 351) 'k': &mut &i32
[354; 366) 'mut_ref_to_x': &mut &i32 [354; 366) 'mut_ref_to_x': &mut &i32

View file

@ -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 [9; 10) 'a': &u32
[18; 19) 'b': &mut u32 [18; 19) 'b': &mut u32
[31; 32) 'c': *const u32 [31; 32) 'c': *const u32
@ -21,3 +25,4 @@
[138; 139) 'd': *mut u32 [138; 139) 'd': *mut u32
[145; 147) '*d': u32 [145; 147) '*d': u32
[146; 147) 'd': *mut u32 [146; 147) 'd': *mut u32

View file

@ -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 [34; 38) 'self': &S
[40; 61) '{ ... }': () [40; 61) '{ ... }': ()
[50; 54) 'self': &S [50; 54) 'self': &S
[75; 79) 'self': &S [75; 79) 'self': &S
[88; 109) '{ ... }': () [88; 109) '{ ... }': ()
[98; 102) 'self': &S [98; 102) 'self': &S

View file

@ -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; }': () [72; 154) '{ ...a.c; }': ()
[82; 83) 'c': [unknown] [82; 83) 'c': [unknown]
[86; 87) 'C': [unknown] [86; 87) 'C': [unknown]
@ -14,3 +18,4 @@
[139; 142) 'a.b': B [139; 142) 'a.b': B
[148; 149) 'a': A [148; 149) 'a': A
[148; 151) 'a.c': C [148; 151) 'a.c': C

View file

@ -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> [36; 38) 'a1': A<u32>
[48; 49) 'i': i32 [48; 49) 'i': i32
[56; 147) '{ ...3.x; }': () [56; 147) '{ ...3.x; }': ()
@ -13,3 +17,4 @@
[131; 132) '1': i128 [131; 132) '1': i128
[140; 142) 'a3': A<i128> [140; 142) 'a3': A<i128>
[140; 144) 'a3.x': i128 [140; 144) 'a3.x': i128

View file

@ -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 [9; 10) 'x': &str
[18; 19) 'y': isize [18; 19) 'y': isize
[28; 170) '{ ...d"); }': () [28; 170) '{ ...d"); }': ()
@ -25,3 +29,4 @@
[159; 167) '(e, "d")': ((i32, &str), &str) [159; 167) '(e, "d")': ((i32, &str), &str)
[160; 161) 'e': (i32, &str) [160; 161) 'e': (i32, &str)
[163; 166) '"d"': &str [163; 166) '"d"': &str

View file

@ -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 [27; 28) 'x': SomeType
[40; 197) '{ ...lo"; }': () [40; 197) '{ ...lo"; }': ()
[50; 51) 'b': bool [50; 51) 'b': bool
@ -26,3 +30,4 @@
[179; 180) 'x': SomeType [179; 180) 'x': SomeType
[186; 194) '-"hello"': [unknown] [186; 194) '-"hello"': [unknown]
[187; 194) '"hello"': &str [187; 194) '"hello"': &str

View file

@ -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]

View file

@ -1,11 +1,8 @@
use std::sync::Arc; use std::sync::Arc;
use std::fmt::Write; use std::fmt::Write;
use std::path::{PathBuf, Path};
use std::fs;
use ra_db::{SyntaxDatabase, salsa::Database}; use ra_db::{SyntaxDatabase, salsa::Database};
use ra_syntax::ast::{self, AstNode}; use ra_syntax::ast::{self, AstNode};
use test_utils::{project_dir, assert_eq_text, read_text};
use crate::{ use crate::{
source_binder, source_binder,
@ -13,14 +10,13 @@ use crate::{
}; };
// These tests compare the inference results for all expressions in a file // These tests compare the inference results for all expressions in a file
// against snapshots of the expected results. If you change something and these // against snapshots of the expected results using insta. Run the tests with
// tests fail expectedly, you can update the comparison files by deleting them // INSTA_UPDATE=1 to update the snapshots.
// 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.
#[test] #[test]
fn infer_basics() { fn infer_basics() {
check_inference( check_inference(
"infer_basics",
r#" r#"
fn test(a: u32, b: isize, c: !, d: &str) { fn test(a: u32, b: isize, c: !, d: &str) {
a; a;
@ -32,13 +28,13 @@ fn test(a: u32, b: isize, c: !, d: &str) {
"test"; "test";
1.0f32; 1.0f32;
}"#, }"#,
"basics.txt",
); );
} }
#[test] #[test]
fn infer_let() { fn infer_let() {
check_inference( check_inference(
"infer_let",
r#" r#"
fn test() { fn test() {
let a = 1isize; let a = 1isize;
@ -46,13 +42,13 @@ fn test() {
let c = b; let c = b;
} }
}"#, }"#,
"let.txt",
); );
} }
#[test] #[test]
fn infer_paths() { fn infer_paths() {
check_inference( check_inference(
"infer_paths",
r#" r#"
fn a() -> u32 { 1 } fn a() -> u32 { 1 }
@ -65,13 +61,13 @@ fn test() {
b::c(); b::c();
} }
}"#, }"#,
"paths.txt",
); );
} }
#[test] #[test]
fn infer_struct() { fn infer_struct() {
check_inference( check_inference(
"infer_struct",
r#" r#"
struct A { struct A {
b: B, b: B,
@ -88,13 +84,13 @@ fn test() {
a.c; a.c;
} }
"#, "#,
"struct.txt",
); );
} }
#[test] #[test]
fn infer_enum() { fn infer_enum() {
check_inference( check_inference(
"infer_enum",
r#" r#"
enum E { enum E {
V1 { field: u32 }, V1 { field: u32 },
@ -104,13 +100,13 @@ fn test() {
E::V1 { field: 1 }; E::V1 { field: 1 };
E::V2; E::V2;
}"#, }"#,
"enum.txt",
); );
} }
#[test] #[test]
fn infer_refs() { fn infer_refs() {
check_inference( check_inference(
"infer_refs",
r#" r#"
fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) { fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) {
a; a;
@ -126,13 +122,13 @@ fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) {
*d; *d;
} }
"#, "#,
"refs_and_ptrs.txt",
); );
} }
#[test] #[test]
fn infer_literals() { fn infer_literals() {
check_inference( check_inference(
"infer_literals",
r##" r##"
fn test() { fn test() {
5i32; 5i32;
@ -152,13 +148,13 @@ fn test() {
br#"yolo"#; br#"yolo"#;
} }
"##, "##,
"literals.txt",
); );
} }
#[test] #[test]
fn infer_unary_op() { fn infer_unary_op() {
check_inference( check_inference(
"infer_unary_op",
r#" r#"
enum SomeType {} enum SomeType {}
@ -175,13 +171,13 @@ fn test(x: SomeType) {
-"hello"; -"hello";
} }
"#, "#,
"unary_op.txt",
); );
} }
#[test] #[test]
fn infer_backwards() { fn infer_backwards() {
check_inference( check_inference(
"infer_backwards",
r#" r#"
fn takes_u32(x: u32) {} fn takes_u32(x: u32) {}
@ -196,13 +192,13 @@ fn test() -> &mut &f64 {
&mut &c &mut &c
} }
"#, "#,
"backwards.txt",
); );
} }
#[test] #[test]
fn infer_self() { fn infer_self() {
check_inference( check_inference(
"infer_self",
r#" r#"
struct S; struct S;
@ -215,13 +211,13 @@ impl S {
} }
} }
"#, "#,
"self.txt",
); );
} }
#[test] #[test]
fn infer_binary_op() { fn infer_binary_op() {
check_inference( check_inference(
"infer_binary_op",
r#" r#"
fn f(x: bool) -> i32 { fn f(x: bool) -> i32 {
0i32 0i32
@ -242,13 +238,13 @@ fn test() -> bool {
ten < 3 ten < 3
} }
"#, "#,
"binary_op.txt",
); );
} }
#[test] #[test]
fn infer_field_autoderef() { fn infer_field_autoderef() {
check_inference( check_inference(
"infer_field_autoderef",
r#" r#"
struct A { struct A {
b: B, b: B,
@ -273,25 +269,25 @@ fn test2(a1: *const A, a2: *mut A) {
a2.b; a2.b;
} }
"#, "#,
"field_autoderef.txt",
); );
} }
#[test] #[test]
fn infer_bug_484() { fn bug_484() {
check_inference( check_inference(
"bug_484",
r#" r#"
fn test() { fn test() {
let x = if true {}; let x = if true {};
} }
"#, "#,
"bug_484.txt",
); );
} }
#[test] #[test]
fn infer_inherent_method() { fn infer_inherent_method() {
check_inference( check_inference(
"infer_inherent_method",
r#" r#"
struct A; struct A;
@ -311,13 +307,13 @@ fn test(a: A) {
a.bar(1); a.bar(1);
} }
"#, "#,
"inherent_method.txt",
); );
} }
#[test] #[test]
fn infer_tuple() { fn infer_tuple() {
check_inference( check_inference(
"infer_tuple",
r#" r#"
fn test(x: &str, y: isize) { fn test(x: &str, y: isize) {
let a: (u32, &str) = (1, "a"); let a: (u32, &str) = (1, "a");
@ -328,13 +324,13 @@ fn test(x: &str, y: isize) {
let f = (e, "d"); let f = (e, "d");
} }
"#, "#,
"tuple.txt",
); );
} }
#[test] #[test]
fn infer_array() { fn infer_array() {
check_inference( check_inference(
"infer_array",
r#" r#"
fn test(x: &str, y: isize) { fn test(x: &str, y: isize) {
let a = [x]; let a = [x];
@ -354,13 +350,13 @@ fn test(x: &str, y: isize) {
let x: [u8; 0] = []; let x: [u8; 0] = [];
} }
"#, "#,
"array.txt",
); );
} }
#[test] #[test]
fn infer_pattern() { fn infer_pattern() {
check_inference( check_inference(
"infer_pattern",
r#" r#"
fn test(x: &i32) { fn test(x: &i32) {
let y = x; let y = x;
@ -384,13 +380,13 @@ fn test(x: &i32) {
let k = mut_ref_to_x; let k = mut_ref_to_x;
} }
"#, "#,
"pattern.txt",
); );
} }
#[test] #[test]
fn infer_adt_pattern() { fn infer_adt_pattern() {
check_inference( check_inference(
"infer_adt_pattern",
r#" r#"
enum E { enum E {
A { x: usize }, A { x: usize },
@ -414,13 +410,13 @@ fn test() {
d; d;
} }
"#, "#,
"adt_pattern.txt",
); );
} }
#[test] #[test]
fn infer_struct_generics() { fn infer_struct_generics() {
check_inference( check_inference(
"infer_struct_generics",
r#" r#"
struct A<T> { struct A<T> {
x: T, x: T,
@ -434,13 +430,13 @@ fn test(a1: A<u32>, i: i32) {
a3.x; a3.x;
} }
"#, "#,
"struct_generics.txt",
); );
} }
#[test] #[test]
fn infer_generics_in_patterns() { fn infer_generics_in_patterns() {
check_inference( check_inference(
"infer_generics_in_patterns",
r#" r#"
struct A<T> { struct A<T> {
x: T, x: T,
@ -460,13 +456,13 @@ fn test(a1: A<u32>, o: Option<u64>) {
}; };
} }
"#, "#,
"generics_in_patterns.txt",
); );
} }
#[test] #[test]
fn infer_function_generics() { fn infer_function_generics() {
check_inference( check_inference(
"infer_function_generics",
r#" r#"
fn id<T>(t: T) -> T { t } fn id<T>(t: T) -> T { t }
@ -476,13 +472,13 @@ fn test() {
let x: u64 = id(1); let x: u64 = id(1);
} }
"#, "#,
"function_generics.txt",
); );
} }
#[test] #[test]
fn infer_generic_chain() { fn infer_generic_chain() {
check_inference( check_inference(
"infer_generic_chain",
r#" r#"
struct A<T> { struct A<T> {
x: T, x: T,
@ -503,13 +499,13 @@ fn test() -> i128 {
b.x() b.x()
} }
"#, "#,
"generic_chain.txt",
); );
} }
#[test] #[test]
fn no_panic_on_field_of_enum() { fn no_panic_on_field_of_enum() {
check_inference( check_inference(
"no_panic_on_field_of_enum",
r#" r#"
enum X {} enum X {}
@ -517,13 +513,13 @@ fn test(x: X) {
x.some_field; x.some_field;
} }
"#, "#,
"no_panic_on_field_of_enum.txt",
); );
} }
#[test] #[test]
fn bug_585() { fn bug_585() {
check_inference( check_inference(
"bug_585",
r#" r#"
fn test() { fn test() {
X {}; X {};
@ -533,7 +529,6 @@ fn test() {
} }
} }
"#, "#,
"bug_585.txt",
); );
} }
@ -581,19 +576,10 @@ fn infer(content: &str) -> String {
acc acc
} }
fn check_inference(content: &str, data_file: impl AsRef<Path>) { fn check_inference(name: &str, content: &str) {
let data_file_path = test_data_dir().join(data_file);
let result = infer(content); let result = infer(content);
if !data_file_path.exists() { insta::assert_snapshot_matches!(&name, &result);
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);
} }
fn ellipsize(mut text: String, max_len: usize) -> String { fn ellipsize(mut text: String, max_len: usize) -> String {
@ -614,10 +600,6 @@ fn ellipsize(mut text: String, max_len: usize) -> String {
text text
} }
fn test_data_dir() -> PathBuf {
project_dir().join("crates/ra_hir/src/ty/tests/data")
}
#[test] #[test]
fn typing_whitespace_inside_a_function_should_not_invalidate_types() { fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
let (mut db, pos) = MockDatabase::with_position( let (mut db, pos) = MockDatabase::with_position(

View file

@ -1,4 +0,0 @@
[48; 82) '{ E:...:V2; }': ()
[52; 70) 'E::V1 ...d: 1 }': E
[67; 68) '1': u32
[74; 79) 'E::V2': E

View file

@ -1,4 +0,0 @@
[20; 21) 'x': X
[26; 47) '{ ...eld; }': ()
[32; 33) 'x': X
[32; 44) 'x.some_field': [unknown]