nushell/crates/nu-command/tests/commands/path/basename.rs

84 lines
1.6 KiB
Rust
Raw Normal View History

Path Command Enhancement Project (#2742) * Add string argument support for path subcommands * Add --replace option to 'path extension' command * Add examples of replacing for path extension * Refactor path extension and its example * Add replacement functionality to path basename * Refactor path subcommands to support more args This adds a lot of redundancy to non-relevant subcommands such as type, exists or expand. * Add replace and num_levels options to path dirname * Rename num_levels option to num-levels * Remove commented code * Clean up path basename * Fix path dirname description * Add path filestem opts; Rename extension -> suffix * Add prefix option and examples to path filestem * Fix broken num-levels of path dirname * Fix failing example test of path filestem * Fix failing test of path extension * Formatting * Add Windows-specific path subcommand examples `path expand` is still broken but otherwise seems to fix all examples on Windows * Fix weird path expand on Windows Also disable example tests for path expand. Failed caconicalization (e.g., due to path not existing) returns the original path so the examples always fail. * Formatting * Return path datatype when appropriate * Do not append empty remainder to path dirname * Add tests for path subcommands * Formatting * Revisit path subcommand description strings * Apply clippy suggestions; Formatting * Remove problematic test checking '~' expansion Wouldn't run on minimal due to useing optional dependency. The test success was also deending on the presence of home dir on the testing machine which might not be completely robust. * Add missing newline to file
2020-11-24 10:18:38 +01:00
use nu_test_support::{nu, pipeline};
use super::join_path_sep;
#[test]
fn returns_basename_of_empty_input() {
let actual = nu!(
cwd: "tests", pipeline(
r#"
echo ""
Path Command Enhancement Project (#2742) * Add string argument support for path subcommands * Add --replace option to 'path extension' command * Add examples of replacing for path extension * Refactor path extension and its example * Add replacement functionality to path basename * Refactor path subcommands to support more args This adds a lot of redundancy to non-relevant subcommands such as type, exists or expand. * Add replace and num_levels options to path dirname * Rename num_levels option to num-levels * Remove commented code * Clean up path basename * Fix path dirname description * Add path filestem opts; Rename extension -> suffix * Add prefix option and examples to path filestem * Fix broken num-levels of path dirname * Fix failing example test of path filestem * Fix failing test of path extension * Formatting * Add Windows-specific path subcommand examples `path expand` is still broken but otherwise seems to fix all examples on Windows * Fix weird path expand on Windows Also disable example tests for path expand. Failed caconicalization (e.g., due to path not existing) returns the original path so the examples always fail. * Formatting * Return path datatype when appropriate * Do not append empty remainder to path dirname * Add tests for path subcommands * Formatting * Revisit path subcommand description strings * Apply clippy suggestions; Formatting * Remove problematic test checking '~' expansion Wouldn't run on minimal due to useing optional dependency. The test success was also deending on the presence of home dir on the testing machine which might not be completely robust. * Add missing newline to file
2020-11-24 10:18:38 +01:00
| path basename
"#
));
assert_eq!(actual.out, "");
}
#[test]
fn replaces_basename_of_empty_input() {
let actual = nu!(
cwd: "tests", pipeline(
r#"
echo ""
Path Command Enhancement Project (#2742) * Add string argument support for path subcommands * Add --replace option to 'path extension' command * Add examples of replacing for path extension * Refactor path extension and its example * Add replacement functionality to path basename * Refactor path subcommands to support more args This adds a lot of redundancy to non-relevant subcommands such as type, exists or expand. * Add replace and num_levels options to path dirname * Rename num_levels option to num-levels * Remove commented code * Clean up path basename * Fix path dirname description * Add path filestem opts; Rename extension -> suffix * Add prefix option and examples to path filestem * Fix broken num-levels of path dirname * Fix failing example test of path filestem * Fix failing test of path extension * Formatting * Add Windows-specific path subcommand examples `path expand` is still broken but otherwise seems to fix all examples on Windows * Fix weird path expand on Windows Also disable example tests for path expand. Failed caconicalization (e.g., due to path not existing) returns the original path so the examples always fail. * Formatting * Return path datatype when appropriate * Do not append empty remainder to path dirname * Add tests for path subcommands * Formatting * Revisit path subcommand description strings * Apply clippy suggestions; Formatting * Remove problematic test checking '~' expansion Wouldn't run on minimal due to useing optional dependency. The test success was also deending on the presence of home dir on the testing machine which might not be completely robust. * Add missing newline to file
2020-11-24 10:18:38 +01:00
| path basename -r newname.txt
"#
));
assert_eq!(actual.out, "newname.txt");
}
#[test]
fn returns_basename_of_path_ending_with_dot() {
let actual = nu!(
cwd: "tests", pipeline(
r#"
echo "some/file.txt/."
| path basename
Path Command Enhancement Project (#2742) * Add string argument support for path subcommands * Add --replace option to 'path extension' command * Add examples of replacing for path extension * Refactor path extension and its example * Add replacement functionality to path basename * Refactor path subcommands to support more args This adds a lot of redundancy to non-relevant subcommands such as type, exists or expand. * Add replace and num_levels options to path dirname * Rename num_levels option to num-levels * Remove commented code * Clean up path basename * Fix path dirname description * Add path filestem opts; Rename extension -> suffix * Add prefix option and examples to path filestem * Fix broken num-levels of path dirname * Fix failing example test of path filestem * Fix failing test of path extension * Formatting * Add Windows-specific path subcommand examples `path expand` is still broken but otherwise seems to fix all examples on Windows * Fix weird path expand on Windows Also disable example tests for path expand. Failed caconicalization (e.g., due to path not existing) returns the original path so the examples always fail. * Formatting * Return path datatype when appropriate * Do not append empty remainder to path dirname * Add tests for path subcommands * Formatting * Revisit path subcommand description strings * Apply clippy suggestions; Formatting * Remove problematic test checking '~' expansion Wouldn't run on minimal due to useing optional dependency. The test success was also deending on the presence of home dir on the testing machine which might not be completely robust. * Add missing newline to file
2020-11-24 10:18:38 +01:00
"#
));
assert_eq!(actual.out, "file.txt");
}
#[test]
fn replaces_basename_of_path_ending_with_dot() {
let actual = nu!(
cwd: "tests", pipeline(
r#"
echo "some/file.txt/."
Path Command Enhancement Project (#2742) * Add string argument support for path subcommands * Add --replace option to 'path extension' command * Add examples of replacing for path extension * Refactor path extension and its example * Add replacement functionality to path basename * Refactor path subcommands to support more args This adds a lot of redundancy to non-relevant subcommands such as type, exists or expand. * Add replace and num_levels options to path dirname * Rename num_levels option to num-levels * Remove commented code * Clean up path basename * Fix path dirname description * Add path filestem opts; Rename extension -> suffix * Add prefix option and examples to path filestem * Fix broken num-levels of path dirname * Fix failing example test of path filestem * Fix failing test of path extension * Formatting * Add Windows-specific path subcommand examples `path expand` is still broken but otherwise seems to fix all examples on Windows * Fix weird path expand on Windows Also disable example tests for path expand. Failed caconicalization (e.g., due to path not existing) returns the original path so the examples always fail. * Formatting * Return path datatype when appropriate * Do not append empty remainder to path dirname * Add tests for path subcommands * Formatting * Revisit path subcommand description strings * Apply clippy suggestions; Formatting * Remove problematic test checking '~' expansion Wouldn't run on minimal due to useing optional dependency. The test success was also deending on the presence of home dir on the testing machine which might not be completely robust. * Add missing newline to file
2020-11-24 10:18:38 +01:00
| path basename -r viking.txt
"#
));
let expected = join_path_sep(&["some", "viking.txt"]);
assert_eq!(actual.out, expected);
}
#[test]
fn returns_basename_of_path_ending_with_double_dot() {
let actual = nu!(
cwd: "tests", pipeline(
r#"
echo "some/file.txt/.."
| path basename
Path Command Enhancement Project (#2742) * Add string argument support for path subcommands * Add --replace option to 'path extension' command * Add examples of replacing for path extension * Refactor path extension and its example * Add replacement functionality to path basename * Refactor path subcommands to support more args This adds a lot of redundancy to non-relevant subcommands such as type, exists or expand. * Add replace and num_levels options to path dirname * Rename num_levels option to num-levels * Remove commented code * Clean up path basename * Fix path dirname description * Add path filestem opts; Rename extension -> suffix * Add prefix option and examples to path filestem * Fix broken num-levels of path dirname * Fix failing example test of path filestem * Fix failing test of path extension * Formatting * Add Windows-specific path subcommand examples `path expand` is still broken but otherwise seems to fix all examples on Windows * Fix weird path expand on Windows Also disable example tests for path expand. Failed caconicalization (e.g., due to path not existing) returns the original path so the examples always fail. * Formatting * Return path datatype when appropriate * Do not append empty remainder to path dirname * Add tests for path subcommands * Formatting * Revisit path subcommand description strings * Apply clippy suggestions; Formatting * Remove problematic test checking '~' expansion Wouldn't run on minimal due to useing optional dependency. The test success was also deending on the presence of home dir on the testing machine which might not be completely robust. * Add missing newline to file
2020-11-24 10:18:38 +01:00
"#
));
assert_eq!(actual.out, "");
}
#[test]
fn replaces_basename_of_path_ending_with_double_dot() {
let actual = nu!(
cwd: "tests", pipeline(
r#"
echo "some/file.txt/.."
Path Command Enhancement Project (#2742) * Add string argument support for path subcommands * Add --replace option to 'path extension' command * Add examples of replacing for path extension * Refactor path extension and its example * Add replacement functionality to path basename * Refactor path subcommands to support more args This adds a lot of redundancy to non-relevant subcommands such as type, exists or expand. * Add replace and num_levels options to path dirname * Rename num_levels option to num-levels * Remove commented code * Clean up path basename * Fix path dirname description * Add path filestem opts; Rename extension -> suffix * Add prefix option and examples to path filestem * Fix broken num-levels of path dirname * Fix failing example test of path filestem * Fix failing test of path extension * Formatting * Add Windows-specific path subcommand examples `path expand` is still broken but otherwise seems to fix all examples on Windows * Fix weird path expand on Windows Also disable example tests for path expand. Failed caconicalization (e.g., due to path not existing) returns the original path so the examples always fail. * Formatting * Return path datatype when appropriate * Do not append empty remainder to path dirname * Add tests for path subcommands * Formatting * Revisit path subcommand description strings * Apply clippy suggestions; Formatting * Remove problematic test checking '~' expansion Wouldn't run on minimal due to useing optional dependency. The test success was also deending on the presence of home dir on the testing machine which might not be completely robust. * Add missing newline to file
2020-11-24 10:18:38 +01:00
| path basename -r eggs
"#
));
let expected = join_path_sep(&["some/file.txt/..", "eggs"]);
assert_eq!(actual.out, expected);
}