aboutsummaryrefslogtreecommitdiff
path: root/crates/libanalysis/tests
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libanalysis/tests')
-rw-r--r--crates/libanalysis/tests/tests.rs34
1 files changed, 16 insertions, 18 deletions
diff --git a/crates/libanalysis/tests/tests.rs b/crates/libanalysis/tests/tests.rs
index 1f210f579..ebc8037b3 100644
--- a/crates/libanalysis/tests/tests.rs
+++ b/crates/libanalysis/tests/tests.rs
@@ -4,40 +4,38 @@ extern crate test_utils;
4 4
5use std::{ 5use std::{
6 collections::HashMap, 6 collections::HashMap,
7 path::{Path},
8}; 7};
9 8
10use relative_path::{RelativePath, RelativePathBuf}; 9use relative_path::{RelativePath};
11use libanalysis::{AnalysisHost, FileId, FileResolver, JobHandle, CrateGraph, CrateId}; 10use libanalysis::{AnalysisHost, FileId, FileResolver, JobHandle, CrateGraph, CrateId};
12use test_utils::assert_eq_dbg; 11use test_utils::assert_eq_dbg;
13 12
14struct FileMap(&'static [(u32, &'static str)]); 13struct FileMap(&'static [(u32, &'static str)]);
15 14
16impl FileMap { 15impl FileMap {
17 fn path(&self, id: FileId) -> &'static Path { 16 fn iter<'a>(&'a self) -> impl Iterator<Item=(FileId, &'a RelativePath)> + 'a {
18 let s = self.0.iter() 17 self.0.iter().map(|&(id, path)| {
19 .find(|it| it.0 == id.0) 18 assert!(path.starts_with('/'));
19 (FileId(id), RelativePath::new(&path[1..]))
20 })
21 }
22
23 fn path(&self, id: FileId) -> &RelativePath {
24 self.iter()
25 .find(|&(it, _)| it == id)
20 .unwrap() 26 .unwrap()
21 .1; 27 .1
22 Path::new(s)
23 } 28 }
24} 29}
25 30
26impl FileResolver for FileMap { 31impl FileResolver for FileMap {
27 fn file_stem(&self, id: FileId) -> String { 32 fn file_stem(&self, id: FileId) -> String {
28 self.path(id).file_stem().unwrap().to_str().unwrap().to_string() 33 self.path(id).file_stem().unwrap().to_string()
29 } 34 }
30 fn resolve(&self, id: FileId, rel: &RelativePath) -> Option<FileId> { 35 fn resolve(&self, id: FileId, rel: &RelativePath) -> Option<FileId> {
31 let path = rel.to_path(self.path(id)); 36 let path = self.path(id).join(rel).normalize();
32 let path = path.strip_prefix("/").unwrap(); 37 let id = self.iter().find(|&(_, p)| path == p)?.0;
33 let path = RelativePathBuf::from_path(&path).unwrap().normalize(); 38 Some(id)
34 let &(id, _) = self.0.iter()
35 .find(|it| {
36 let p = Path::new(it.1).strip_prefix("/").unwrap();
37 let p = RelativePathBuf::from_path(p).unwrap();
38 path == p
39 })?;
40 Some(FileId(id))
41 } 39 }
42} 40}
43 41