forked from extern/nushell
Refactor arguments of path subcommands & Add path join subcommand (#3123)
* Refactor path subcommand argument handling DefaultArguments are no longer passed to each subcommand. Instead, each subcommand has its own Path<xxx>Arguments. This means that it is no longer necessary to edit every single path subcommand source file when changing the arguments struct. * Add new path join subcommand Makes it easier to create new paths. It's just a wrapper around Rust's Path.join().
This commit is contained in:
45
crates/nu-command/tests/commands/path/join.rs
Normal file
45
crates/nu-command/tests/commands/path/join.rs
Normal file
@ -0,0 +1,45 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
use super::join_path_sep;
|
||||
|
||||
#[test]
|
||||
fn returns_path_joined_with_column_path() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo [ [name]; [eggs] ]
|
||||
| path join spam.txt name
|
||||
| get name
|
||||
"#
|
||||
));
|
||||
|
||||
let expected = join_path_sep(&["eggs", "spam.txt"]);
|
||||
assert_eq!(actual.out, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn appends_slash_when_joined_with_empty_path() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "/some/dir"
|
||||
| path join ''
|
||||
"#
|
||||
));
|
||||
|
||||
let expected = join_path_sep(&["/some/dir", ""]);
|
||||
assert_eq!(actual.out, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_joined_path_when_joining_empty_path() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo ""
|
||||
| path join foo.txt
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "foo.txt");
|
||||
}
|
Reference in New Issue
Block a user