Skip to content

Commit 1973f01

Browse files
committed
path chagnes
1 parent b6af783 commit 1973f01

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

lib/src/ontology.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -264,36 +264,50 @@ impl SerializeAs<NamedNode> for LocalType {
264264
mod tests {
265265
use super::*;
266266

267+
fn assert_location_matches_path(display: &str, iri: &NamedNode, expected: &Path) {
268+
if let Some(url) = OntologyLocation::file_url_for(expected) {
269+
let expected_url: String = url.into();
270+
assert_eq!(display, expected_url, "display should equal file URL");
271+
assert_eq!(iri.as_str(), expected_url, "iri should equal file URL");
272+
} else {
273+
let expected_str = expected.to_string_lossy().into_owned();
274+
assert!(
275+
display.contains(&expected_str),
276+
"display should contain normalized path"
277+
);
278+
assert!(
279+
iri.as_str().contains(&expected_str),
280+
"iri should contain normalized path"
281+
);
282+
}
283+
}
284+
267285
#[test]
268286
fn file_location_with_empty_path_uses_current_dir() {
269287
let cwd = std::env::current_dir().unwrap();
288+
let expected = OntologyLocation::normalized_file_path(Path::new(""));
289+
assert_eq!(expected, cwd);
270290
let location = OntologyLocation::File(PathBuf::new());
271291

272292
let display = location.to_string();
273293
let iri = location.to_iri();
274294

275-
let cwd_str = cwd.to_string_lossy().into_owned();
276-
277295
assert!(!display.is_empty());
278-
assert!(display.contains(&cwd_str));
279-
280-
assert!(iri.as_str().starts_with("file:"));
281-
assert!(iri.as_str().contains(&cwd_str));
296+
assert_location_matches_path(&display, &iri, &expected);
282297
}
283298

284299
#[test]
285300
fn file_location_normalizes_relative_paths() {
286301
let relative = PathBuf::from("some/relative/path");
287302
let location = OntologyLocation::File(relative.clone());
288303

289-
let expected = std::env::current_dir().unwrap().join(relative);
290-
let expected_str = expected.to_string_lossy().into_owned();
291-
304+
let expected = OntologyLocation::normalized_file_path(&relative);
305+
let cwd = std::env::current_dir().unwrap();
306+
assert_eq!(expected, cwd.join(&relative));
292307
let display = location.to_string();
293308
let iri = location.to_iri();
294309

295-
assert!(display.contains(&expected_str));
296-
assert!(iri.as_str().contains(&expected_str));
310+
assert_location_matches_path(&display, &iri, &expected);
297311
}
298312
}
299313

0 commit comments

Comments
 (0)