mirror of
https://github.com/nushell/nushell.git
synced 2024-11-28 19:33:47 +01:00
f184a77fe1
This PR changes `nu_path::expand_path_with()` to no longer remove trailing slashes. It also fixes bugs in the current implementation due to ineffective tests (Fixes #12602).
51 lines
1.9 KiB
Rust
51 lines
1.9 KiB
Rust
//! Path equality in Rust is defined by comparing their `components()`. However,
|
|
//! `Path::components()` will perform its own normalization, which makes
|
|
//! `assert_eq!` not suitable testing.
|
|
//!
|
|
//! This module provides two macros, `assert_path_eq!` and `assert_path_ne!`,
|
|
//! which converts path to string before comparison. They accept PathBuf, Path,
|
|
//! String, and &str as parameters.
|
|
|
|
#[macro_export]
|
|
macro_rules! assert_path_eq {
|
|
($left:expr, $right:expr $(,)?) => {
|
|
assert_eq!(
|
|
AsRef::<Path>::as_ref(&$left).to_str().unwrap(),
|
|
AsRef::<Path>::as_ref(&$right).to_str().unwrap()
|
|
)
|
|
};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! assert_path_ne {
|
|
($left:expr, $right:expr $(,)?) => {
|
|
assert_ne!(
|
|
AsRef::<Path>::as_ref(&$left).to_str().unwrap(),
|
|
AsRef::<Path>::as_ref(&$right).to_str().unwrap()
|
|
)
|
|
};
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
use std::path::{Path, PathBuf};
|
|
|
|
#[test]
|
|
fn assert_path_eq_works() {
|
|
assert_path_eq!(PathBuf::from("/foo/bar"), Path::new("/foo/bar"));
|
|
assert_path_eq!(PathBuf::from("/foo/bar"), String::from("/foo/bar"));
|
|
assert_path_eq!(PathBuf::from("/foo/bar"), "/foo/bar");
|
|
assert_path_eq!(Path::new("/foo/bar"), String::from("/foo/bar"));
|
|
assert_path_eq!(Path::new("/foo/bar"), "/foo/bar");
|
|
assert_path_eq!(Path::new(r"\foo\bar"), r"\foo\bar");
|
|
|
|
assert_path_ne!(PathBuf::from("/foo/bar/."), Path::new("/foo/bar"));
|
|
assert_path_ne!(PathBuf::from("/foo/bar/."), String::from("/foo/bar"));
|
|
assert_path_ne!(PathBuf::from("/foo/bar/."), "/foo/bar");
|
|
assert_path_ne!(Path::new("/foo/./bar"), String::from("/foo/bar"));
|
|
assert_path_ne!(Path::new("/foo/./bar"), "/foo/bar");
|
|
assert_path_ne!(Path::new(r"\foo\bar"), r"/foo/bar");
|
|
assert_path_ne!(Path::new(r"/foo/bar"), r"\foo\bar");
|
|
}
|
|
}
|