use std::path::Path;
use syn_inline_mod::InlinerBuilder;
#[test]
fn resolve_lib() {
let builder = InlinerBuilder::new();
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let lib_rs = manifest_dir.join("src/lib.rs");
let mut files_seen = vec![];
let res = builder
.inline_with_callback(&lib_rs, |path, file| {
files_seen.push((path.to_path_buf(), file));
})
.expect("src/lib.rs should parse successfully");
assert!(!res.has_errors(), "result has no errors");
let file_list: Vec<_> = files_seen
.iter()
.map(|(path, _)| {
let rel_path = path
.strip_prefix(manifest_dir)
.expect("path should be relative to manifest dir");
rel_path.to_str().expect("path is valid Unicode")
})
.collect();
assert_eq!(
file_list,
vec![
"src/lib.rs",
"src/mod_path.rs",
"src/resolver.rs",
"src/visitor.rs",
]
);
for (path, contents) in &files_seen {
let disk_contents = std::fs::read_to_string(path).expect("reading contents failed");
assert_eq!(&disk_contents, contents, "file contents match");
}
}