tests: add tests for the __gitcomp() completion helper function
authorSZEDER Gábor <szeder@ira.uka.de>
Tue, 17 Apr 2012 10:27:15 +0000 (12:27 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sun, 22 Apr 2012 05:39:06 +0000 (22:39 -0700)
These tests check that trailing space, prefix, and suffix are added
correctly.

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

index a6eaa15c1cf558c616e3ce9c5f97a9c438c26f5e..de1c3e91d315ba135bbc3b7a9f8fc87e3a43271d 100755 (executable)
@@ -73,6 +73,91 @@ test_completion ()
        test_cmp expected out
 }
 
+newline=$'\n'
+
+test_expect_success '__gitcomp - trailing space - options' '
+       sed -e "s/Z$//" >expected <<-\EOF &&
+       --reuse-message=Z
+       --reedit-message=Z
+       --reset-author Z
+       EOF
+       (
+               local -a COMPREPLY &&
+               cur="--re" &&
+               __gitcomp "--dry-run --reuse-message= --reedit-message=
+                               --reset-author" &&
+               IFS="$newline" &&
+               echo "${COMPREPLY[*]}" > out
+       ) &&
+       test_cmp expected out
+'
+
+test_expect_success '__gitcomp - trailing space - config keys' '
+       sed -e "s/Z$//" >expected <<-\EOF &&
+       branch.Z
+       branch.autosetupmerge Z
+       branch.autosetuprebase Z
+       browser.Z
+       EOF
+       (
+               local -a COMPREPLY &&
+               cur="br" &&
+               __gitcomp "branch. branch.autosetupmerge
+                               branch.autosetuprebase browser." &&
+               IFS="$newline" &&
+               echo "${COMPREPLY[*]}" > out
+       ) &&
+       test_cmp expected out
+'
+
+test_expect_success '__gitcomp - option parameter' '
+       sed -e "s/Z$//" >expected <<-\EOF &&
+       recursive Z
+       resolve Z
+       EOF
+       (
+               local -a COMPREPLY &&
+               cur="--strategy=re" &&
+               __gitcomp "octopus ours recursive resolve subtree
+                       " "" "re" &&
+               IFS="$newline" &&
+               echo "${COMPREPLY[*]}" > out
+       ) &&
+       test_cmp expected out
+'
+
+test_expect_success '__gitcomp - prefix' '
+       sed -e "s/Z$//" >expected <<-\EOF &&
+       branch.maint.merge Z
+       branch.maint.mergeoptions Z
+       EOF
+       (
+               local -a COMPREPLY &&
+               cur="branch.me" &&
+               __gitcomp "remote merge mergeoptions rebase
+                       " "branch.maint." "me" &&
+               IFS="$newline" &&
+               echo "${COMPREPLY[*]}" > out
+       ) &&
+       test_cmp expected out
+'
+
+test_expect_success '__gitcomp - suffix' '
+       sed -e "s/Z$//" >expected <<-\EOF &&
+       branch.master.Z
+       branch.maint.Z
+       EOF
+       (
+               local -a COMPREPLY &&
+               cur="branch.me" &&
+               __gitcomp "master maint next pu
+                       " "branch." "ma" "." &&
+               IFS="$newline" &&
+               echo "${COMPREPLY[*]}" > out
+       ) &&
+       test_cmp expected out
+'
+
 test_expect_success 'basic' '
        run_completion "git \"\"" &&
        # built-in