making ls and du supports rest parameters. (#12327)

# Description
Close: #12147
Close: #11796 

About the change: it make pattern handling into a function:
`ls_for_one_pattern`(for ls), `du_for_one_pattern`(for du). Then
iterates on user input pattern, call these core function, and chaining
these iterator to one pipelinedata.
This commit is contained in:
Wind
2024-04-13 23:03:17 +08:00
committed by GitHub
parent 56cdee1fd8
commit 0110345755
5 changed files with 462 additions and 332 deletions

View File

@ -50,7 +50,7 @@ fn test_du_flag_max_depth() {
#[case("a[bc]d")]
#[case("a][c")]
fn du_files_with_glob_metachars(#[case] src_name: &str) {
Playground::setup("umv_test_16", |dirs, sandbox| {
Playground::setup("du_test_16", |dirs, sandbox| {
sandbox.with_files(vec![EmptyFile(src_name)]);
let src = dirs.test().join(src_name);
@ -82,3 +82,21 @@ fn du_files_with_glob_metachars(#[case] src_name: &str) {
fn du_files_with_glob_metachars_nw(#[case] src_name: &str) {
du_files_with_glob_metachars(src_name);
}
#[test]
fn du_with_multiple_path() {
let actual = nu!(cwd: "tests/fixtures", "du cp formats | get path | path basename");
assert!(actual.out.contains("cp"));
assert!(actual.out.contains("formats"));
assert!(!actual.out.contains("lsp"));
assert!(actual.status.success());
// report errors if one path not exists
let actual = nu!(cwd: "tests/fixtures", "du cp asdf | get path | path basename");
assert!(actual.err.contains("directory not found"));
assert!(!actual.status.success());
// du with spreading empty list should returns nothing.
let actual = nu!(cwd: "tests/fixtures", "du ...[] | length");
assert_eq!(actual.out, "0");
}

View File

@ -733,3 +733,29 @@ fn list_with_tilde() {
assert!(actual.out.contains("~tilde"));
})
}
#[test]
fn list_with_multiple_path() {
Playground::setup("ls_multiple_path", |dirs, sandbox| {
sandbox.with_files(vec![
EmptyFile("f1.txt"),
EmptyFile("f2.txt"),
EmptyFile("f3.txt"),
]);
let actual = nu!(cwd: dirs.test(), "ls f1.txt f2.txt");
assert!(actual.out.contains("f1.txt"));
assert!(actual.out.contains("f2.txt"));
assert!(!actual.out.contains("f3.txt"));
assert!(actual.status.success());
// report errors if one path not exists
let actual = nu!(cwd: dirs.test(), "ls asdf f1.txt");
assert!(actual.err.contains("directory not found"));
assert!(!actual.status.success());
// ls with spreading empty list should returns nothing.
let actual = nu!(cwd: dirs.test(), "ls ...[] | length");
assert_eq!(actual.out, "0");
})
}