completion: add __gitcomp_nl tests
Original patch by SZEDER Gábor. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
Apr 10, 2013 at 01:57 UTC
43369a22588373b987d427a937b761bb04817e4d
1 file changed
+60
t/t9902-completion.sh
+60
@@ -105,6 +105,23 @@ test_gitcomp ()
105
test_cmp expected out
106
}
107
108
+# Test __gitcomp_nl
109
+# Arguments are:
110
+# 1: current word (cur)
111
+# -: the rest are passed to __gitcomp_nl
112
+test_gitcomp_nl ()
113
+{
114
+ local -a COMPREPLY &&
115
+ sed -e 's/Z$//' >expected &&
116
+ cur="$1" &&
117
+ shift &&
118
+ __gitcomp_nl "$@" &&
119
+ print_comp &&
120
+ test_cmp expected out
121
+}
122
+
123
+invalid_variable_name='${foo.bar}'
124
+
125
test_expect_success '__gitcomp - trailing space - options' '
126
test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
127
--reset-author" <<-EOF
@@ -148,6 +165,49 @@ test_expect_success '__gitcomp - suffix' '
165
EOF
166
'
167
168
+test_expect_failure '__gitcomp - doesnt fail because of invalid variable name' '
169
+ __gitcomp "$invalid_variable_name"
170
+'
171
+
172
+read -r -d "" refs <<-\EOF
173
+maint
174
+master
175
+next
176
+pu
177
+EOF
178
+
179
+test_expect_success '__gitcomp_nl - trailing space' '
180
+ test_gitcomp_nl "m" "$refs" <<-EOF
181
+ maint Z
182
+ master Z
183
+ EOF
184
+'
185
+
186
+test_expect_success '__gitcomp_nl - prefix' '
187
+ test_gitcomp_nl "--fixup=m" "$refs" "--fixup=" "m" <<-EOF
188
+ --fixup=maint Z
189
+ --fixup=master Z
190
+ EOF
191
+'
192
+
193
+test_expect_success '__gitcomp_nl - suffix' '
194
+ test_gitcomp_nl "branch.ma" "$refs" "branch." "ma" "." <<-\EOF
195
+ branch.maint.Z
196
+ branch.master.Z
197
+ EOF
198
+'
199
+
200
+test_expect_success '__gitcomp_nl - no suffix' '
201
+ test_gitcomp_nl "ma" "$refs" "" "ma" "" <<-\EOF
202
+ maintZ
203
+ masterZ
204
+ EOF
205
+'
206
+
207
+test_expect_failure '__gitcomp_nl - doesnt fail because of invalid variable name' '
208
+ __gitcomp_nl "$invalid_variable_name"
209
+'
210
+
211
test_expect_success 'basic' '
212
run_completion "git " &&
213
# built-in