Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions clap_complete/tests/testsuite/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,3 +1191,40 @@ fn complete(cmd: &mut Command, args: impl AsRef<str>, current_dir: Option<&Path>
.collect::<Vec<_>>()
.join("\n")
}

#[test]
fn suggest_value_path_with_filter_and_mapper() {
Comment on lines +1195 to +1196
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention of the split commits was for this test to overwrite the suggest_value_path_without_mapper, showing the change in behavior. Only the call to map and output should change in this commit.

Copy link
Author

@Gmin2 Gmin2 Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in this and added an additional test mentioned here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All test additions should be done in the first commit

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So @epage, i should do that same as i did for suggest_value_path_with_mapper (in the first commit showing the behaviour without mapper and then showing the behaviour with mapper right ?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

let testdir = snapbox::dir::DirRoot::mutable_temp().unwrap();
let testdir_path = testdir.path().unwrap();
fs::write(testdir_path.join("a_file"), "").unwrap();
fs::write(testdir_path.join("b_file"), "").unwrap();
fs::create_dir_all(testdir_path.join("c_dir")).unwrap();
fs::create_dir_all(testdir_path.join("d_dir")).unwrap();

fs::write(testdir_path.join("c_dir").join("Cargo.toml"), "").unwrap();

let mut cmd = Command::new("dynamic")
.arg(
clap::Arg::new("input")
.long("input")
.short('i')
.add(ArgValueCompleter::new(
PathCompleter::dir()
.current_dir(testdir_path.to_owned())
.filter(|path| {
path.file_name()
.and_then(|n| n.to_str())
.map_or(false, |name| name.starts_with('c'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you ran clippy on this, it would complain about the use of map_or. CI isn't catching it because we aren't running it on unstable features from non-default packages.

})
)),
)
.args_conflicts_with_subcommands(true);

assert_data_eq!(
complete!(cmd, "--input [TAB]", current_dir = Some(testdir_path)),
snapbox::str![[r#"
c_dir/
d_dir/
"#]],
);
}