summaryrefslogtreecommitdiff
path: root/.config/shells/zsh/plugins/fzf-tab/test/fzftab.ztst
blob: 98028f3a81688229b312d3cc5e2d0a9a3117e4f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# Tests for fzf tab.

%prep
  unset -m LC_\*
  ZSH_TEST_LANG=
  langs=(en_{US,GB}.{UTF-,utf}8 en.UTF-8
         $(locale -a 2>/dev/null | egrep 'utf8|UTF-8'))
  for LANG in $langs; do
    if [[ é = ? ]]; then
      ZSH_TEST_LANG=$LANG
      break;
    fi
  done
  if [[ $OSTYPE = cygwin ]]; then
    ZTST_unimplemented="the zsh/zpty module does not work on Cygwin"
  elif ( zmodload zsh/zpty 2>/dev/null ); then
    . $ZTST_srcdir/comptest
    mkdir comp.tmp
    cd comp.tmp
    comptestinit -z zsh &&
    {
      comptesteval 'compdef _tst tst'
      mkdir dir1 &&
      mkdir dir2 &&
      touch file1 &&
      touch file2
      touch dir1/file1
      git init
    }
  else
    ZTST_unimplemented="the zsh/zpty module is not available"
  fi

  comptesteval ". $ZTST_srcdir/../fzf-tab.zsh"
  comptesteval "zstyle ':fzf-tab:*' debug-command $ZTST_srcdir/select -n 1 -h '\$#_ftb_headers' -q '\"\$_ftb_query\"'"
  comptesteval '
  zstyle ":fzf-tab:*" default-color "<LC><C0><RC>"
  zstyle ":fzf-tab:*" single-group color header
  zstyle ":fzf-tab:*" group-colors "<LC><C1><RC>" "<LC><C2><RC>" "<LC><C3><RC>" "<LC><C4><RC>"
  fzf-tab-complete-with-report() {
    print -lr "<WIDGET><fzf-tab-complete>"
    zle fzf-tab-complete 2>&1
    print -lr - "<LBUFFER>$LBUFFER</LBUFFER>" "<RBUFFER>$RBUFFER</RBUFFER>"
    zle clear-screen
    zle -R
  }
  zle -N fzf-tab-complete-with-report
  bindkey "^I" fzf-tab-complete-with-report
  '

%test

  comptest $': \t'
0:directories and files
>line: {: dir1/}{}
>QUERY:{}
>DESCRIPTION:{file}
>C1:{dir1/}
>C1:{dir2/}
>C1:{file1}
>C1:{file2}

  comptest $': d\t'
0:prefix
>line: {: dir1/}{}
>QUERY:{dir}
>DESCRIPTION:{file}
>C1:{dir1/}
>C1:{dir2/}

  comptesteval '_tst () { compadd d c b a }'
  comptest $'tst \t'
0:normal
>line: {tst a }{}
>QUERY:{}
>C0:{a}
>C0:{b}
>C0:{c}
>C0:{d}

  comptesteval 'zstyle ":completion:*:tst:*" sort false'
  comptest $'tst \t'
0:no sort
>line: {tst d }{}
>QUERY:{}
>C0:{d}
>C0:{c}
>C0:{b}
>C0:{a}

  comptesteval 'zstyle ":fzf-tab:*:tst:*" fzf-flags -n 1,2'
  comptest $'tst \t'
  comptesteval 'zstyle -d ":fzf-tab:*:tst:*" fzf-flags'
0:multi select
>line: {tst c d }{}
>QUERY:{}
>C0:{d}
>C0:{c}
>C0:{b}
>C0:{a}

  comptest $': *\t'
0:expand
>line: {: dir1 dir2 file1 file2 }{}

  comptesteval 'zstyle ":completion:*:warnings" format "<WARN>%d</WARN>"'
  comptest $': asd\t'
0:warnings
>line: {: asd}{}
>WARN:{`file'}
>WARN:{`file'}
# FIXME:why two warnings?

  comptesteval "touch 'abc def'"
  comptest $': ./a\t'
0:filename with space
>line: {: ./abc\ def }{}

  comptest $': ./abdef\C-b\C-b\C-b\t'
0:complete in word
>line: {: ./abc\ def }{}

  comptest $': ./abc def\C-b\C-b\C-b\C-b\t'
  comptesteval "rm 'abc def'"
0:complete in word(with known bug)
>line: {: ./abc\ def}{ def}

  comptesteval 'mkdir -p abc/def/hij abc/dfe/hij'
  comptest $': ./a/d/h\t'
  comptesteval 'rm -rd abc'
0:nested directory
>line: {: ./abc/def/h}{}
>QUERY:{d}
>DESCRIPTION:{file}
>C1:{def/}
>C1:{dfe/}

  comptesteval '_tst() { a=(a); _describe "group1" a; a=(b); _describe "group2" a }'
  comptest $'tst \t'
0:multi headers
>line: {tst a }{}
>QUERY:{}
>DESCRIPTION:{group1}
>DESCRIPTION:{group2}
>C1:{·a}
>C2:{·b}

  comptest $'git add dir1\t'
0:add empty word
>line: {git add dir1/}{}
# FIXME:why two warnings?

  comptesteval "zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*'"
  comptesteval "touch vim.coc"
  comptest $': coc\t'
  comptesteval "rm vim.coc; zstyle -d ':completion:*' matcher-list"
0:matcher-list
>line: {: vim.coc }{}

  comptesteval $'cd dir1'
  comptest $': ../d\t'
  comptesteval $'cd ..'
0:IPREFIX
>line: {: ../dir1/}{}
>QUERY:{dir}
>DESCRIPTION:{file}
>C1:{dir1/}
>C1:{dir2/}

  comptest $': $PWD/d\t'
0:expansion
>line: {: $PWD/dir1/}{}
>QUERY:{dir}
>DESCRIPTION:{file}
>C1:{dir1/}
>C1:{dir2/}

  comptesteval 'echo no > called'
  comptesteval "touch 'dir\`echo yes > called\`'"
  comptest $': d\t'
  echo called:$(<called)
  comptesteval "rm 'dir\`echo yes > called\`' called"
0:don''t expand file name
>line: {: dir1/}{}
>QUERY:{dir}
>DESCRIPTION:{file}
>C1:{dir1/}
>C1:{dir2/}
>C1:{dir`echo yes > called`}
>called:no

  comptesteval "zstyle ':fzf-tab:*' debug-command true"
  comptest $': d\t'
  comptesteval "zstyle ':fzf-tab:*' debug-command $ZTST_srcdir/select -n 1 -h '\$#headers' -q '\"\$query\"'"
0:cancel completion
>line: {: d}{}

  comptesteval "zstyle ':fzf-tab:*' debug-command $ZTST_srcdir/select -n QUERY -h '\$#headers' -q '\"dragon\"'"
  comptest $': ./d\t'
  comptesteval "zstyle ':fzf-tab:*' debug-command $ZTST_srcdir/select -n 1 -h '\$#headers' -q '\"\$query\"'"
0:use query directly
>line: {: ./dragon}{}
>QUERY:{dragon}
>DESCRIPTION:{file}
>C1:{dir1/}
>C1:{dir2/}

%clean

  zmodload -ui zsh/zpty