diff options
author | Aleksey Kladov <[email protected]> | 2020-06-29 13:21:57 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-06-29 16:23:01 +0100 |
commit | e805e8c1d5bf26e9716fb855f97d950395129c20 (patch) | |
tree | d42f406a04551626fba261e75edd752ffb1894c2 /crates/ra_hir_ty/src/tests.rs | |
parent | 82ce5792ab70ab8d20a1afde72c5400c27b9c190 (diff) |
(T): make typification tests more data driven
Diffstat (limited to 'crates/ra_hir_ty/src/tests.rs')
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index 2a85ce85d..4d0dc3011 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -28,6 +28,7 @@ use ra_syntax::{ | |||
28 | SyntaxNode, | 28 | SyntaxNode, |
29 | }; | 29 | }; |
30 | use stdx::format_to; | 30 | use stdx::format_to; |
31 | use test_utils::extract_annotations; | ||
31 | 32 | ||
32 | use crate::{ | 33 | use crate::{ |
33 | db::HirDatabase, display::HirDisplay, infer::TypeMismatch, test_db::TestDB, InferenceResult, Ty, | 34 | db::HirDatabase, display::HirDisplay, infer::TypeMismatch, test_db::TestDB, InferenceResult, Ty, |
@@ -37,6 +38,21 @@ use crate::{ | |||
37 | // against snapshots of the expected results using insta. Use cargo-insta to | 38 | // against snapshots of the expected results using insta. Use cargo-insta to |
38 | // update the snapshots. | 39 | // update the snapshots. |
39 | 40 | ||
41 | fn check_types(ra_fixture: &str) { | ||
42 | let db = TestDB::with_files(ra_fixture); | ||
43 | let mut checked_one = false; | ||
44 | for file_id in db.all_files() { | ||
45 | let text = db.parse(file_id).syntax_node().to_string(); | ||
46 | let annotations = extract_annotations(&text); | ||
47 | for (offset, expected) in annotations { | ||
48 | let actual = type_at_pos(&db, FilePosition { file_id, offset }); | ||
49 | assert_eq!(expected, actual); | ||
50 | checked_one = true; | ||
51 | } | ||
52 | } | ||
53 | assert!(checked_one, "no `//^` annotations found"); | ||
54 | } | ||
55 | |||
40 | fn type_at_pos(db: &TestDB, pos: FilePosition) -> String { | 56 | fn type_at_pos(db: &TestDB, pos: FilePosition) -> String { |
41 | type_at_pos_displayed(db, pos, |ty, _| ty.display(db).to_string()) | 57 | type_at_pos_displayed(db, pos, |ty, _| ty.display(db).to_string()) |
42 | } | 58 | } |