mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 11:38:05 +02:00
engine-q merge
This commit is contained in:
@ -1,6 +1,10 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
<<<<<<< HEAD
|
||||
fn expand_tilde_with(path: impl AsRef<Path>, home: Option<PathBuf>) -> PathBuf {
|
||||
=======
|
||||
fn expand_tilde_with_home(path: impl AsRef<Path>, home: Option<PathBuf>) -> PathBuf {
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
let path = path.as_ref();
|
||||
|
||||
if !path.starts_with("~") {
|
||||
@ -27,7 +31,11 @@ fn expand_tilde_with(path: impl AsRef<Path>, home: Option<PathBuf>) -> PathBuf {
|
||||
/// Expand tilde ("~") into a home directory if it is the first path component
|
||||
pub fn expand_tilde(path: impl AsRef<Path>) -> PathBuf {
|
||||
// TODO: Extend this to work with "~user" style of home paths
|
||||
<<<<<<< HEAD
|
||||
expand_tilde_with(path, dirs_next::home_dir())
|
||||
=======
|
||||
expand_tilde_with_home(path, dirs_next::home_dir())
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -37,17 +45,29 @@ mod tests {
|
||||
fn check_expanded(s: &str) {
|
||||
let home = Path::new("/home");
|
||||
let buf = Some(PathBuf::from(home));
|
||||
<<<<<<< HEAD
|
||||
assert!(expand_tilde_with(Path::new(s), buf).starts_with(&home));
|
||||
=======
|
||||
assert!(expand_tilde_with_home(Path::new(s), buf).starts_with(&home));
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
|
||||
// Tests the special case in expand_tilde for "/" as home
|
||||
let home = Path::new("/");
|
||||
let buf = Some(PathBuf::from(home));
|
||||
<<<<<<< HEAD
|
||||
assert!(!expand_tilde_with(Path::new(s), buf).starts_with("//"));
|
||||
=======
|
||||
assert!(!expand_tilde_with_home(Path::new(s), buf).starts_with("//"));
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
}
|
||||
|
||||
fn check_not_expanded(s: &str) {
|
||||
let home = PathBuf::from("/home");
|
||||
<<<<<<< HEAD
|
||||
let expanded = expand_tilde_with(Path::new(s), Some(home));
|
||||
=======
|
||||
let expanded = expand_tilde_with_home(Path::new(s), Some(home));
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
assert!(expanded == Path::new(s));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user