From 8716c4cec3a05ba891b20b5f28df69d925b913ad Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 2 Oct 2020 15:45:09 +0200 Subject: Move ide::AnalysisChange -> base_db::Change This seems like a better factoring logically; ideally, clients shouldn't touch `set_` methods of the database directly. Additionally, I think this should remove the unfortunate duplication in fixture code. --- crates/ide/src/parent_module.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ide/src/parent_module.rs') diff --git a/crates/ide/src/parent_module.rs b/crates/ide/src/parent_module.rs index 59ed2967c..68b107901 100644 --- a/crates/ide/src/parent_module.rs +++ b/crates/ide/src/parent_module.rs @@ -69,7 +69,7 @@ mod tests { use crate::{ mock_analysis::{analysis_and_position, MockAnalysis}, - AnalysisChange, CrateGraph, + Change, CrateGraph, Edition::Edition2018, }; @@ -146,7 +146,7 @@ mod foo; Env::default(), Default::default(), ); - let mut change = AnalysisChange::new(); + let mut change = Change::new(); change.set_crate_graph(crate_graph); host.apply_change(change); -- cgit v1.2.3 From 09348b247465864c6462a39055803bcbb0156cfe Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 2 Oct 2020 16:13:48 +0200 Subject: Get rid of MockAnalysis --- crates/ide/src/parent_module.rs | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) (limited to 'crates/ide/src/parent_module.rs') diff --git a/crates/ide/src/parent_module.rs b/crates/ide/src/parent_module.rs index 68b107901..253454476 100644 --- a/crates/ide/src/parent_module.rs +++ b/crates/ide/src/parent_module.rs @@ -63,15 +63,9 @@ pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec { #[cfg(test)] mod tests { - use base_db::Env; - use cfg::CfgOptions; use test_utils::mark; - use crate::{ - mock_analysis::{analysis_and_position, MockAnalysis}, - Change, CrateGraph, - Edition::Edition2018, - }; + use crate::mock_analysis::{analysis_and_position, single_file}; #[test] fn test_resolve_parent_module() { @@ -84,7 +78,7 @@ mod tests { ", ); let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); - nav.assert_match("foo MODULE FileId(1) 0..8"); + nav.assert_match("foo MODULE FileId(0) 0..8"); } #[test] @@ -103,7 +97,7 @@ mod tests { ", ); let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); - nav.assert_match("foo MODULE FileId(1) 0..8"); + nav.assert_match("foo MODULE FileId(0) 0..8"); } #[test] @@ -119,37 +113,19 @@ mod tests { ", ); let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); - nav.assert_match("baz MODULE FileId(1) 32..44"); + nav.assert_match("baz MODULE FileId(0) 32..44"); } #[test] fn test_resolve_crate_root() { - let mock = MockAnalysis::with_files( + let (analysis, file_id) = single_file( r#" -//- /bar.rs +//- /main.rs mod foo; //- /foo.rs -// empty +<|> "#, ); - let root_file = mock.id_of("/bar.rs"); - let mod_file = mock.id_of("/foo.rs"); - let mut host = mock.analysis_host(); - assert!(host.analysis().crate_for(mod_file).unwrap().is_empty()); - - let mut crate_graph = CrateGraph::default(); - let crate_id = crate_graph.add_crate_root( - root_file, - Edition2018, - None, - CfgOptions::default(), - Env::default(), - Default::default(), - ); - let mut change = Change::new(); - change.set_crate_graph(crate_graph); - host.apply_change(change); - - assert_eq!(host.analysis().crate_for(mod_file).unwrap(), vec![crate_id]); + assert_eq!(analysis.crate_for(file_id).unwrap().len(), 1); } } -- cgit v1.2.3 From b06259673f9b535a63c0cabf4eeb935ff73d86d0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 2 Oct 2020 17:34:31 +0200 Subject: rename mock_analysis -> fixture --- crates/ide/src/parent_module.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ide/src/parent_module.rs') diff --git a/crates/ide/src/parent_module.rs b/crates/ide/src/parent_module.rs index 253454476..ef94acfec 100644 --- a/crates/ide/src/parent_module.rs +++ b/crates/ide/src/parent_module.rs @@ -65,11 +65,11 @@ pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec { mod tests { use test_utils::mark; - use crate::mock_analysis::{analysis_and_position, single_file}; + use crate::fixture::{self}; #[test] fn test_resolve_parent_module() { - let (analysis, pos) = analysis_and_position( + let (analysis, pos) = fixture::position( " //- /lib.rs mod foo; @@ -84,7 +84,7 @@ mod tests { #[test] fn test_resolve_parent_module_on_module_decl() { mark::check!(test_resolve_parent_module_on_module_decl); - let (analysis, pos) = analysis_and_position( + let (analysis, pos) = fixture::position( " //- /lib.rs mod foo; @@ -102,7 +102,7 @@ mod tests { #[test] fn test_resolve_parent_module_for_inline() { - let (analysis, pos) = analysis_and_position( + let (analysis, pos) = fixture::position( " //- /lib.rs mod foo { @@ -118,7 +118,7 @@ mod tests { #[test] fn test_resolve_crate_root() { - let (analysis, file_id) = single_file( + let (analysis, file_id) = fixture::file( r#" //- /main.rs mod foo; -- cgit v1.2.3