Skip to content

Commit 43369a2

Browse files
felipecgitster
authored andcommitted
completion: add __gitcomp_nl tests
Original patch by SZEDER Gábor. Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1ce23aa commit 43369a2

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

t/t9902-completion.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,23 @@ test_gitcomp ()
105105
test_cmp expected out
106106
}
107107

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+
108125
test_expect_success '__gitcomp - trailing space - options' '
109126
test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
110127
--reset-author" <<-EOF
@@ -148,6 +165,49 @@ test_expect_success '__gitcomp - suffix' '
148165
EOF
149166
'
150167

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+
151211
test_expect_success 'basic' '
152212
run_completion "git " &&
153213
# built-in

0 commit comments

Comments
 (0)