/
general.rs
40 lines (33 loc) · 1.17 KB
/
general.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#[test]
fn infer_value_hint_for_path_buf() {
let mut cmd = clap::Command::new("completer")
.arg(clap::Arg::new("input").value_parser(clap::value_parser!(std::path::PathBuf)));
cmd.build();
let input = cmd
.get_arguments()
.find(|arg| arg.get_id() == "input")
.unwrap();
assert_eq!(input.get_value_hint(), clap::builder::ValueHint::AnyPath);
}
#[cfg(windows)]
#[test]
fn shell_absolute_path() {
use clap_complete::Shell;
let path = std::path::Path::new(&std::env::var("PSHOME").unwrap()).join("powershell.exe");
let matches = clap::Command::new("test")
.arg(clap::Arg::new("shell").value_parser(clap::value_parser!(Shell)))
.get_matches_from(["myprog", path.to_str().unwrap()]);
assert_eq!(
matches.get_one::<Shell>("shell").unwrap(),
&Shell::PowerShell
);
}
#[cfg(not(windows))]
#[test]
fn shell_absolute_path() {
use clap_complete::Shell;
let matches = clap::Command::new("test")
.arg(clap::Arg::new("shell").value_parser(clap::value_parser!(Shell)))
.get_matches_from(["myprog", "/bin/bash"]);
assert_eq!(matches.get_one::<Shell>("shell").unwrap(), &Shell::Bash);
}