]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t9902-completion: add tests for the __git_find_on_cmdline() helper
authorSZEDER Gábor <szeder.dev@gmail.com>
Thu, 19 Dec 2019 15:09:16 +0000 (16:09 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 15 Jan 2020 22:06:12 +0000 (14:06 -0800)
The following two patches will refactor and extend the
__git_find_on_cmdline() helper function, so let's add a few tests
first to make sure that its basic behavior doesn't change.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t9902-completion.sh

index ec3eccfd3d67c67dab10859918af960c5e452a38..a1762f9d58d18205d5840dec07f877a0e5fc0dbc 100755 (executable)
@@ -1363,6 +1363,34 @@ 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_get_config_variables' '
        cat >expect <<-EOF &&