tests: add tests for the __gitcomp() completion helper function

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>

SZEDER Gábor committed Apr 17, 2012 at 12:27 UTC 74a8c849f1257dde0c42feac95ba517bae625647
1 file changed +85
t/t9902-completion.sh
+85
@@ -73,6 +73,91 @@ test_completion ()
73 test_cmp expected out
74 }
75
76 +newline=$'\n'
77 +
78 +test_expect_success '__gitcomp - trailing space - options' '
79 + sed -e "s/Z$//" >expected <<-\EOF &&
80 + --reuse-message=Z
81 + --reedit-message=Z
82 + --reset-author Z
83 + EOF
84 + (
85 + local -a COMPREPLY &&
86 + cur="--re" &&
87 + __gitcomp "--dry-run --reuse-message= --reedit-message=
88 + --reset-author" &&
89 + IFS="$newline" &&
90 + echo "${COMPREPLY[*]}" > out
91 + ) &&
92 + test_cmp expected out
93 +'
94 +
95 +test_expect_success '__gitcomp - trailing space - config keys' '
96 + sed -e "s/Z$//" >expected <<-\EOF &&
97 + branch.Z
98 + branch.autosetupmerge Z
99 + branch.autosetuprebase Z
100 + browser.Z
101 + EOF
102 + (
103 + local -a COMPREPLY &&
104 + cur="br" &&
105 + __gitcomp "branch. branch.autosetupmerge
106 + branch.autosetuprebase browser." &&
107 + IFS="$newline" &&
108 + echo "${COMPREPLY[*]}" > out
109 + ) &&
110 + test_cmp expected out
111 +'
112 +
113 +test_expect_success '__gitcomp - option parameter' '
114 + sed -e "s/Z$//" >expected <<-\EOF &&
115 + recursive Z
116 + resolve Z
117 + EOF
118 + (
119 + local -a COMPREPLY &&
120 + cur="--strategy=re" &&
121 + __gitcomp "octopus ours recursive resolve subtree
122 + " "" "re" &&
123 + IFS="$newline" &&
124 + echo "${COMPREPLY[*]}" > out
125 + ) &&
126 + test_cmp expected out
127 +'
128 +
129 +test_expect_success '__gitcomp - prefix' '
130 + sed -e "s/Z$//" >expected <<-\EOF &&
131 + branch.maint.merge Z
132 + branch.maint.mergeoptions Z
133 + EOF
134 + (
135 + local -a COMPREPLY &&
136 + cur="branch.me" &&
137 + __gitcomp "remote merge mergeoptions rebase
138 + " "branch.maint." "me" &&
139 + IFS="$newline" &&
140 + echo "${COMPREPLY[*]}" > out
141 + ) &&
142 + test_cmp expected out
143 +'
144 +
145 +test_expect_success '__gitcomp - suffix' '
146 + sed -e "s/Z$//" >expected <<-\EOF &&
147 + branch.master.Z
148 + branch.maint.Z
149 + EOF
150 + (
151 + local -a COMPREPLY &&
152 + cur="branch.me" &&
153 + __gitcomp "master maint next pu
154 + " "branch." "ma" "." &&
155 + IFS="$newline" &&
156 + echo "${COMPREPLY[*]}" > out
157 + ) &&
158 + test_cmp expected out
159 +'
160 +
161 test_expect_success 'basic' '
162 run_completion "git \"\"" &&
163 # built-in