aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-01-28 16:03:24 +0000
committerKirill Bulatov <[email protected]>2020-01-28 16:03:24 +0000
commit713870ee0c51a11dc0d2a5b8eafbc2624d42c359 (patch)
tree80c27afadba55e1c92a799e04b9eb06233e6cb8d /crates/ra_hir_def/src
parent07b505b6339b84c0dfd5c6b1b5aaa163f73f1df2 (diff)
Add the tests
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/find_path.rs41
-rw-r--r--crates/ra_hir_def/src/marks.rs1
2 files changed, 42 insertions, 0 deletions
diff --git a/crates/ra_hir_def/src/find_path.rs b/crates/ra_hir_def/src/find_path.rs
index ebfd6e211..43b9b124a 100644
--- a/crates/ra_hir_def/src/find_path.rs
+++ b/crates/ra_hir_def/src/find_path.rs
@@ -8,6 +8,7 @@ use crate::{
8 CrateId, ModuleDefId, ModuleId, 8 CrateId, ModuleDefId, ModuleId,
9}; 9};
10use hir_expand::name::{known, Name}; 10use hir_expand::name::{known, Name};
11use test_utils::tested_by;
11 12
12const MAX_PATH_LEN: usize = 15; 13const MAX_PATH_LEN: usize = 15;
13 14
@@ -151,8 +152,10 @@ fn find_path_inner(
151 152
152fn select_best_path(old_path: ModPath, new_path: ModPath) -> ModPath { 153fn select_best_path(old_path: ModPath, new_path: ModPath) -> ModPath {
153 if old_path.starts_with_std() && new_path.should_start_with_std() { 154 if old_path.starts_with_std() && new_path.should_start_with_std() {
155 tested_by!(prefer_std_paths);
154 old_path 156 old_path
155 } else if new_path.starts_with_std() && old_path.should_start_with_std() { 157 } else if new_path.starts_with_std() && old_path.should_start_with_std() {
158 tested_by!(prefer_std_paths);
156 new_path 159 new_path
157 } else if new_path.len() < old_path.len() { 160 } else if new_path.len() < old_path.len() {
158 new_path 161 new_path
@@ -231,6 +234,7 @@ mod tests {
231 use hir_expand::hygiene::Hygiene; 234 use hir_expand::hygiene::Hygiene;
232 use ra_db::fixture::WithFixture; 235 use ra_db::fixture::WithFixture;
233 use ra_syntax::ast::AstNode; 236 use ra_syntax::ast::AstNode;
237 use test_utils::covers;
234 238
235 /// `code` needs to contain a cursor marker; checks that `find_path` for the 239 /// `code` needs to contain a cursor marker; checks that `find_path` for the
236 /// item the `path` refers to returns that same path when called from the 240 /// item the `path` refers to returns that same path when called from the
@@ -482,4 +486,41 @@ mod tests {
482 "#; 486 "#;
483 check_found_path(code, "crate::foo::S"); 487 check_found_path(code, "crate::foo::S");
484 } 488 }
489
490 #[test]
491 fn prefer_std_paths_over_alloc() {
492 covers!(prefer_std_paths);
493 let code = r#"
494 //- /main.rs crate:main deps:alloc,std
495 <|>
496
497 //- /std.rs crate:std deps:alloc
498 pub mod sync {
499 pub use alloc::sync::Arc;
500 }
501
502 //- /zzz.rs crate:alloc
503 pub mod sync {
504 pub struct Arc;
505 }
506 "#;
507 check_found_path(code, "std::sync::Arc");
508 }
509
510 #[test]
511 fn prefer_shorter_paths_if_not_alloc() {
512 let code = r#"
513 //- /main.rs crate:main deps:megaalloc,std
514 <|>
515
516 //- /std.rs crate:std deps:megaalloc
517 pub mod sync {
518 pub use megaalloc::sync::Arc;
519 }
520
521 //- /zzz.rs crate:megaalloc
522 pub struct Arc;
523 "#;
524 check_found_path(code, "megaalloc::Arc");
525 }
485} 526}
diff --git a/crates/ra_hir_def/src/marks.rs b/crates/ra_hir_def/src/marks.rs
index 457ba4abe..daa49d5f1 100644
--- a/crates/ra_hir_def/src/marks.rs
+++ b/crates/ra_hir_def/src/marks.rs
@@ -13,4 +13,5 @@ test_utils::marks!(
13 macro_dollar_crate_self 13 macro_dollar_crate_self
14 macro_dollar_crate_other 14 macro_dollar_crate_other
15 infer_resolve_while_let 15 infer_resolve_while_let
16 prefer_std_paths
16); 17);