diff options
author | Aleksey Kladov <[email protected]> | 2019-11-15 10:16:16 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-15 10:16:30 +0000 |
commit | 5766ceab0629acc4464dcc57d00d9cc5c12f1c6b (patch) | |
tree | 01f180b8475b7a1ac7b4aa550beea556f3c23847 | |
parent | 3564fbb7f5fc7fc91530c441a6dacce88762fcc9 (diff) |
Add convenience method for testing
-rw-r--r-- | crates/ra_db/src/fixture.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests/incremental.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests/mod_resolution.rs | 2 |
4 files changed, 15 insertions, 7 deletions
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs index ee883b615..ade187629 100644 --- a/crates/ra_db/src/fixture.rs +++ b/crates/ra_db/src/fixture.rs | |||
@@ -8,8 +8,8 @@ use rustc_hash::FxHashMap; | |||
8 | use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER}; | 8 | use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER}; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | CrateGraph, Edition, FileId, FilePosition, RelativePathBuf, SourceDatabaseExt, SourceRoot, | 11 | CrateGraph, CrateId, Edition, FileId, FilePosition, RelativePathBuf, SourceDatabaseExt, |
12 | SourceRootId, | 12 | SourceRoot, SourceRootId, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | pub const WORKSPACE: SourceRootId = SourceRootId(0); | 15 | pub const WORKSPACE: SourceRootId = SourceRootId(0); |
@@ -33,6 +33,14 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static { | |||
33 | let pos = with_files(&mut db, fixture); | 33 | let pos = with_files(&mut db, fixture); |
34 | (db, pos.unwrap()) | 34 | (db, pos.unwrap()) |
35 | } | 35 | } |
36 | |||
37 | fn test_crate(&self) -> CrateId { | ||
38 | let crate_graph = self.crate_graph(); | ||
39 | let mut it = crate_graph.iter(); | ||
40 | let res = it.next().unwrap(); | ||
41 | assert!(it.next().is_none()); | ||
42 | res | ||
43 | } | ||
36 | } | 44 | } |
37 | 45 | ||
38 | impl<DB: SourceDatabaseExt + Default + 'static> WithFixture for DB {} | 46 | impl<DB: SourceDatabaseExt + Default + 'static> WithFixture for DB {} |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 37d0f3093..83eef821f 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -798,7 +798,7 @@ mod tests { | |||
798 | 798 | ||
799 | fn do_limited_resolve(code: &str, limit: u32, poison_limit: u32) -> CrateDefMap { | 799 | fn do_limited_resolve(code: &str, limit: u32, poison_limit: u32) -> CrateDefMap { |
800 | let (db, _file_id) = TestDB::with_single_file(&code); | 800 | let (db, _file_id) = TestDB::with_single_file(&code); |
801 | let krate = db.crate_graph().iter().next().unwrap(); | 801 | let krate = db.test_crate(); |
802 | 802 | ||
803 | let def_map = { | 803 | let def_map = { |
804 | let edition = db.crate_graph().edition(krate); | 804 | let edition = db.crate_graph().edition(krate); |
diff --git a/crates/ra_hir_def/src/nameres/tests/incremental.rs b/crates/ra_hir_def/src/nameres/tests/incremental.rs index 80dcec62f..903a22771 100644 --- a/crates/ra_hir_def/src/nameres/tests/incremental.rs +++ b/crates/ra_hir_def/src/nameres/tests/incremental.rs | |||
@@ -1,12 +1,12 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use ra_db::{SourceDatabase, SourceDatabaseExt}; | 3 | use ra_db::SourceDatabaseExt; |
4 | 4 | ||
5 | use super::*; | 5 | use super::*; |
6 | 6 | ||
7 | fn check_def_map_is_not_recomputed(initial: &str, file_change: &str) { | 7 | fn check_def_map_is_not_recomputed(initial: &str, file_change: &str) { |
8 | let (mut db, pos) = TestDB::with_position(initial); | 8 | let (mut db, pos) = TestDB::with_position(initial); |
9 | let krate = db.crate_graph().iter().next().unwrap(); | 9 | let krate = db.test_crate(); |
10 | { | 10 | { |
11 | let events = db.log_executed(|| { | 11 | let events = db.log_executed(|| { |
12 | db.crate_def_map(krate); | 12 | db.crate_def_map(krate); |
@@ -111,7 +111,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() { | |||
111 | m!(X); | 111 | m!(X); |
112 | ", | 112 | ", |
113 | ); | 113 | ); |
114 | let krate = db.crate_graph().iter().next().unwrap(); | 114 | let krate = db.test_crate(); |
115 | { | 115 | { |
116 | let events = db.log_executed(|| { | 116 | let events = db.log_executed(|| { |
117 | let crate_def_map = db.crate_def_map(krate); | 117 | let crate_def_map = db.crate_def_map(krate); |
diff --git a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs index dee364a14..eb7b85c07 100644 --- a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs +++ b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs | |||
@@ -656,7 +656,7 @@ fn unresolved_module_diagnostics() { | |||
656 | //- /foo.rs | 656 | //- /foo.rs |
657 | ", | 657 | ", |
658 | ); | 658 | ); |
659 | let krate = db.crate_graph().iter().next().unwrap(); | 659 | let krate = db.test_crate(); |
660 | 660 | ||
661 | let crate_def_map = db.crate_def_map(krate); | 661 | let crate_def_map = db.crate_def_map(krate); |
662 | 662 | ||