fzf.vader
This file
Path
test/vim/fzf.vader
255 lines · 8.3 KiB
Last changed by
[vim] Open fzf in a tmux or Zellij floating pane by default (#4905)Junegunn Choibefore adoptiona52ac84
History of this fileTake it
The walk stopped after 200 commits: lines older than 76efddd point at it.
bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 1–6why, one step back1Execute (Setup):2 let g:dir = fnamemodify(g:vader_file, ':p:h')3 unlet! g:fzf_layout g:fzf_action g:fzf_history_dir4 Log 'Test directory: ' . g:dir5 Save &acd6Run fzf asynchronously in the Vim plugin (#4897)Junegunn Choibefore adoption5cb7bab
lines 7–35why, one step back7 " fzf#run runs fzf in a terminal buffer and returns immediately, so the8 " assertions have to wait for the run to finish. 'exit' is called from the9 " same handler that runs the sink, just before it, so once it has fired the10 " sink has run too. It also fires when nothing is selected, unlike the sink.11 function! g:FzfExit(code)12 let g:fzf_done = 113 endfunction1415 " Collects the output without displacing a 'sink' the spec already has.16 " s:callback runs both17 function! g:FzfCollect(lines)18 call extend(g:fzf_lines, a:lines)19 endfunction2021 function! g:FzfRun(spec) abort22 let g:fzf_done = 023 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)) < 1028 sleep 10m29 endwhile30 if !g:fzf_done31 throw 'Timed out waiting for fzf#run'32 endif33 return g:fzf_lines34 endfunction35bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 36–37why, one step back36Execute (fzf#run with dir option):37 let cwd = getcwd()Run fzf asynchronously in the Vim plugin (#4897)Junegunn Choibefore adoption5cb7bab
line 38why, one step back38 let result = g:FzfRun({ 'source': 'git ls-files', 'options': '--filter=vdr', 'dir': g:dir })bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 39–43why, one step back39 AssertEqual ['fzf.vader'], result40 AssertEqual 0, haslocaldir()41 AssertEqual getcwd(), cwd4243 execute 'lcd' fnameescape(cwd)Run fzf asynchronously in the Vim plugin (#4897)Junegunn Choibefore adoption5cb7bab
line 44why, one step back44 let result = sort(g:FzfRun({ 'source': 'git ls-files', 'options': '--filter e', 'dir': g:dir }))bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 45–53why, one step back45 AssertEqual ['fzf.vader'], result46 AssertEqual 1, haslocaldir()47 AssertEqual getcwd(), cwd4849Execute (fzf#run with Funcref command):50 let g:ret = []51 function! g:FzfTest(e)52 call add(g:ret, a:e)53 endfunctionRun fzf asynchronously in the Vim plugin (#4897)Junegunn Choibefore adoption5cb7bab
line 54why, one step back54 let result = sort(g:FzfRun({ 'source': 'git ls-files', 'sink': function('g:FzfTest'), 'options': '--filter e', 'dir': g:dir }))bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 55–58why, one step back55 AssertEqual ['fzf.vader'], result56 AssertEqual ['fzf.vader'], sort(g:ret)5758Execute (fzf#run with string source):Run fzf asynchronously in the Vim plugin (#4897)Junegunn Choibefore adoption5cb7bab
line 59why, one step back59 let result = sort(g:FzfRun({ 'source': 'echo hi', 'options': '-f i' }))bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 60–62why, one step back60 AssertEqual ['hi'], result6162Execute (fzf#run with list source):Run fzf asynchronously in the Vim plugin (#4897)Junegunn Choibefore adoption5cb7bab
line 63why, one step back63 let result = sort(g:FzfRun({ 'source': ['hello', 'world'], 'options': '-f e' }))bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 64why, one step back64 AssertEqual ['hello'], resultRun fzf asynchronously in the Vim plugin (#4897)Junegunn Choibefore adoption5cb7bab
line 65why, one step back65 let result = sort(g:FzfRun({ 'source': ['hello', 'world'], 'options': '-f o' }))bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 66–68why, one step back66 AssertEqual ['hello', 'world'], result6768Execute (fzf#run with string source):Run fzf asynchronously in the Vim plugin (#4897)Junegunn Choibefore adoption5cb7bab
line 69why, one step back69 let result = sort(g:FzfRun({ 'source': 'echo hi', 'options': '-f i' }))bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 70–74why, one step back70 AssertEqual ['hi'], result7172Execute (fzf#run with dir option and noautochdir):73 set noacd74 let cwd = getcwd()Run fzf asynchronously in the Vim plugin (#4897)Junegunn Choibefore adoption5cb7bab
line 75why, one step back75 call g:FzfRun({'source': ['/foobar'], 'sink': 'e', 'dir': '/tmp', 'options': '-1'})bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 76–78why, one step back76 " No change in working directory77 AssertEqual cwd, getcwd()78Run fzf asynchronously in the Vim plugin (#4897)Junegunn Choibefore adoption5cb7bab
line 79why, one step back79 call g:FzfRun({'source': ['/foobar'], 'sink': 'tabe', 'dir': '/tmp', 'options': '-1'})bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 80–86why, one step back80 AssertEqual cwd, getcwd()81 tabclose82 AssertEqual cwd, getcwd()8384Execute (Incomplete fzf#run with dir option and autochdir):85 set acd86 let cwd = getcwd()Run fzf asynchronously in the Vim plugin (#4897)Junegunn Choibefore adoption5cb7bab
line 87why, one step back87 call g:FzfRun({'source': [], 'sink': 'e', 'dir': '/tmp', 'options': '-0'})bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 88–92why, one step back88 " No change in working directory even if &acd is set89 AssertEqual cwd, getcwd()9091Execute (FIXME: fzf#run with dir option and autochdir):92 set acdRun fzf asynchronously in the Vim plugin (#4897)Junegunn Choibefore adoption5cb7bab
line 93why, one step back93 call g:FzfRun({'source': ['/foobar'], 'sink': 'e', 'dir': '/tmp', 'options': '-1'})bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 94–100why, one step back94 " Working directory changed due to &acd95 AssertEqual '/foobar', expand('%')96 AssertEqual '/', getcwd()9798Execute (fzf#run with dir option and autochdir when final cwd is same as dir):99 set acd100 cd /tmpRun fzf asynchronously in the Vim plugin (#4897)Junegunn Choibefore adoption5cb7bab
line 101why, one step back101 call g:FzfRun({'source': ['/foobar'], 'sink': 'e', 'dir': '/', 'options': '-1'})bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 102–104why, one step back102 " Working directory changed due to &acd103 AssertEqual '/', getcwd()104[vim] Open fzf in a tmux or Zellij floating pane by default (#4905)Junegunn Choibefore adoptiona52ac84
lines 105–128why, one step back105Execute (Default layout):106 unlet! g:fzf_layout g:fzf_height107 let layout_keys = ['window', 'popup', 'tmux', 'up', 'down', 'left', 'right']108109 let opts = fzf#wrap('foobar')110 Log opts111 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 runs115 Assert !empty($TMUX) || !empty($ZELLIJ)116 AssertEqual '90%,60%', opts.tmux117 elseif found[0] ==# 'window'118 AssertEqual 0.9, opts.window.width119 else120 " No popup support in this build121 AssertEqual '~40%', opts.down122 endif123124 " Fullscreen strips it, whichever it was125 let opts = fzf#wrap('foobar', {}, 1)126 Log opts127 AssertEqual [], filter(copy(layout_keys), 'has_key(opts, v:val)')128bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 129–130why, one step back129Execute (fzf#wrap):130 AssertThrows fzf#wrap({'foo': 'bar'})[vim] Open fzf in a tmux or Zellij floating pane by default (#4905)Junegunn Choibefore adoptiona52ac84
lines 131–133why, one step back131132 " Pin the layout so the assertions do not depend on the environment133 let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 134–207why, one step back134135 let opts = fzf#wrap('foobar')136 Log opts137 AssertEqual 0.9, opts.window.width138 Assert opts.options =~ '--expect='139 Assert !has_key(opts, 'sink')140 Assert has_key(opts, 'sink*')141142 let opts = fzf#wrap('foobar', {}, 0)143 Log opts144 AssertEqual 0.9, opts.window.width145146 let opts = fzf#wrap('foobar', {}, 1)147 Log opts148 Assert !has_key(opts, 'window')149150 let opts = fzf#wrap('foobar', {'down': '50%'})151 Log opts152 AssertEqual '50%', opts.down153154 let opts = fzf#wrap('foobar', {'down': '50%'}, 1)155 Log opts156 Assert !has_key(opts, 'down')157158 let opts = fzf#wrap('foobar', {'sink': 'e'})159 Log opts160 AssertEqual 'e', opts.sink161 Assert !has_key(opts, 'sink*')162163 let opts = fzf#wrap('foobar', {'options': '--reverse'})164 Log opts165 Assert opts.options =~ '--expect='166 Assert opts.options =~ '--reverse'167168 let g:fzf_layout = {'window': 'enew'}169 let opts = fzf#wrap('foobar')170 Log opts171 AssertEqual 'enew', opts.window172173 let opts = fzf#wrap('foobar', {}, 1)174 Log opts175 Assert !has_key(opts, 'window')176177 let opts = fzf#wrap('foobar', {'right': '50%'})178 Log opts179 Assert !has_key(opts, 'window')180 AssertEqual '50%', opts.right181182 let opts = fzf#wrap('foobar', {'right': '50%'}, 1)183 Log opts184 Assert !has_key(opts, 'window')185 Assert !has_key(opts, 'right')186187 let g:fzf_action = {'a': 'tabe'}188 let opts = fzf#wrap('foobar')189 Log opts190 Assert opts.options =~ '--expect=a'191 Assert !has_key(opts, 'sink')192 Assert has_key(opts, 'sink*')193194 let opts = fzf#wrap('foobar', {'sink': 'e'})195 Log opts196 AssertEqual 'e', opts.sink197 Assert !has_key(opts, 'sink*')198199 let g:fzf_history_dir = '/tmp'200 let opts = fzf#wrap('foobar', {'options': '--color light'})201 Log opts202 Assert opts.options =~ "--history '/tmp/foobar'"203 Assert opts.options =~ '--color light'204205 let g:fzf_colors = { 'fg': ['fg', 'Error'] }206 let opts = fzf#wrap({})207 Assert opts.options =~ '--color=fg:'Run fzf asynchronously in the Vim plugin (#4897)Junegunn Choibefore adoption5cb7bab
lines 208–231why, one step back208209Execute (popup is a synonym of tmux):210 unlet! g:fzf_layout211212 " Treated as a layout option, so g:fzf_layout is not applied on top213 let opts = fzf#wrap('foobar', {'popup': '90%,70%'})214 AssertEqual '90%,70%', opts.popup215 Assert !has_key(opts, 'window')216217 " And stripped in fullscreen, like the others218 let opts = fzf#wrap('foobar', {'popup': '90%,70%'}, 1)219 Assert !has_key(opts, 'popup')220221 " Accepted in g:fzf_layout222 let g:fzf_layout = {'popup': '90%,70%'}223 let opts = fzf#wrap('foobar')224 AssertEqual '90%,70%', opts.popup225 unlet g:fzf_layout226227 " Listed as a valid key228 let g:fzf_layout = {'bogus': 1}229 AssertThrows call fzf#wrap('foobar')230 Assert g:vader_exception =~ 'popup'231 unlet g:fzf_layoutbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 232–255why, one step back232233Execute (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')240241Execute (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')248249 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')252253Execute (Cleanup):254 unlet g:dir255 Restore