mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-08 04:46:15 +08:00
Add unit tests for path_normalize_for_cd()
This commit is contained in:
parent
8c62f733b3
commit
96b979077c
|
@ -322,6 +322,90 @@ pub fn path_normalize_for_cd(wd: &wstr, path: &wstr) -> WString {
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod path_cd_tests {
|
||||||
|
use super::path_normalize_for_cd;
|
||||||
|
use crate::wchar::L;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn relative_path() {
|
||||||
|
let wd = L!("/home/user/");
|
||||||
|
let path = L!("projects");
|
||||||
|
eprintln!("({}, {})", wd, path);
|
||||||
|
assert_eq!(path_normalize_for_cd(wd, path), L!("/home/user/projects"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn absolute_path() {
|
||||||
|
let wd = L!("/home/user/");
|
||||||
|
let path = L!("/etc");
|
||||||
|
eprintln!("({}, {})", wd, path);
|
||||||
|
assert_eq!(path_normalize_for_cd(wd, path), L!("/etc"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parent_directory() {
|
||||||
|
let wd = L!("/home/user/projects/");
|
||||||
|
let path = L!("../docs");
|
||||||
|
eprintln!("({}, {})", wd, path);
|
||||||
|
assert_eq!(path_normalize_for_cd(wd, path), L!("/home/user/docs"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn current_directory() {
|
||||||
|
let wd = L!("/home/user/");
|
||||||
|
let path = L!("./");
|
||||||
|
eprintln!("({}, {})", wd, path);
|
||||||
|
assert_eq!(path_normalize_for_cd(wd, path), L!("/home/user"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn nested_parent_directory() {
|
||||||
|
let wd = L!("/home/user/projects/");
|
||||||
|
let path = L!("../../");
|
||||||
|
eprintln!("({}, {})", wd, path);
|
||||||
|
assert_eq!(path_normalize_for_cd(wd, path), L!("/home"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn complex_path() {
|
||||||
|
let wd = L!("/home/user/projects/");
|
||||||
|
let path = L!("./../other/projects/./.././../docs");
|
||||||
|
eprintln!("({}, {})", wd, path);
|
||||||
|
assert_eq!(
|
||||||
|
path_normalize_for_cd(wd, path),
|
||||||
|
L!("/home/user/other/projects/./.././../docs")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn root_directory() {
|
||||||
|
let wd = L!("/");
|
||||||
|
let path = L!("..");
|
||||||
|
eprintln!("({}, {})", wd, path);
|
||||||
|
assert_eq!(path_normalize_for_cd(wd, path), L!("/.."));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty_path() {
|
||||||
|
let wd = L!("/home/user/");
|
||||||
|
let path = L!("");
|
||||||
|
eprintln!("({}, {})", wd, path);
|
||||||
|
assert_eq!(path_normalize_for_cd(wd, path), L!("/home/user/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn trailing_slash() {
|
||||||
|
let wd = L!("/home/user/projects/");
|
||||||
|
let path = L!("docs/");
|
||||||
|
eprintln!("({}, {})", wd, path);
|
||||||
|
assert_eq!(
|
||||||
|
path_normalize_for_cd(wd, path),
|
||||||
|
L!("/home/user/projects/docs/")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Wide character version of dirname().
|
/// Wide character version of dirname().
|
||||||
pub fn wdirname(mut path: &wstr) -> &wstr {
|
pub fn wdirname(mut path: &wstr) -> &wstr {
|
||||||
// Do not use system-provided dirname (#7837).
|
// Do not use system-provided dirname (#7837).
|
||||||
|
|
Loading…
Reference in New Issue
Block a user