aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/parent_module.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-10-02 16:50:20 +0100
committerGitHub <[email protected]>2020-10-02 16:50:20 +0100
commit673e1ddb9ae12c565f966549ba7ea8c306cfba87 (patch)
treea1d9c304711806c393163547fe6da69289aa9f16 /crates/ide/src/parent_module.rs
parenta360832c95dbfe10167ebebe4978760e9be6a4bd (diff)
parentb06259673f9b535a63c0cabf4eeb935ff73d86d0 (diff)
Merge #6123
6123: Reduce duplication in fixtures r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ide/src/parent_module.rs')
-rw-r--r--crates/ide/src/parent_module.rs46
1 files changed, 11 insertions, 35 deletions
diff --git a/crates/ide/src/parent_module.rs b/crates/ide/src/parent_module.rs
index 59ed2967c..ef94acfec 100644
--- a/crates/ide/src/parent_module.rs
+++ b/crates/ide/src/parent_module.rs
@@ -63,19 +63,13 @@ pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> {
63 63
64#[cfg(test)] 64#[cfg(test)]
65mod tests { 65mod 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::fixture::{self};
71 mock_analysis::{analysis_and_position, MockAnalysis},
72 AnalysisChange, CrateGraph,
73 Edition::Edition2018,
74 };
75 69
76 #[test] 70 #[test]
77 fn test_resolve_parent_module() { 71 fn test_resolve_parent_module() {
78 let (analysis, pos) = analysis_and_position( 72 let (analysis, pos) = fixture::position(
79 " 73 "
80 //- /lib.rs 74 //- /lib.rs
81 mod foo; 75 mod foo;
@@ -84,13 +78,13 @@ 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]
91 fn test_resolve_parent_module_on_module_decl() { 85 fn test_resolve_parent_module_on_module_decl() {
92 mark::check!(test_resolve_parent_module_on_module_decl); 86 mark::check!(test_resolve_parent_module_on_module_decl);
93 let (analysis, pos) = analysis_and_position( 87 let (analysis, pos) = fixture::position(
94 " 88 "
95 //- /lib.rs 89 //- /lib.rs
96 mod foo; 90 mod foo;
@@ -103,12 +97,12 @@ 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]
110 fn test_resolve_parent_module_for_inline() { 104 fn test_resolve_parent_module_for_inline() {
111 let (analysis, pos) = analysis_and_position( 105 let (analysis, pos) = fixture::position(
112 " 106 "
113 //- /lib.rs 107 //- /lib.rs
114 mod foo { 108 mod foo {
@@ -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) = fixture::file(
128 r#" 122 r#"
129//- /bar.rs 123//- /main.rs
130mod foo; 124mod 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 = AnalysisChange::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}