]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t9902-completion.sh
t2060: add a test for switch with --orphan and --discard-changes
[thirdparty/git.git] / t / t9902-completion.sh
index 93877ba9cd625de373cff3a704b17c9bdf7ed379..5505e5aa249e43b88455b0565f0f9348546d5e4c 100755 (executable)
@@ -1363,6 +1363,63 @@ test_expect_success 'teardown after path completion tests' '
               BS\\dir '$'separators\034in\035dir''
 '
 
+test_expect_success '__git_find_on_cmdline - single match' '
+       echo list >expect &&
+       (
+               words=(git command --opt list) &&
+               cword=${#words[@]} &&
+               __git_find_on_cmdline "add list remove" >actual
+       ) &&
+       test_cmp expect actual
+'
+
+test_expect_success '__git_find_on_cmdline - multiple matches' '
+       echo remove >expect &&
+       (
+               words=(git command -o --opt remove list add) &&
+               cword=${#words[@]} &&
+               __git_find_on_cmdline "add list remove" >actual
+       ) &&
+       test_cmp expect actual
+'
+
+test_expect_success '__git_find_on_cmdline - no match' '
+       (
+               words=(git command --opt branch) &&
+               cword=${#words[@]} &&
+               __git_find_on_cmdline "add list remove" >actual
+       ) &&
+       test_must_be_empty actual
+'
+
+test_expect_success '__git_find_on_cmdline - single match with index' '
+       echo "3 list" >expect &&
+       (
+               words=(git command --opt list) &&
+               cword=${#words[@]} &&
+               __git_find_on_cmdline --show-idx "add list remove" >actual
+       ) &&
+       test_cmp expect actual
+'
+
+test_expect_success '__git_find_on_cmdline - multiple matches with index' '
+       echo "4 remove" >expect &&
+       (
+               words=(git command -o --opt remove list add) &&
+               cword=${#words[@]} &&
+               __git_find_on_cmdline --show-idx "add list remove" >actual
+       ) &&
+       test_cmp expect actual
+'
+
+test_expect_success '__git_find_on_cmdline - no match with index' '
+       (
+               words=(git command --opt branch) &&
+               cword=${#words[@]} &&
+               __git_find_on_cmdline --show-idx "add list remove" >actual
+       ) &&
+       test_must_be_empty actual
+'
 
 test_expect_success '__git_get_config_variables' '
        cat >expect <<-EOF &&