diff options
author | Aleksey Kladov <[email protected]> | 2018-09-10 18:14:31 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-09-15 22:00:05 +0100 |
commit | 99d02fe583f4747f67debc1973a3eb3ca62e2005 (patch) | |
tree | 61af7d14bb5eafec446ee5b1bc9d07d13ef70006 /crates/libanalysis/tests | |
parent | 6ee4c287f9c95738f0482bf635ccc3801fc2fea2 (diff) |
start query-based modules
Diffstat (limited to 'crates/libanalysis/tests')
-rw-r--r-- | crates/libanalysis/tests/tests.rs | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/crates/libanalysis/tests/tests.rs b/crates/libanalysis/tests/tests.rs index 00efe059c..547f85958 100644 --- a/crates/libanalysis/tests/tests.rs +++ b/crates/libanalysis/tests/tests.rs | |||
@@ -14,24 +14,6 @@ use test_utils::assert_eq_dbg; | |||
14 | #[derive(Debug)] | 14 | #[derive(Debug)] |
15 | struct FileMap(Vec<(FileId, RelativePathBuf)>); | 15 | struct FileMap(Vec<(FileId, RelativePathBuf)>); |
16 | 16 | ||
17 | fn analysis_host(files: &'static [(&'static str, &'static str)]) -> AnalysisHost { | ||
18 | let mut host = AnalysisHost::new(); | ||
19 | let mut file_map = Vec::new(); | ||
20 | for (id, &(path, contents)) in files.iter().enumerate() { | ||
21 | let file_id = FileId((id + 1) as u32); | ||
22 | assert!(path.starts_with('/')); | ||
23 | let path = RelativePathBuf::from_path(&path[1..]).unwrap(); | ||
24 | host.change_file(file_id, Some(contents.to_string())); | ||
25 | file_map.push((file_id, path)); | ||
26 | } | ||
27 | host.set_file_resolver(Arc::new(FileMap(file_map))); | ||
28 | host | ||
29 | } | ||
30 | |||
31 | fn analysis(files: &'static [(&'static str, &'static str)]) -> Analysis { | ||
32 | analysis_host(files).analysis() | ||
33 | } | ||
34 | |||
35 | impl FileMap { | 17 | impl FileMap { |
36 | fn iter<'a>(&'a self) -> impl Iterator<Item=(FileId, &'a RelativePath)> + 'a { | 18 | fn iter<'a>(&'a self) -> impl Iterator<Item=(FileId, &'a RelativePath)> + 'a { |
37 | self.0.iter().map(|(id, path)| (*id, path.as_relative_path())) | 19 | self.0.iter().map(|(id, path)| (*id, path.as_relative_path())) |
@@ -56,6 +38,23 @@ impl FileResolver for FileMap { | |||
56 | } | 38 | } |
57 | } | 39 | } |
58 | 40 | ||
41 | fn analysis_host(files: &'static [(&'static str, &'static str)]) -> AnalysisHost { | ||
42 | let mut host = AnalysisHost::new(); | ||
43 | let mut file_map = Vec::new(); | ||
44 | for (id, &(path, contents)) in files.iter().enumerate() { | ||
45 | let file_id = FileId((id + 1) as u32); | ||
46 | assert!(path.starts_with('/')); | ||
47 | let path = RelativePathBuf::from_path(&path[1..]).unwrap(); | ||
48 | host.change_file(file_id, Some(contents.to_string())); | ||
49 | file_map.push((file_id, path)); | ||
50 | } | ||
51 | host.set_file_resolver(Arc::new(FileMap(file_map))); | ||
52 | host | ||
53 | } | ||
54 | |||
55 | fn analysis(files: &'static [(&'static str, &'static str)]) -> Analysis { | ||
56 | analysis_host(files).analysis() | ||
57 | } | ||
59 | 58 | ||
60 | #[test] | 59 | #[test] |
61 | fn test_resolve_module() { | 60 | fn test_resolve_module() { |