From d0e22d7578bc789748b784bd72f338908e10d611 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 5 Sep 2018 18:27:44 +0300 Subject: less hacky paths --- crates/libanalysis/tests/tests.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'crates/libanalysis') diff --git a/crates/libanalysis/tests/tests.rs b/crates/libanalysis/tests/tests.rs index 9d2db731b..1f210f579 100644 --- a/crates/libanalysis/tests/tests.rs +++ b/crates/libanalysis/tests/tests.rs @@ -7,7 +7,7 @@ use std::{ path::{Path}, }; -use relative_path::RelativePath; +use relative_path::{RelativePath, RelativePathBuf}; use libanalysis::{AnalysisHost, FileId, FileResolver, JobHandle, CrateGraph, CrateId}; use test_utils::assert_eq_dbg; @@ -28,18 +28,15 @@ impl FileResolver for FileMap { self.path(id).file_stem().unwrap().to_str().unwrap().to_string() } fn resolve(&self, id: FileId, rel: &RelativePath) -> Option { - let path = { - if rel.starts_with("..") { - rel.strip_prefix("..").unwrap() - .to_path(&self.path(id).parent().unwrap()) - } else { - rel.to_path(self.path(id)) - } - }; - let path = &path.to_str().unwrap()[1..]; - let path = RelativePath::new(&path[0..]).normalize(); + let path = rel.to_path(self.path(id)); + let path = path.strip_prefix("/").unwrap(); + let path = RelativePathBuf::from_path(&path).unwrap().normalize(); let &(id, _) = self.0.iter() - .find(|it| path == RelativePath::new(&it.1[0..]).normalize())?; + .find(|it| { + let p = Path::new(it.1).strip_prefix("/").unwrap(); + let p = RelativePathBuf::from_path(p).unwrap(); + path == p + })?; Some(FileId(id)) } } -- cgit v1.2.3