2020-11-24 10:18:38 +01:00
|
|
|
use nu_test_support::fs::Stub::EmptyFile;
|
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expands_path_with_dot() {
|
|
|
|
Playground::setup("path_expand_1", |dirs, sandbox| {
|
|
|
|
sandbox
|
|
|
|
.within("menu")
|
|
|
|
.with_files(vec![EmptyFile("spam.txt")]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
2022-02-21 14:38:15 +01:00
|
|
|
echo "menu/./spam.txt"
|
2020-11-24 10:18:38 +01:00
|
|
|
| path expand
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
let expected = dirs.test.join("menu").join("spam.txt");
|
|
|
|
assert_eq!(PathBuf::from(actual.out), expected);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expands_path_with_double_dot() {
|
|
|
|
Playground::setup("path_expand_2", |dirs, sandbox| {
|
|
|
|
sandbox
|
|
|
|
.within("menu")
|
|
|
|
.with_files(vec![EmptyFile("spam.txt")]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
2022-02-21 14:38:15 +01:00
|
|
|
echo "menu/../menu/spam.txt"
|
2020-11-24 10:18:38 +01:00
|
|
|
| path expand
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
let expected = dirs.test.join("menu").join("spam.txt");
|
|
|
|
assert_eq!(PathBuf::from(actual.out), expected);
|
|
|
|
})
|
|
|
|
}
|
2021-06-20 01:07:26 +02:00
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
mod windows {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expands_path_with_tilde_backward_slash() {
|
|
|
|
Playground::setup("path_expand_2", |dirs, _| {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
echo "~\tmp.txt" | path expand
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(!PathBuf::from(actual.out).starts_with("~"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn win_expands_path_with_tilde_forward_slash() {
|
|
|
|
Playground::setup("path_expand_2", |dirs, _| {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
echo "~/tmp.txt" | path expand
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(!PathBuf::from(actual.out).starts_with("~"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|