Skip to content

Commit 74a8c84

Browse files
szedergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5c293a6 commit 74a8c84

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

t/t9902-completion.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,91 @@ test_completion ()
7373
test_cmp expected out
7474
}
7575

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+
76161
test_expect_success 'basic' '
77162
run_completion "git \"\"" &&
78163
# built-in

0 commit comments

Comments
 (0)