mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
i-slint-compiler: Add some tests for fileaccess
This commit is contained in:
parent
a76c3ec789
commit
46b7839db2
1 changed files with 38 additions and 0 deletions
|
@ -38,6 +38,44 @@ pub fn load_file(path: &std::path::Path) -> Option<VirtualFile> {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_load_file() {
|
||||
let builtin = load_file(&std::path::PathBuf::from(
|
||||
"builtin:/foo/../common/./MadeWithSlint-logo-dark.svg",
|
||||
))
|
||||
.unwrap();
|
||||
assert!(builtin.is_builtin());
|
||||
assert_eq!(
|
||||
builtin.canon_path,
|
||||
std::path::PathBuf::from("builtin:/common/MadeWithSlint-logo-dark.svg")
|
||||
);
|
||||
|
||||
let dir = std::env::var_os("CARGO_MANIFEST_DIR").unwrap().to_string_lossy().to_string();
|
||||
let dir_path = std::path::PathBuf::from(dir);
|
||||
|
||||
let non_existing = dir_path.join("XXXCargo.tomlXXX");
|
||||
assert!(load_file(&non_existing).is_none());
|
||||
|
||||
assert!(dir_path.exists()); // We need some existing path for all the rest
|
||||
|
||||
let cargo_toml = dir_path.join("Cargo.toml");
|
||||
let abs_cargo_toml = load_file(&cargo_toml).unwrap();
|
||||
assert!(!abs_cargo_toml.is_builtin());
|
||||
assert!(crate::pathutils::is_absolute(&abs_cargo_toml.canon_path));
|
||||
assert!(abs_cargo_toml.canon_path.exists());
|
||||
|
||||
let current = std::env::current_dir().unwrap();
|
||||
assert!(current.ends_with("compiler")); // This test is run in .../internal/compiler
|
||||
|
||||
let cargo_toml = std::path::PathBuf::from("./tests/../Cargo.toml");
|
||||
let rel_cargo_toml = load_file(&cargo_toml).unwrap();
|
||||
assert!(!rel_cargo_toml.is_builtin());
|
||||
assert!(crate::pathutils::is_absolute(&rel_cargo_toml.canon_path));
|
||||
assert!(rel_cargo_toml.canon_path.exists());
|
||||
|
||||
assert_eq!(abs_cargo_toml.canon_path, rel_cargo_toml.canon_path);
|
||||
}
|
||||
|
||||
mod builtin_library {
|
||||
include!(env!("SLINT_WIDGETS_LIBRARY"));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue