diff options
author | Aleksey Kladov <[email protected]> | 2019-04-12 22:56:57 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-04-12 22:56:57 +0100 |
commit | 7c13e223345e4ff14cc884fc5b785c925f0e0b61 (patch) | |
tree | 7905137b3559d1d53dbcd4d3ca6588c224f9f6e0 | |
parent | 0fd93bc14a2d0ce2edd682d26c18979c13f181c5 (diff) |
simplify tests
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 39 |
3 files changed, 23 insertions, 36 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 3c1f7cd65..5179f719d 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -606,11 +606,6 @@ impl Const { | |||
606 | db.infer((*self).into()) | 606 | db.infer((*self).into()) |
607 | } | 607 | } |
608 | 608 | ||
609 | #[cfg(test)] | ||
610 | pub(crate) fn body_source_map(&self, db: &impl HirDatabase) -> Arc<BodySourceMap> { | ||
611 | db.body_with_source_map((*self).into()).1 | ||
612 | } | ||
613 | |||
614 | /// The containing impl block, if this is a method. | 609 | /// The containing impl block, if this is a method. |
615 | pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> { | 610 | pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> { |
616 | let module_impls = db.impls_in_module(self.module(db)); | 611 | let module_impls = db.impls_in_module(self.module(db)); |
@@ -679,11 +674,6 @@ impl Static { | |||
679 | pub fn infer(&self, db: &impl HirDatabase) -> Arc<InferenceResult> { | 674 | pub fn infer(&self, db: &impl HirDatabase) -> Arc<InferenceResult> { |
680 | db.infer((*self).into()) | 675 | db.infer((*self).into()) |
681 | } | 676 | } |
682 | |||
683 | #[cfg(test)] | ||
684 | pub(crate) fn body_source_map(&self, db: &impl HirDatabase) -> Arc<BodySourceMap> { | ||
685 | db.body_with_source_map((*self).into()).1 | ||
686 | } | ||
687 | } | 677 | } |
688 | 678 | ||
689 | impl Docs for Static { | 679 | impl Docs for Static { |
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 846394212..c3cb17882 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -343,4 +343,14 @@ impl SourceAnalyzer { | |||
343 | }; | 343 | }; |
344 | Some(res) | 344 | Some(res) |
345 | } | 345 | } |
346 | |||
347 | #[cfg(test)] | ||
348 | pub(crate) fn body_source_map(&self) -> Arc<crate::expr::BodySourceMap> { | ||
349 | self.body_source_map.clone().unwrap() | ||
350 | } | ||
351 | |||
352 | #[cfg(test)] | ||
353 | pub(crate) fn inference_result(&self) -> Arc<crate::ty::InferenceResult> { | ||
354 | self.infer.clone().unwrap() | ||
355 | } | ||
346 | } | 356 | } |
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index ecc63f376..87d6bcaec 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -4,7 +4,7 @@ use std::fmt::Write; | |||
4 | use insta::assert_snapshot_matches; | 4 | use insta::assert_snapshot_matches; |
5 | 5 | ||
6 | use ra_db::{SourceDatabase, salsa::Database, FilePosition}; | 6 | use ra_db::{SourceDatabase, salsa::Database, FilePosition}; |
7 | use ra_syntax::{algo, ast::{self, AstNode}}; | 7 | use ra_syntax::{algo, ast::{self, AstNode}, SyntaxKind::*}; |
8 | use test_utils::covers; | 8 | use test_utils::covers; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
@@ -12,7 +12,8 @@ use crate::{ | |||
12 | mock::MockDatabase, | 12 | mock::MockDatabase, |
13 | ty::display::HirDisplay, | 13 | ty::display::HirDisplay, |
14 | ty::InferenceResult, | 14 | ty::InferenceResult, |
15 | expr::BodySourceMap | 15 | expr::BodySourceMap, |
16 | SourceAnalyzer, | ||
16 | }; | 17 | }; |
17 | 18 | ||
18 | // These tests compare the inference results for all expressions in a file | 19 | // These tests compare the inference results for all expressions in a file |
@@ -1862,14 +1863,14 @@ fn test() { | |||
1862 | @r###" | 1863 | @r###" |
1863 | [49; 50) '0': u32 | 1864 | [49; 50) '0': u32 |
1864 | [80; 83) '101': u32 | 1865 | [80; 83) '101': u32 |
1865 | [126; 128) '99': u32 | ||
1866 | [95; 213) '{ ...NST; }': () | 1866 | [95; 213) '{ ...NST; }': () |
1867 | [138; 139) 'x': {unknown} | 1867 | [138; 139) 'x': {unknown} |
1868 | [142; 153) 'LOCAL_CONST': {unknown} | 1868 | [142; 153) 'LOCAL_CONST': {unknown} |
1869 | [163; 164) 'z': u32 | 1869 | [163; 164) 'z': u32 |
1870 | [167; 179) 'GLOBAL_CONST': u32 | 1870 | [167; 179) 'GLOBAL_CONST': u32 |
1871 | [189; 191) 'id': u32 | 1871 | [189; 191) 'id': u32 |
1872 | [194; 210) 'Foo::A..._CONST': u32"### | 1872 | [194; 210) 'Foo::A..._CONST': u32 |
1873 | [126; 128) '99': u32"### | ||
1873 | ); | 1874 | ); |
1874 | } | 1875 | } |
1875 | 1876 | ||
@@ -1891,8 +1892,6 @@ fn test() { | |||
1891 | @r###" | 1892 | @r###" |
1892 | [29; 32) '101': u32 | 1893 | [29; 32) '101': u32 |
1893 | [70; 73) '101': u32 | 1894 | [70; 73) '101': u32 |
1894 | [118; 120) '99': u32 | ||
1895 | [161; 163) '99': u32 | ||
1896 | [85; 280) '{ ...MUT; }': () | 1895 | [85; 280) '{ ...MUT; }': () |
1897 | [173; 174) 'x': {unknown} | 1896 | [173; 174) 'x': {unknown} |
1898 | [177; 189) 'LOCAL_STATIC': {unknown} | 1897 | [177; 189) 'LOCAL_STATIC': {unknown} |
@@ -1901,7 +1900,9 @@ fn test() { | |||
1901 | [229; 230) 'z': u32 | 1900 | [229; 230) 'z': u32 |
1902 | [233; 246) 'GLOBAL_STATIC': u32 | 1901 | [233; 246) 'GLOBAL_STATIC': u32 |
1903 | [256; 257) 'w': u32 | 1902 | [256; 257) 'w': u32 |
1904 | [260; 277) 'GLOBAL...IC_MUT': u32"### | 1903 | [260; 277) 'GLOBAL...IC_MUT': u32 |
1904 | [118; 120) '99': u32 | ||
1905 | [161; 163) '99': u32"### | ||
1905 | ); | 1906 | ); |
1906 | } | 1907 | } |
1907 | 1908 | ||
@@ -2350,25 +2351,11 @@ fn infer(content: &str) -> String { | |||
2350 | } | 2351 | } |
2351 | }; | 2352 | }; |
2352 | 2353 | ||
2353 | for const_def in source_file.syntax().descendants().filter_map(ast::ConstDef::cast) { | 2354 | for node in source_file.syntax().descendants() { |
2354 | let konst = source_binder::const_from_source(&db, file_id, const_def).unwrap(); | 2355 | if node.kind() == FN_DEF || node.kind() == CONST_DEF || node.kind() == STATIC_DEF { |
2355 | let inference_result = konst.infer(&db); | 2356 | let analyzer = SourceAnalyzer::new(&db, file_id, node, None); |
2356 | let body_source_map = konst.body_source_map(&db); | 2357 | infer_def(analyzer.inference_result(), analyzer.body_source_map()); |
2357 | infer_def(inference_result, body_source_map) | 2358 | } |
2358 | } | ||
2359 | |||
2360 | for static_def in source_file.syntax().descendants().filter_map(ast::StaticDef::cast) { | ||
2361 | let static_ = source_binder::static_from_source(&db, file_id, static_def).unwrap(); | ||
2362 | let inference_result = static_.infer(&db); | ||
2363 | let body_source_map = static_.body_source_map(&db); | ||
2364 | infer_def(inference_result, body_source_map) | ||
2365 | } | ||
2366 | |||
2367 | for fn_def in source_file.syntax().descendants().filter_map(ast::FnDef::cast) { | ||
2368 | let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap(); | ||
2369 | let inference_result = func.infer(&db); | ||
2370 | let body_source_map = func.body_source_map(&db); | ||
2371 | infer_def(inference_result, body_source_map) | ||
2372 | } | 2359 | } |
2373 | 2360 | ||
2374 | acc.truncate(acc.trim_end().len()); | 2361 | acc.truncate(acc.trim_end().len()); |