| 1 |
Execute (Setup): |
| 2 |
let g:dir = fnamemodify(g:vader_file, ':p:h') |
| 3 |
unlet! g:fzf_layout g:fzf_action g:fzf_history_dir |
| 4 |
Log 'Test directory: ' . g:dir |
| 5 |
Save &acd |
| 6 |
|
| 7 |
" fzf#run runs fzf in a terminal buffer and returns immediately, so the |
| 8 |
" assertions have to wait for the run to finish. 'exit' is called from the |
| 9 |
" same handler that runs the sink, just before it, so once it has fired the |
| 10 |
" sink has run too. It also fires when nothing is selected, unlike the sink. |
| 11 |
function! g:FzfExit(code) |
| 12 |
let g:fzf_done = 1 |
| 13 |
endfunction |
| 14 |
|
| 15 |
" Collects the output without displacing a 'sink' the spec already has. |
| 16 |
" s:callback runs both |
| 17 |
function! g:FzfCollect(lines) |
| 18 |
call extend(g:fzf_lines, a:lines) |
| 19 |
endfunction |
| 20 |
|
| 21 |
function! g:FzfRun(spec) abort |
| 22 |
let g:fzf_done = 0 |
| 23 |
let g:fzf_lines = [] |
| 24 |
call fzf#run(extend(copy(a:spec), |
| 25 |
\ { 'exit': function('g:FzfExit'), 'sinklist': function('g:FzfCollect') })) |
| 26 |
let started = reltime() |
| 27 |
while !g:fzf_done && reltimefloat(reltime(started)) < 10 |
| 28 |
sleep 10m |
| 29 |
endwhile |
| 30 |
if !g:fzf_done |
| 31 |
throw 'Timed out waiting for fzf#run' |
| 32 |
endif |
| 33 |
return g:fzf_lines |
| 34 |
endfunction |
| 35 |
|
| 36 |
Execute (fzf#run with dir option): |
| 37 |
let cwd = getcwd() |
| 38 |
let result = g:FzfRun({ 'source': 'git ls-files', 'options': '--filter=vdr', 'dir': g:dir }) |
| 39 |
AssertEqual ['fzf.vader'], result |
| 40 |
AssertEqual 0, haslocaldir() |
| 41 |
AssertEqual getcwd(), cwd |
| 42 |
|
| 43 |
execute 'lcd' fnameescape(cwd) |
| 44 |
let result = sort(g:FzfRun({ 'source': 'git ls-files', 'options': '--filter e', 'dir': g:dir })) |
| 45 |
AssertEqual ['fzf.vader'], result |
| 46 |
AssertEqual 1, haslocaldir() |
| 47 |
AssertEqual getcwd(), cwd |
| 48 |
|
| 49 |
Execute (fzf#run with Funcref command): |
| 50 |
let g:ret = [] |
| 51 |
function! g:FzfTest(e) |
| 52 |
call add(g:ret, a:e) |
| 53 |
endfunction |
| 54 |
let result = sort(g:FzfRun({ 'source': 'git ls-files', 'sink': function('g:FzfTest'), 'options': '--filter e', 'dir': g:dir })) |
| 55 |
AssertEqual ['fzf.vader'], result |
| 56 |
AssertEqual ['fzf.vader'], sort(g:ret) |
| 57 |
|
| 58 |
Execute (fzf#run with string source): |
| 59 |
let result = sort(g:FzfRun({ 'source': 'echo hi', 'options': '-f i' })) |
| 60 |
AssertEqual ['hi'], result |
| 61 |
|
| 62 |
Execute (fzf#run with list source): |
| 63 |
let result = sort(g:FzfRun({ 'source': ['hello', 'world'], 'options': '-f e' })) |
| 64 |
AssertEqual ['hello'], result |
| 65 |
let result = sort(g:FzfRun({ 'source': ['hello', 'world'], 'options': '-f o' })) |
| 66 |
AssertEqual ['hello', 'world'], result |
| 67 |
|
| 68 |
Execute (fzf#run with string source): |
| 69 |
let result = sort(g:FzfRun({ 'source': 'echo hi', 'options': '-f i' })) |
| 70 |
AssertEqual ['hi'], result |
| 71 |
|
| 72 |
Execute (fzf#run with dir option and noautochdir): |
| 73 |
set noacd |
| 74 |
let cwd = getcwd() |
| 75 |
call g:FzfRun({'source': ['/foobar'], 'sink': 'e', 'dir': '/tmp', 'options': '-1'}) |
| 76 |
" No change in working directory |
| 77 |
AssertEqual cwd, getcwd() |
| 78 |
|
| 79 |
call g:FzfRun({'source': ['/foobar'], 'sink': 'tabe', 'dir': '/tmp', 'options': '-1'}) |
| 80 |
AssertEqual cwd, getcwd() |
| 81 |
tabclose |
| 82 |
AssertEqual cwd, getcwd() |
| 83 |
|
| 84 |
Execute (Incomplete fzf#run with dir option and autochdir): |
| 85 |
set acd |
| 86 |
let cwd = getcwd() |
| 87 |
call g:FzfRun({'source': [], 'sink': 'e', 'dir': '/tmp', 'options': '-0'}) |
| 88 |
" No change in working directory even if &acd is set |
| 89 |
AssertEqual cwd, getcwd() |
| 90 |
|
| 91 |
Execute (FIXME: fzf#run with dir option and autochdir): |
| 92 |
set acd |
| 93 |
call g:FzfRun({'source': ['/foobar'], 'sink': 'e', 'dir': '/tmp', 'options': '-1'}) |
| 94 |
" Working directory changed due to &acd |
| 95 |
AssertEqual '/foobar', expand('%') |
| 96 |
AssertEqual '/', getcwd() |
| 97 |
|
| 98 |
Execute (fzf#run with dir option and autochdir when final cwd is same as dir): |
| 99 |
set acd |
| 100 |
cd /tmp |
| 101 |
call g:FzfRun({'source': ['/foobar'], 'sink': 'e', 'dir': '/', 'options': '-1'}) |
| 102 |
" Working directory changed due to &acd |
| 103 |
AssertEqual '/', getcwd() |
| 104 |
|
| 105 |
Execute (Default layout): |
| 106 |
unlet! g:fzf_layout g:fzf_height |
| 107 |
let layout_keys = ['window', 'popup', 'tmux', 'up', 'down', 'left', 'right'] |
| 108 |
|
| 109 |
let opts = fzf#wrap('foobar') |
| 110 |
Log opts |
| 111 |
let found = filter(copy(layout_keys), 'has_key(opts, v:val)') |
| 112 |
AssertEqual 1, len(found) |
| 113 |
if found[0] ==# 'tmux' |
| 114 |
" Only where fzf opens a floating pane, which can be left while fzf runs |
| 115 |
Assert !empty($TMUX) || !empty($ZELLIJ) |
| 116 |
AssertEqual '90%,60%', opts.tmux |
| 117 |
elseif found[0] ==# 'window' |
| 118 |
AssertEqual 0.9, opts.window.width |
| 119 |
else |
| 120 |
" No popup support in this build |
| 121 |
AssertEqual '~40%', opts.down |
| 122 |
endif |
| 123 |
|
| 124 |
" Fullscreen strips it, whichever it was |
| 125 |
let opts = fzf#wrap('foobar', {}, 1) |
| 126 |
Log opts |
| 127 |
AssertEqual [], filter(copy(layout_keys), 'has_key(opts, v:val)') |
| 128 |
|
| 129 |
Execute (fzf#wrap): |
| 130 |
AssertThrows fzf#wrap({'foo': 'bar'}) |
| 131 |
|
| 132 |
" Pin the layout so the assertions do not depend on the environment |
| 133 |
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } } |
| 134 |
|
| 135 |
let opts = fzf#wrap('foobar') |
| 136 |
Log opts |
| 137 |
AssertEqual 0.9, opts.window.width |
| 138 |
Assert opts.options =~ '--expect=' |
| 139 |
Assert !has_key(opts, 'sink') |
| 140 |
Assert has_key(opts, 'sink*') |
| 141 |
|
| 142 |
let opts = fzf#wrap('foobar', {}, 0) |
| 143 |
Log opts |
| 144 |
AssertEqual 0.9, opts.window.width |
| 145 |
|
| 146 |
let opts = fzf#wrap('foobar', {}, 1) |
| 147 |
Log opts |
| 148 |
Assert !has_key(opts, 'window') |
| 149 |
|
| 150 |
let opts = fzf#wrap('foobar', {'down': '50%'}) |
| 151 |
Log opts |
| 152 |
AssertEqual '50%', opts.down |
| 153 |
|
| 154 |
let opts = fzf#wrap('foobar', {'down': '50%'}, 1) |
| 155 |
Log opts |
| 156 |
Assert !has_key(opts, 'down') |
| 157 |
|
| 158 |
let opts = fzf#wrap('foobar', {'sink': 'e'}) |
| 159 |
Log opts |
| 160 |
AssertEqual 'e', opts.sink |
| 161 |
Assert !has_key(opts, 'sink*') |
| 162 |
|
| 163 |
let opts = fzf#wrap('foobar', {'options': '--reverse'}) |
| 164 |
Log opts |
| 165 |
Assert opts.options =~ '--expect=' |
| 166 |
Assert opts.options =~ '--reverse' |
| 167 |
|
| 168 |
let g:fzf_layout = {'window': 'enew'} |
| 169 |
let opts = fzf#wrap('foobar') |
| 170 |
Log opts |
| 171 |
AssertEqual 'enew', opts.window |
| 172 |
|
| 173 |
let opts = fzf#wrap('foobar', {}, 1) |
| 174 |
Log opts |
| 175 |
Assert !has_key(opts, 'window') |
| 176 |
|
| 177 |
let opts = fzf#wrap('foobar', {'right': '50%'}) |
| 178 |
Log opts |
| 179 |
Assert !has_key(opts, 'window') |
| 180 |
AssertEqual '50%', opts.right |
| 181 |
|
| 182 |
let opts = fzf#wrap('foobar', {'right': '50%'}, 1) |
| 183 |
Log opts |
| 184 |
Assert !has_key(opts, 'window') |
| 185 |
Assert !has_key(opts, 'right') |
| 186 |
|
| 187 |
let g:fzf_action = {'a': 'tabe'} |
| 188 |
let opts = fzf#wrap('foobar') |
| 189 |
Log opts |
| 190 |
Assert opts.options =~ '--expect=a' |
| 191 |
Assert !has_key(opts, 'sink') |
| 192 |
Assert has_key(opts, 'sink*') |
| 193 |
|
| 194 |
let opts = fzf#wrap('foobar', {'sink': 'e'}) |
| 195 |
Log opts |
| 196 |
AssertEqual 'e', opts.sink |
| 197 |
Assert !has_key(opts, 'sink*') |
| 198 |
|
| 199 |
let g:fzf_history_dir = '/tmp' |
| 200 |
let opts = fzf#wrap('foobar', {'options': '--color light'}) |
| 201 |
Log opts |
| 202 |
Assert opts.options =~ "--history '/tmp/foobar'" |
| 203 |
Assert opts.options =~ '--color light' |
| 204 |
|
| 205 |
let g:fzf_colors = { 'fg': ['fg', 'Error'] } |
| 206 |
let opts = fzf#wrap({}) |
| 207 |
Assert opts.options =~ '--color=fg:' |
| 208 |
|
| 209 |
Execute (popup is a synonym of tmux): |
| 210 |
unlet! g:fzf_layout |
| 211 |
|
| 212 |
" Treated as a layout option, so g:fzf_layout is not applied on top |
| 213 |
let opts = fzf#wrap('foobar', {'popup': '90%,70%'}) |
| 214 |
AssertEqual '90%,70%', opts.popup |
| 215 |
Assert !has_key(opts, 'window') |
| 216 |
|
| 217 |
" And stripped in fullscreen, like the others |
| 218 |
let opts = fzf#wrap('foobar', {'popup': '90%,70%'}, 1) |
| 219 |
Assert !has_key(opts, 'popup') |
| 220 |
|
| 221 |
" Accepted in g:fzf_layout |
| 222 |
let g:fzf_layout = {'popup': '90%,70%'} |
| 223 |
let opts = fzf#wrap('foobar') |
| 224 |
AssertEqual '90%,70%', opts.popup |
| 225 |
unlet g:fzf_layout |
| 226 |
|
| 227 |
" Listed as a valid key |
| 228 |
let g:fzf_layout = {'bogus': 1} |
| 229 |
AssertThrows call fzf#wrap('foobar') |
| 230 |
Assert g:vader_exception =~ 'popup' |
| 231 |
unlet g:fzf_layout |
| 232 |
|
| 233 |
Execute (fzf#shellescape with sh): |
| 234 |
AssertEqual '''''', fzf#shellescape('', 'sh') |
| 235 |
AssertEqual '''\''', fzf#shellescape('\', 'sh') |
| 236 |
AssertEqual '''""''', fzf#shellescape('""', 'sh') |
| 237 |
AssertEqual '''foobar>''', fzf#shellescape('foobar>', 'sh') |
| 238 |
AssertEqual '''\\\"\\\''', fzf#shellescape('\\\"\\\', 'sh') |
| 239 |
AssertEqual '''echo ''\''''a''\'''' && echo ''\''''b''\''''''', fzf#shellescape('echo ''a'' && echo ''b''', 'sh') |
| 240 |
|
| 241 |
Execute (fzf#shellescape with cmd.exe): |
| 242 |
AssertEqual '^"^"', fzf#shellescape('', 'cmd.exe') |
| 243 |
AssertEqual '^"\\^"', fzf#shellescape('\', 'cmd.exe') |
| 244 |
AssertEqual '^"\^"\^"^"', fzf#shellescape('""', 'cmd.exe') |
| 245 |
AssertEqual '^"foobar^>^"', fzf#shellescape('foobar>', 'cmd.exe') |
| 246 |
AssertEqual '^"\\\\\\\^"\\\\\\^"', fzf#shellescape('\\\"\\\', 'cmd.exe') |
| 247 |
AssertEqual '^"echo ''a'' ^&^& echo ''b''^"', fzf#shellescape('echo ''a'' && echo ''b''', 'cmd.exe') |
| 248 |
|
| 249 |
AssertEqual '^"C:\Program Files ^(x86^)\\^"', fzf#shellescape('C:\Program Files (x86)\', 'cmd.exe') |
| 250 |
AssertEqual '^"C:/Program Files ^(x86^)/^"', fzf#shellescape('C:/Program Files (x86)/', 'cmd.exe') |
| 251 |
AssertEqual '^"%%USERPROFILE%%^"', fzf#shellescape('%USERPROFILE%', 'cmd.exe') |
| 252 |
|
| 253 |
Execute (Cleanup): |
| 254 |
unlet g:dir |
| 255 |
Restore |