clap/clap_complete/tests/bash.rs
David Aguilar 170bd59111 fix(complete): Handle multi-valued arguments
zsh completions for commands that have multiple Vec arguments require
special care.

We can have two Vec args separated with a value terminator.
We can also have two Vec args with no value terminators specified
where the final arg uses 'raw' and thus requires '--' to be used.

The 2nd of these scenarios requires special handling to avoid
emitting a duplicate '*:arguments' completion entry.

Currently, the zsh completions generate an error in this scenario:

    $ my-app <TAB>
    _arguments:...: doubled rest argument definition:
    *::second -- second set of of multi-length arguments:

We already use the '-S' option when calling _arguments.
This option makes it so that completion stops after '--' is encountered.
This means that the handling for trailing 'raw' arguments does not need
to specified.

Special-case multi-valued arguments so that we can skip emitting
the final multi-valued argument if a previous multi-valued argument
has already been emitted.

Closes #3022
Signed-off-by: David Aguilar <davvid@gmail.com>
2023-01-10 14:39:33 -08:00

125 lines
2.8 KiB
Rust

mod common;
#[test]
fn basic() {
let name = "my-app";
let cmd = common::basic_command(name);
common::assert_matches_path(
"tests/snapshots/basic.bash",
clap_complete::shells::Bash,
cmd,
name,
);
}
#[test]
fn feature_sample() {
let name = "my-app";
let cmd = common::feature_sample_command(name);
common::assert_matches_path(
"tests/snapshots/feature_sample.bash",
clap_complete::shells::Bash,
cmd,
name,
);
}
#[test]
fn special_commands() {
let name = "my-app";
let cmd = common::special_commands_command(name);
common::assert_matches_path(
"tests/snapshots/special_commands.bash",
clap_complete::shells::Bash,
cmd,
name,
);
}
#[test]
fn quoting() {
let name = "my-app";
let cmd = common::quoting_command(name);
common::assert_matches_path(
"tests/snapshots/quoting.bash",
clap_complete::shells::Bash,
cmd,
name,
);
}
#[test]
fn aliases() {
let name = "my-app";
let cmd = common::aliases_command(name);
common::assert_matches_path(
"tests/snapshots/aliases.bash",
clap_complete::shells::Bash,
cmd,
name,
);
}
#[test]
fn sub_subcommands() {
let name = "my-app";
let cmd = common::sub_subcommands_command(name);
common::assert_matches_path(
"tests/snapshots/sub_subcommands.bash",
clap_complete::shells::Bash,
cmd,
name,
);
}
#[test]
fn value_hint() {
let name = "my-app";
let cmd = common::value_hint_command(name);
common::assert_matches_path(
"tests/snapshots/value_hint.bash",
clap_complete::shells::Bash,
cmd,
name,
);
}
#[test]
fn value_terminator() {
let name = "my-app";
let cmd = common::value_terminator_command(name);
common::assert_matches_path(
"tests/snapshots/value_terminator.bash",
clap_complete::shells::Bash,
cmd,
name,
);
}
#[cfg(feature = "unstable-dynamic")]
#[test]
fn register_minimal() {
let name = "my-app";
let executables = [name];
let completer = name;
let behavior = clap_complete::dynamic::bash::Behavior::Minimal;
let mut buf = Vec::new();
clap_complete::dynamic::bash::register(name, executables, completer, &behavior, &mut buf)
.unwrap();
snapbox::Assert::new()
.action_env("SNAPSHOTS")
.matches_path("tests/snapshots/register_minimal.bash", buf);
}
#[test]
fn two_multi_valued_arguments() {
let name = "my-app";
let cmd = common::two_multi_valued_arguments_command(name);
common::assert_matches_path(
"tests/snapshots/two_multi_valued_arguments.bash",
clap_complete::shells::Bash,
cmd,
name,
);
}