Skip to content

Commit

Permalink
add test case for include resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Akhil T Thomas committed Nov 20, 2024
1 parent fdd1ad0 commit e2ff0a6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions a2lfile/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ mod tests {

#[test]
fn included_files() {
use std::path::{Path, MAIN_SEPARATOR};
let dir = tempdir().unwrap();

// base file at <tempdir>/base
Expand Down Expand Up @@ -257,5 +258,22 @@ mod tests {
let out_path = Path::new(&out).canonicalize().unwrap();
let expected = subdir.join("def/include2").canonicalize().unwrap();
assert_eq!(out_path.to_string_lossy(), expected.to_string_lossy());

// verify if cross platform paths work
let (incname, expected_subdir) = if cfg!(windows) {
// unix-style input path on Windows
("abc/include1", format!("abc{}include1", MAIN_SEPARATOR))
} else {
// Windows-style input path on Unix
(r"abc\include1", format!("abc{}include1", MAIN_SEPARATOR))
};
let out = make_include_filename(incname, base_filename.as_os_str())
.into_string()
.unwrap();
let out_path = Path::new(&out).canonicalize().expect("Output path should be resolvable");
let expected_path = dir.path().join(expected_subdir);
let expected = expected_path.canonicalize()
.expect("Expected path should be resolvable");
assert_eq!(out_path.to_string_lossy(), expected.to_string_lossy(), "Normalized output does not match");
}
}

0 comments on commit e2ff0a6

Please sign in to comment.