OILS / spec / ysh-completion.test.sh View on Github | oilshell.org

204 lines, 61 significant
1## oils_failures_allowed: 6
2
3#### compexport
4
5compexport -c 'hay'
6
7## STDOUT:
8"haynode "
9"hay "
10## END
11
12#### compexport with multi-line commands
13
14# TODO: Why do we get 3 copies of echo?
15# compexport -c $'for x in y; do\nec'
16
17compexport -c $'for x in y; do\ncompl'
18
19
20## STDOUT:
21"complete "
22## END
23
24#### redirect completions are quoted
25
26touch "can't touch this"
27
28compexport -c 'echo hi > c'
29## STDOUT:
30"echo hi > can\\'t\\ touch\\ this"
31## END
32
33#### dir completions have trailing slash
34
35mkdir -p "can't touch this"
36compexport -c 'cd ca'
37
38## STDOUT:
39"cd can\\'t\\ touch\\ this/"
40## END
41
42
43#### complete -F strings are not quoted again
44
45. $REPO_ROOT/testdata/completion/quoting.bash
46
47compexport -c 'pq-argv c'
48echo
49
50# note: excluding "can't" because there's an intentional bug
51compexport -c 'sq-argv ch'
52
53# Quoting doesn't match bash exactly, but it definitely works interactively!
54
55## STDOUT:
56"pq-argv $'can\\'t' "
57"pq-argv 'ch with space' "
58"pq-argv checkout "
59"pq-argv cherry "
60
61"sq-argv 'ch with space' "
62"sq-argv 'checkout' "
63"sq-argv 'cherry' "
64## END
65
66#### complete -W quoting
67
68. $REPO_ROOT/testdata/completion/quoting.bash
69
70compexport -c 'q2-argv c'
71echo
72
73## STDOUT:
74"q2-argv can\\'t "
75"q2-argv checkout "
76"q2-argv cherry "
77## END
78
79#### filenames are completed
80
81touch foo bar baz
82
83compexport -c $'echo ba'
84
85
86## STDOUT:
87
88TODO: Is the order reversed? I guess this is file system order, which is
89nondeterministic. YSH can sort them
90
91echo baz
92echo bar
93## END
94
95#### complete both -W and -F: words and functions
96
97__git() {
98 COMPREPLY=(corn dill)
99}
100complete -W 'ale $(echo bean)' -F __git GIT
101
102compexport -c 'GIT '
103
104## STDOUT:
105Hm they are kinda reversed, I want to fix that. This is true even in Python
106though, weird.
107## END
108
109
110#### -o default is an "else action", when zero are shown
111
112touch file1 file2
113
114echo '-- nothing registered'
115compexport -c 'GIT '
116
117__git() {
118 #argv.py "$@"
119 COMPREPLY=(foo bar)
120}
121
122complete -F __git GIT
123
124echo '-- func'
125compexport -c 'GIT '
126
127complete -F __git -o default GIT
128echo '-- func default'
129compexport -c 'GIT '
130
131__git() {
132 # don't show anything
133 true
134}
135
136# have to RE-REGISTER after defining function! Hm
137complete -F __git -o default GIT
138
139echo '-- empty func default'
140compexport -c 'GIT '
141
142# Is the order reversed?
143# Does GNU readline always sort them?
144
145## STDOUT:
146TODO
147git
148## END
149
150# TODO:
151# --begin --end
152# --table ? For mulitiple completions
153# compatible with -C ?
154# --trace - show debug_f tracing on stderr? Would be very nice!
155
156#### git completion space issue (disabled for old git, e.g. v2.17.1)
157
158# Hack for lenny: version detection for 2.17.1 on Ubuntu 18.02
159if ! git --list-cmds=list-complete >/dev/null; then
160 cat <<'EOF'
161status=0
162"git cherry "
163"git cherry-pick "
164"git checkout "
165EOF
166 return
167fi
168
169. $REPO_ROOT/testdata/completion/git-completion.bash
170echo status=$?
171
172#complete
173
174# Bug: it has an extra \ on it
175compexport -c 'git ch'
176
177## status: 0
178## STDOUT:
179status=0
180"git cherry "
181"git cherry-pick "
182"git checkout "
183## END
184
185#### Complete Filenames with bad characters
186
187touch hello
188touch $'hi\xffthere'
189
190compexport -c 'echo h'
191## STDOUT:
192TODO
193## END
194
195#### Complete Command with bad characters
196
197touch foo fooz
198
199compexport -c $'echo "bad \xff byte" f'
200
201## STDOUT:
202TODO
203## END
204