Skip to content

Commit eded64a

Browse files
committed
test(complete): Verify PathCompleter::dir
1 parent 03d7226 commit eded64a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

clap_complete/tests/testsuite/engine.rs

+34
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,40 @@ d_dir/
616616
);
617617
}
618618

619+
#[test]
620+
fn suggest_value_path_dir() {
621+
let testdir = snapbox::dir::DirRoot::mutable_temp().unwrap();
622+
let testdir_path = testdir.path().unwrap();
623+
fs::write(testdir_path.join("a_file"), "").unwrap();
624+
fs::write(testdir_path.join("b_file"), "").unwrap();
625+
fs::create_dir_all(testdir_path.join("c_dir")).unwrap();
626+
fs::create_dir_all(testdir_path.join("d_dir")).unwrap();
627+
628+
let mut cmd = Command::new("dynamic")
629+
.arg(
630+
clap::Arg::new("input")
631+
.long("input")
632+
.short('i')
633+
.add(ArgValueCompleter::new(
634+
PathCompleter::dir().current_dir(testdir_path.to_owned()),
635+
)),
636+
)
637+
.args_conflicts_with_subcommands(true);
638+
639+
assert_data_eq!(
640+
complete!(cmd, "--input [TAB]", current_dir = Some(testdir_path)),
641+
snapbox::str![[r#"
642+
c_dir/
643+
d_dir/
644+
"#]],
645+
);
646+
647+
assert_data_eq!(
648+
complete!(cmd, "--input c[TAB]", current_dir = Some(testdir_path)),
649+
snapbox::str!["c_dir/"],
650+
);
651+
}
652+
619653
#[test]
620654
fn suggest_custom_arg_value() {
621655
fn custom_completer() -> Vec<CompletionCandidate> {

0 commit comments

Comments
 (0)