diff options
author | Aleksey Kladov <[email protected]> | 2020-10-02 15:13:48 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-10-02 16:31:20 +0100 |
commit | 09348b247465864c6462a39055803bcbb0156cfe (patch) | |
tree | d57122ddcaa21d6f4ea50204afc3e3bc341583fc /crates/ide/src/parent_module.rs | |
parent | eeb27f95f1025128f8a1d24a515eb009498a1d44 (diff) |
Get rid of MockAnalysis
Diffstat (limited to 'crates/ide/src/parent_module.rs')
-rw-r--r-- | crates/ide/src/parent_module.rs | 40 |
1 files changed, 8 insertions, 32 deletions
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<CrateId> { | |||
63 | 63 | ||
64 | #[cfg(test)] | 64 | #[cfg(test)] |
65 | mod tests { | 65 | mod tests { |
66 | use base_db::Env; | ||
67 | use cfg::CfgOptions; | ||
68 | use test_utils::mark; | 66 | use test_utils::mark; |
69 | 67 | ||
70 | use crate::{ | 68 | use crate::mock_analysis::{analysis_and_position, single_file}; |
71 | mock_analysis::{analysis_and_position, MockAnalysis}, | ||
72 | Change, CrateGraph, | ||
73 | Edition::Edition2018, | ||
74 | }; | ||
75 | 69 | ||
76 | #[test] | 70 | #[test] |
77 | fn test_resolve_parent_module() { | 71 | fn test_resolve_parent_module() { |
@@ -84,7 +78,7 @@ mod tests { | |||
84 | ", | 78 | ", |
85 | ); | 79 | ); |
86 | let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); | 80 | let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); |
87 | nav.assert_match("foo MODULE FileId(1) 0..8"); | 81 | nav.assert_match("foo MODULE FileId(0) 0..8"); |
88 | } | 82 | } |
89 | 83 | ||
90 | #[test] | 84 | #[test] |
@@ -103,7 +97,7 @@ mod tests { | |||
103 | ", | 97 | ", |
104 | ); | 98 | ); |
105 | let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); | 99 | let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); |
106 | nav.assert_match("foo MODULE FileId(1) 0..8"); | 100 | nav.assert_match("foo MODULE FileId(0) 0..8"); |
107 | } | 101 | } |
108 | 102 | ||
109 | #[test] | 103 | #[test] |
@@ -119,37 +113,19 @@ mod tests { | |||
119 | ", | 113 | ", |
120 | ); | 114 | ); |
121 | let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); | 115 | let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); |
122 | nav.assert_match("baz MODULE FileId(1) 32..44"); | 116 | nav.assert_match("baz MODULE FileId(0) 32..44"); |
123 | } | 117 | } |
124 | 118 | ||
125 | #[test] | 119 | #[test] |
126 | fn test_resolve_crate_root() { | 120 | fn test_resolve_crate_root() { |
127 | let mock = MockAnalysis::with_files( | 121 | let (analysis, file_id) = single_file( |
128 | r#" | 122 | r#" |
129 | //- /bar.rs | 123 | //- /main.rs |
130 | mod foo; | 124 | mod foo; |
131 | //- /foo.rs | 125 | //- /foo.rs |
132 | // empty | 126 | <|> |
133 | "#, | 127 | "#, |
134 | ); | 128 | ); |
135 | let root_file = mock.id_of("/bar.rs"); | 129 | assert_eq!(analysis.crate_for(file_id).unwrap().len(), 1); |
136 | let mod_file = mock.id_of("/foo.rs"); | ||
137 | let mut host = mock.analysis_host(); | ||
138 | assert!(host.analysis().crate_for(mod_file).unwrap().is_empty()); | ||
139 | |||
140 | let mut crate_graph = CrateGraph::default(); | ||
141 | let crate_id = crate_graph.add_crate_root( | ||
142 | root_file, | ||
143 | Edition2018, | ||
144 | None, | ||
145 | CfgOptions::default(), | ||
146 | Env::default(), | ||
147 | Default::default(), | ||
148 | ); | ||
149 | let mut change = Change::new(); | ||
150 | change.set_crate_graph(crate_graph); | ||
151 | host.apply_change(change); | ||
152 | |||
153 | assert_eq!(host.analysis().crate_for(mod_file).unwrap(), vec![crate_id]); | ||
154 | } | 130 | } |
155 | } | 131 | } |