engine-q merge

This commit is contained in:
Fernando Herrera
2022-02-07 19:11:34 +00:00
1965 changed files with 119062 additions and 20 deletions

View File

@ -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));
}