mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
move tests to separate file
This commit is contained in:
parent
6a16d3fb0b
commit
e89da32bb7
2 changed files with 95 additions and 97 deletions
|
@ -312,7 +312,6 @@ where
|
||||||
let mut segments = import.path.segments.iter().enumerate();
|
let mut segments = import.path.segments.iter().enumerate();
|
||||||
|
|
||||||
let mut curr = match import.path.kind {
|
let mut curr = match import.path.kind {
|
||||||
// TODO: handle extern crates
|
|
||||||
PathKind::Plain => {
|
PathKind::Plain => {
|
||||||
let root_id = module_id.crate_root(&self.module_tree);
|
let root_id = module_id.crate_root(&self.module_tree);
|
||||||
let file_id = root_id.source(&self.module_tree).file_id();
|
let file_id = root_id.source(&self.module_tree).file_id();
|
||||||
|
@ -389,99 +388,4 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use salsa::Database;
|
|
||||||
use ra_db::FilesDatabase;
|
|
||||||
use ra_syntax::SmolStr;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
self as hir,
|
|
||||||
db::HirDatabase,
|
|
||||||
mock::MockDatabase,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn item_map(fixture: &str) -> (Arc<hir::ItemMap>, hir::ModuleId) {
|
|
||||||
let (db, pos) = MockDatabase::with_position(fixture);
|
|
||||||
let source_root = db.file_source_root(pos.file_id);
|
|
||||||
let module = hir::source_binder::module_from_position(&db, pos)
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
let module_id = module.module_id;
|
|
||||||
(db.item_map(source_root).unwrap(), module_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_item_map() {
|
|
||||||
let (item_map, module_id) = item_map(
|
|
||||||
"
|
|
||||||
//- /lib.rs
|
|
||||||
mod foo;
|
|
||||||
|
|
||||||
use crate::foo::bar::Baz;
|
|
||||||
<|>
|
|
||||||
|
|
||||||
//- /foo/mod.rs
|
|
||||||
pub mod bar;
|
|
||||||
|
|
||||||
//- /foo/bar.rs
|
|
||||||
pub struct Baz;
|
|
||||||
",
|
|
||||||
);
|
|
||||||
let name = SmolStr::from("Baz");
|
|
||||||
let resolution = &item_map.per_module[&module_id].items[&name];
|
|
||||||
assert!(resolution.def_id.is_some());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn typing_inside_a_function_should_not_invalidate_item_map() {
|
|
||||||
let (mut db, pos) = MockDatabase::with_position(
|
|
||||||
"
|
|
||||||
//- /lib.rs
|
|
||||||
mod foo;<|>
|
|
||||||
|
|
||||||
use crate::foo::bar::Baz;
|
|
||||||
|
|
||||||
fn foo() -> i32 {
|
|
||||||
1 + 1
|
|
||||||
}
|
|
||||||
//- /foo/mod.rs
|
|
||||||
pub mod bar;
|
|
||||||
|
|
||||||
//- /foo/bar.rs
|
|
||||||
pub struct Baz;
|
|
||||||
",
|
|
||||||
);
|
|
||||||
let source_root = db.file_source_root(pos.file_id);
|
|
||||||
{
|
|
||||||
let events = db.log_executed(|| {
|
|
||||||
db.item_map(source_root).unwrap();
|
|
||||||
});
|
|
||||||
assert!(format!("{:?}", events).contains("item_map"))
|
|
||||||
}
|
|
||||||
|
|
||||||
let new_text = "
|
|
||||||
mod foo;
|
|
||||||
|
|
||||||
use crate::foo::bar::Baz;
|
|
||||||
|
|
||||||
fn foo() -> i32 { 92 }
|
|
||||||
"
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
db.query_mut(ra_db::FileTextQuery)
|
|
||||||
.set(pos.file_id, Arc::new(new_text));
|
|
||||||
|
|
||||||
{
|
|
||||||
let events = db.log_executed(|| {
|
|
||||||
db.item_map(source_root).unwrap();
|
|
||||||
});
|
|
||||||
assert!(
|
|
||||||
!format!("{:?}", events).contains("_item_map"),
|
|
||||||
"{:#?}",
|
|
||||||
events
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
94
crates/ra_hir/src/module/nameres/tests.rs
Normal file
94
crates/ra_hir/src/module/nameres/tests.rs
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use salsa::Database;
|
||||||
|
use ra_db::FilesDatabase;
|
||||||
|
use ra_syntax::SmolStr;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
self as hir,
|
||||||
|
db::HirDatabase,
|
||||||
|
mock::MockDatabase,
|
||||||
|
};
|
||||||
|
|
||||||
|
fn item_map(fixture: &str) -> (Arc<hir::ItemMap>, hir::ModuleId) {
|
||||||
|
let (db, pos) = MockDatabase::with_position(fixture);
|
||||||
|
let source_root = db.file_source_root(pos.file_id);
|
||||||
|
let module = hir::source_binder::module_from_position(&db, pos)
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let module_id = module.module_id;
|
||||||
|
(db.item_map(source_root).unwrap(), module_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_item_map() {
|
||||||
|
let (item_map, module_id) = item_map(
|
||||||
|
"
|
||||||
|
//- /lib.rs
|
||||||
|
mod foo;
|
||||||
|
|
||||||
|
use crate::foo::bar::Baz;
|
||||||
|
<|>
|
||||||
|
|
||||||
|
//- /foo/mod.rs
|
||||||
|
pub mod bar;
|
||||||
|
|
||||||
|
//- /foo/bar.rs
|
||||||
|
pub struct Baz;
|
||||||
|
",
|
||||||
|
);
|
||||||
|
let name = SmolStr::from("Baz");
|
||||||
|
let resolution = &item_map.per_module[&module_id].items[&name];
|
||||||
|
assert!(resolution.def_id.is_some());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn typing_inside_a_function_should_not_invalidate_item_map() {
|
||||||
|
let (mut db, pos) = MockDatabase::with_position(
|
||||||
|
"
|
||||||
|
//- /lib.rs
|
||||||
|
mod foo;<|>
|
||||||
|
|
||||||
|
use crate::foo::bar::Baz;
|
||||||
|
|
||||||
|
fn foo() -> i32 {
|
||||||
|
1 + 1
|
||||||
|
}
|
||||||
|
//- /foo/mod.rs
|
||||||
|
pub mod bar;
|
||||||
|
|
||||||
|
//- /foo/bar.rs
|
||||||
|
pub struct Baz;
|
||||||
|
",
|
||||||
|
);
|
||||||
|
let source_root = db.file_source_root(pos.file_id);
|
||||||
|
{
|
||||||
|
let events = db.log_executed(|| {
|
||||||
|
db.item_map(source_root).unwrap();
|
||||||
|
});
|
||||||
|
assert!(format!("{:?}", events).contains("item_map"))
|
||||||
|
}
|
||||||
|
|
||||||
|
let new_text = "
|
||||||
|
mod foo;
|
||||||
|
|
||||||
|
use crate::foo::bar::Baz;
|
||||||
|
|
||||||
|
fn foo() -> i32 { 92 }
|
||||||
|
"
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
db.query_mut(ra_db::FileTextQuery)
|
||||||
|
.set(pos.file_id, Arc::new(new_text));
|
||||||
|
|
||||||
|
{
|
||||||
|
let events = db.log_executed(|| {
|
||||||
|
db.item_map(source_root).unwrap();
|
||||||
|
});
|
||||||
|
assert!(
|
||||||
|
!format!("{:?}", events).contains("_item_map"),
|
||||||
|
"{:#?}",
|
||||||
|
events
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue