From c3e5d16183f01540739e813de3ac73a4393c93a7 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 4 Sep 2024 09:32:21 -0500 Subject: [PATCH] test(complete): Verify prefix completions --- clap_complete/tests/testsuite/bash.rs | 22 ++++++++++++++++++ clap_complete/tests/testsuite/elvish.rs | 30 +++++++++++++++++++++++++ clap_complete/tests/testsuite/fish.rs | 25 +++++++++++++++++++++ clap_complete/tests/testsuite/zsh.rs | 25 +++++++++++++++++++++ 4 files changed, 102 insertions(+) diff --git a/clap_complete/tests/testsuite/bash.rs b/clap_complete/tests/testsuite/bash.rs index 2baec1a0..e0019d86 100644 --- a/clap_complete/tests/testsuite/bash.rs +++ b/clap_complete/tests/testsuite/bash.rs @@ -281,3 +281,25 @@ fn complete_dynamic_env_quoted_help() { let actual = runtime.complete(input, &term).unwrap(); assert_data_eq!(actual, expected); } + +#[test] +#[cfg(all(unix, feature = "unstable-dynamic"))] +fn complete_dynamic_env_option_value() { + if !common::has_command("bash") { + return; + } + + let term = completest::Term::new(); + let mut runtime = + common::load_runtime::("dynamic-env", "exhaustive"); + + let input = "exhaustive action --choice=\t\t"; + let expected = snapbox::str!["% "]; + let actual = runtime.complete(input, &term).unwrap(); + assert_data_eq!(actual, expected); + + let input = "exhaustive action --choice=f\t"; + let expected = snapbox::str!["exhaustive action --choice=f % exhaustive action --choice=f"]; + let actual = runtime.complete(input, &term).unwrap(); + assert_data_eq!(actual, expected); +} diff --git a/clap_complete/tests/testsuite/elvish.rs b/clap_complete/tests/testsuite/elvish.rs index 564a3963..9821f264 100644 --- a/clap_complete/tests/testsuite/elvish.rs +++ b/clap_complete/tests/testsuite/elvish.rs @@ -225,3 +225,33 @@ fn complete_dynamic_env_quoted_help() { let actual = runtime.complete(input, &term).unwrap(); assert_data_eq!(actual, expected); } + +#[test] +#[cfg(all(unix, feature = "unstable-dynamic"))] +fn complete_dynamic_env_option_value() { + if !common::has_command("elvish") { + return; + } + + let term = completest::Term::new(); + let mut runtime = + common::load_runtime::("dynamic-env", "exhaustive"); + + let input = "exhaustive action --choice=\t"; + let expected = snapbox::str![[r#" +% exhaustive action '--choice=first' + COMPLETING argument +--choice=first --choice=second +"#]]; + let actual = runtime.complete(input, &term).unwrap(); + assert_data_eq!(actual, expected); + + let input = "exhaustive action --choice=f\t"; + let expected = snapbox::str![[r#" +% exhaustive action '--choice=first' + COMPLETING argument +--choice=first +"#]]; + let actual = runtime.complete(input, &term).unwrap(); + assert_data_eq!(actual, expected); +} diff --git a/clap_complete/tests/testsuite/fish.rs b/clap_complete/tests/testsuite/fish.rs index 4ea55e10..451b57fa 100644 --- a/clap_complete/tests/testsuite/fish.rs +++ b/clap_complete/tests/testsuite/fish.rs @@ -237,3 +237,28 @@ help (Print this message or the help of the given subcommand(s)) let actual = runtime.complete(input, &term).unwrap(); assert_data_eq!(actual, expected); } + +#[test] +#[cfg(all(unix, feature = "unstable-dynamic"))] +fn complete_dynamic_env_option_value() { + if !common::has_command("fish") { + return; + } + + let term = completest::Term::new(); + let mut runtime = + common::load_runtime::("dynamic-env", "exhaustive"); + + let input = "exhaustive action --choice=\t\t"; + let expected = snapbox::str![[r#" +% exhaustive action --choice=first +--choice=first --choice=second +"#]]; + let actual = runtime.complete(input, &term).unwrap(); + assert_data_eq!(actual, expected); + + let input = "exhaustive action --choice=f\t"; + let expected = snapbox::str!["% exhaustive action --choice=first "]; + let actual = runtime.complete(input, &term).unwrap(); + assert_data_eq!(actual, expected); +} diff --git a/clap_complete/tests/testsuite/zsh.rs b/clap_complete/tests/testsuite/zsh.rs index 43273ffe..1d0e507c 100644 --- a/clap_complete/tests/testsuite/zsh.rs +++ b/clap_complete/tests/testsuite/zsh.rs @@ -211,3 +211,28 @@ fn complete_dynamic_env_quoted_help() { let actual = runtime.complete(input, &term).unwrap(); assert_data_eq!(actual, expected); } + +#[test] +#[cfg(all(unix, feature = "unstable-dynamic"))] +fn complete_dynamic_env_option_value() { + if !common::has_command("zsh") { + return; + } + + let term = completest::Term::new(); + let mut runtime = + common::load_runtime::("dynamic-env", "exhaustive"); + + let input = "exhaustive action --choice=\t\t"; + let expected = snapbox::str![[r#" +% exhaustive action --choice= +--choice=first --choice=second +"#]]; + let actual = runtime.complete(input, &term).unwrap(); + assert_data_eq!(actual, expected); + + let input = "exhaustive action --choice=f\t\t"; + let expected = snapbox::str!["% exhaustive action --choice=first "]; + let actual = runtime.complete(input, &term).unwrap(); + assert_data_eq!(actual, expected); +}