diff options
Diffstat (limited to 'crates/ide/src/parent_module.rs')
-rw-r--r-- | crates/ide/src/parent_module.rs | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/crates/ide/src/parent_module.rs b/crates/ide/src/parent_module.rs index d343638fb..ddbaf22b7 100644 --- a/crates/ide/src/parent_module.rs +++ b/crates/ide/src/parent_module.rs | |||
@@ -63,57 +63,62 @@ 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 ide_db::base_db::FileRange; | ||
66 | use test_utils::mark; | 67 | use test_utils::mark; |
67 | 68 | ||
68 | use crate::fixture::{self}; | 69 | use crate::fixture; |
70 | |||
71 | fn check(ra_fixture: &str) { | ||
72 | let (analysis, position, expected) = fixture::nav_target_annotation(ra_fixture); | ||
73 | let mut navs = analysis.parent_module(position).unwrap(); | ||
74 | assert_eq!(navs.len(), 1); | ||
75 | let nav = navs.pop().unwrap(); | ||
76 | assert_eq!(expected, FileRange { file_id: nav.file_id, range: nav.focus_or_full_range() }); | ||
77 | } | ||
69 | 78 | ||
70 | #[test] | 79 | #[test] |
71 | fn test_resolve_parent_module() { | 80 | fn test_resolve_parent_module() { |
72 | let (analysis, pos) = fixture::position( | 81 | check( |
73 | " | 82 | r#" |
74 | //- /lib.rs | 83 | //- /lib.rs |
75 | mod foo; | 84 | mod foo; |
76 | //- /foo.rs | 85 | //^^^ |
77 | $0// empty | 86 | |
78 | ", | 87 | //- /foo.rs |
88 | $0// empty | ||
89 | "#, | ||
79 | ); | 90 | ); |
80 | let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); | ||
81 | nav.assert_match("foo Module FileId(0) 0..8"); | ||
82 | } | 91 | } |
83 | 92 | ||
84 | #[test] | 93 | #[test] |
85 | fn test_resolve_parent_module_on_module_decl() { | 94 | fn test_resolve_parent_module_on_module_decl() { |
86 | mark::check!(test_resolve_parent_module_on_module_decl); | 95 | mark::check!(test_resolve_parent_module_on_module_decl); |
87 | let (analysis, pos) = fixture::position( | 96 | check( |
88 | " | 97 | r#" |
89 | //- /lib.rs | 98 | //- /lib.rs |
90 | mod foo; | 99 | mod foo; |
91 | 100 | //^^^ | |
92 | //- /foo.rs | 101 | //- /foo.rs |
93 | mod $0bar; | 102 | mod $0bar; |
94 | 103 | ||
95 | //- /foo/bar.rs | 104 | //- /foo/bar.rs |
96 | // empty | 105 | // empty |
97 | ", | 106 | "#, |
98 | ); | 107 | ); |
99 | let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); | ||
100 | nav.assert_match("foo Module FileId(0) 0..8"); | ||
101 | } | 108 | } |
102 | 109 | ||
103 | #[test] | 110 | #[test] |
104 | fn test_resolve_parent_module_for_inline() { | 111 | fn test_resolve_parent_module_for_inline() { |
105 | let (analysis, pos) = fixture::position( | 112 | check( |
106 | " | 113 | r#" |
107 | //- /lib.rs | 114 | //- /lib.rs |
108 | mod foo { | 115 | mod foo { |
109 | mod bar { | 116 | mod bar { |
110 | mod baz { $0 } | 117 | mod baz { $0 } |
111 | } | 118 | } //^^^ |
112 | } | 119 | } |
113 | ", | 120 | "#, |
114 | ); | 121 | ); |
115 | let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); | ||
116 | nav.assert_match("baz Module FileId(0) 32..44"); | ||
117 | } | 122 | } |
118 | 123 | ||
119 | #[test] | 124 | #[test] |