diff --git a/Cargo.lock b/Cargo.lock index 490299b4b0..5689cecb48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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)", diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml index 87d2e98e9d..3d5dddc6a0 100644 --- a/crates/ra_hir/Cargo.toml +++ b/crates/ra_hir/Cargo.toml @@ -19,3 +19,4 @@ test_utils = { path = "../test_utils" } [dev-dependencies] flexi_logger = "0.10.0" +insta = "0.1.4" diff --git a/crates/ra_hir/src/ty/tests/data/bug_484.txt b/crates/ra_hir/src/ty/snapshots/tests__bug_484.snap similarity index 51% rename from crates/ra_hir/src/ty/tests/data/bug_484.txt rename to crates/ra_hir/src/ty/snapshots/tests__bug_484.snap index 3005305513..eeb3061d37 100644 --- a/crates/ra_hir/src/ty/tests/data/bug_484.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__bug_484.snap @@ -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) '{}': () + diff --git a/crates/ra_hir/src/ty/tests/data/bug_585.txt b/crates/ra_hir/src/ty/snapshots/tests__bug_585.snap similarity index 66% rename from crates/ra_hir/src/ty/tests/data/bug_585.txt rename to crates/ra_hir/src/ty/snapshots/tests__bug_585.snap index 627702a382..073009bbce 100644 --- a/crates/ra_hir/src/ty/tests/data/bug_585.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__bug_585.snap @@ -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) '()': () + diff --git a/crates/ra_hir/src/ty/tests/data/adt_pattern.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_adt_pattern.snap similarity index 83% rename from crates/ra_hir/src/ty/tests/data/adt_pattern.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_adt_pattern.snap index 2daf9647be..fb261f1c0f 100644 --- a/crates/ra_hir/src/ty/tests/data/adt_pattern.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_adt_pattern.snap @@ -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 + diff --git a/crates/ra_hir/src/ty/tests/data/array.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_array.snap similarity index 92% rename from crates/ra_hir/src/ty/tests/data/array.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_array.snap index acdf74ba49..2fc613e26f 100644 --- a/crates/ra_hir/src/ty/tests/data/array.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_array.snap @@ -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] + diff --git a/crates/ra_hir/src/ty/tests/data/backwards.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_backwards.snap similarity index 84% rename from crates/ra_hir/src/ty/tests/data/backwards.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_backwards.snap index b8593cfd16..12f0d8c907 100644 --- a/crates/ra_hir/src/ty/tests/data/backwards.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_backwards.snap @@ -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 + diff --git a/crates/ra_hir/src/ty/tests/data/basics.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_basics.snap similarity index 72% rename from crates/ra_hir/src/ty/tests/data/basics.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_basics.snap index e65fe07aa4..eba8126e92 100644 --- a/crates/ra_hir/src/ty/tests/data/basics.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_basics.snap @@ -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 + diff --git a/crates/ra_hir/src/ty/tests/data/binary_op.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_binary_op.snap similarity index 91% rename from crates/ra_hir/src/ty/tests/data/binary_op.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_binary_op.snap index 58a7276916..3b750ec450 100644 --- a/crates/ra_hir/src/ty/tests/data/binary_op.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_binary_op.snap @@ -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 + diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_enum.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_enum.snap new file mode 100644 index 0000000000..8018ff025d --- /dev/null +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_enum.snap @@ -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 + diff --git a/crates/ra_hir/src/ty/tests/data/field_autoderef.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_field_autoderef.snap similarity index 90% rename from crates/ra_hir/src/ty/tests/data/field_autoderef.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_field_autoderef.snap index e1db1db40b..1943ef079c 100644 --- a/crates/ra_hir/src/ty/tests/data/field_autoderef.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_field_autoderef.snap @@ -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 + diff --git a/crates/ra_hir/src/ty/tests/data/function_generics.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap similarity index 75% rename from crates/ra_hir/src/ty/tests/data/function_generics.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap index e44d26cfdc..386acc0b3b 100644 --- a/crates/ra_hir/src/ty/tests/data/function_generics.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap @@ -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 + diff --git a/crates/ra_hir/src/ty/tests/data/generic_chain.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_generic_chain.snap similarity index 87% rename from crates/ra_hir/src/ty/tests/data/generic_chain.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_generic_chain.snap index 568e00846b..7a64e4f95a 100644 --- a/crates/ra_hir/src/ty/tests/data/generic_chain.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_generic_chain.snap @@ -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 [254; 259) 'b.x()': i128 + diff --git a/crates/ra_hir/src/ty/tests/data/generics_in_patterns.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_generics_in_patterns.snap similarity index 81% rename from crates/ra_hir/src/ty/tests/data/generics_in_patterns.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_generics_in_patterns.snap index 1b01ef19ec..ae38ec2fbd 100644 --- a/crates/ra_hir/src/ty/tests/data/generics_in_patterns.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_generics_in_patterns.snap @@ -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 [91; 92) 'o': Option [107; 244) '{ ... }; }': () @@ -15,3 +19,4 @@ [217; 218) 't': u64 [228; 229) '_': Option [233; 234) '1': u64 + diff --git a/crates/ra_hir/src/ty/tests/data/inherent_method.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_inherent_method.snap similarity index 78% rename from crates/ra_hir/src/ty/tests/data/inherent_method.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_inherent_method.snap index 6e6f70357a..298dac585c 100644 --- a/crates/ra_hir/src/ty/tests/data/inherent_method.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_inherent_method.snap @@ -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 + diff --git a/crates/ra_hir/src/ty/tests/data/let.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_let.snap similarity index 59% rename from crates/ra_hir/src/ty/tests/data/let.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_let.snap index 8815dba411..aa4e4cc63e 100644 --- a/crates/ra_hir/src/ty/tests/data/let.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_let.snap @@ -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 + diff --git a/crates/ra_hir/src/ty/tests/data/literals.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_literals.snap similarity index 73% rename from crates/ra_hir/src/ty/tests/data/literals.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_literals.snap index 84ee2c11b9..00c7e639ef 100644 --- a/crates/ra_hir/src/ty/tests/data/literals.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_literals.snap @@ -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] + diff --git a/crates/ra_hir/src/ty/tests/data/paths.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_paths.snap similarity index 66% rename from crates/ra_hir/src/ty/tests/data/paths.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_paths.snap index b22f4d4a52..0924cdc804 100644 --- a/crates/ra_hir/src/ty/tests/data/paths.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_paths.snap @@ -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 + diff --git a/crates/ra_hir/src/ty/tests/data/pattern.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_pattern.snap similarity index 92% rename from crates/ra_hir/src/ty/tests/data/pattern.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_pattern.snap index 966289aafc..b22b71765a 100644 --- a/crates/ra_hir/src/ty/tests/data/pattern.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_pattern.snap @@ -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 + diff --git a/crates/ra_hir/src/ty/tests/data/refs_and_ptrs.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_refs.snap similarity index 83% rename from crates/ra_hir/src/ty/tests/data/refs_and_ptrs.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_refs.snap index afab343ea5..fc5bfe6776 100644 --- a/crates/ra_hir/src/ty/tests/data/refs_and_ptrs.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_refs.snap @@ -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 + diff --git a/crates/ra_hir/src/ty/tests/data/self.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_self.snap similarity index 57% rename from crates/ra_hir/src/ty/tests/data/self.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_self.snap index c38029f97b..76cb620553 100644 --- a/crates/ra_hir/src/ty/tests/data/self.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_self.snap @@ -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 + diff --git a/crates/ra_hir/src/ty/tests/data/struct.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_struct.snap similarity index 77% rename from crates/ra_hir/src/ty/tests/data/struct.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_struct.snap index be9e12d024..0c94d68377 100644 --- a/crates/ra_hir/src/ty/tests/data/struct.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_struct.snap @@ -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 + diff --git a/crates/ra_hir/src/ty/tests/data/struct_generics.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_struct_generics.snap similarity index 77% rename from crates/ra_hir/src/ty/tests/data/struct_generics.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_struct_generics.snap index 1024a39a96..7cf947d4d3 100644 --- a/crates/ra_hir/src/ty/tests/data/struct_generics.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_struct_generics.snap @@ -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 [48; 49) 'i': i32 [56; 147) '{ ...3.x; }': () @@ -13,3 +17,4 @@ [131; 132) '1': i128 [140; 142) 'a3': A [140; 144) 'a3.x': i128 + diff --git a/crates/ra_hir/src/ty/tests/data/tuple.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_tuple.snap similarity index 87% rename from crates/ra_hir/src/ty/tests/data/tuple.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_tuple.snap index a95d3c286e..8626441458 100644 --- a/crates/ra_hir/src/ty/tests/data/tuple.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_tuple.snap @@ -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 + diff --git a/crates/ra_hir/src/ty/tests/data/unary_op.txt b/crates/ra_hir/src/ty/snapshots/tests__infer_unary_op.snap similarity index 86% rename from crates/ra_hir/src/ty/tests/data/unary_op.txt rename to crates/ra_hir/src/ty/snapshots/tests__infer_unary_op.snap index 203022e829..8906bb9c00 100644 --- a/crates/ra_hir/src/ty/tests/data/unary_op.txt +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_unary_op.snap @@ -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 + diff --git a/crates/ra_hir/src/ty/snapshots/tests__no_panic_on_field_of_enum.snap b/crates/ra_hir/src/ty/snapshots/tests__no_panic_on_field_of_enum.snap new file mode 100644 index 0000000000..024fbf929b --- /dev/null +++ b/crates/ra_hir/src/ty/snapshots/tests__no_panic_on_field_of_enum.snap @@ -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] + diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index dc9b626dcf..9bf1fd3b23 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -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 { x: T, @@ -434,13 +430,13 @@ fn test(a1: A, i: i32) { a3.x; } "#, - "struct_generics.txt", ); } #[test] fn infer_generics_in_patterns() { check_inference( + "infer_generics_in_patterns", r#" struct A { x: T, @@ -460,13 +456,13 @@ fn test(a1: A, o: Option) { }; } "#, - "generics_in_patterns.txt", ); } #[test] fn infer_function_generics() { check_inference( + "infer_function_generics", r#" fn id(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 { 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) { - 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( diff --git a/crates/ra_hir/src/ty/tests/data/enum.txt b/crates/ra_hir/src/ty/tests/data/enum.txt deleted file mode 100644 index 481eb0bc72..0000000000 --- a/crates/ra_hir/src/ty/tests/data/enum.txt +++ /dev/null @@ -1,4 +0,0 @@ -[48; 82) '{ E:...:V2; }': () -[52; 70) 'E::V1 ...d: 1 }': E -[67; 68) '1': u32 -[74; 79) 'E::V2': E diff --git a/crates/ra_hir/src/ty/tests/data/no_panic_on_field_of_enum.txt b/crates/ra_hir/src/ty/tests/data/no_panic_on_field_of_enum.txt deleted file mode 100644 index 4dca0b7f44..0000000000 --- a/crates/ra_hir/src/ty/tests/data/no_panic_on_field_of_enum.txt +++ /dev/null @@ -1,4 +0,0 @@ -[20; 21) 'x': X -[26; 47) '{ ...eld; }': () -[32; 33) 'x': X -[32; 44) 'x.some_field': [unknown]