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

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