Add some unit tests for path expansion
This commit is contained in:
40
src/lib.rs
40
src/lib.rs
@@ -19,6 +19,46 @@ use repo::{
|
|||||||
|
|
||||||
const GIT_MAIN_WORKTREE_DIRECTORY: &str = ".git-main-working-tree";
|
const GIT_MAIN_WORKTREE_DIRECTORY: &str = ".git-main-working-tree";
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn setup() {
|
||||||
|
std::env::set_var("HOME", "/home/test");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_expand_tilde() {
|
||||||
|
setup();
|
||||||
|
assert_eq!(
|
||||||
|
expand_path(Path::new("~/file")),
|
||||||
|
Path::new("/home/test/file")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_expand_invalid_tilde() {
|
||||||
|
setup();
|
||||||
|
assert_eq!(
|
||||||
|
expand_path(Path::new("/home/~/file")),
|
||||||
|
Path::new("/home/~/file")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_expand_home() {
|
||||||
|
setup();
|
||||||
|
assert_eq!(
|
||||||
|
expand_path(Path::new("$HOME/file")),
|
||||||
|
Path::new("/home/test/file")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
expand_path(Path::new("${HOME}/file")),
|
||||||
|
Path::new("/home/test/file")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn path_as_string(path: &Path) -> String {
|
fn path_as_string(path: &Path) -> String {
|
||||||
path.to_path_buf().into_os_string().into_string().unwrap()
|
path.to_path_buf().into_os_string().into_string().unwrap()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user