workflow.vader 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. Execute (Initialize test environment):
  2. Save &rtp, g:plugs, g:plug_home, $MYVIMRC
  3. let vader = fnamemodify(globpath(&rtp, 'autoload/vader.vim'), ':h:h')
  4. let plug = fnamemodify(globpath(&rtp, 'autoload/plug.vim'), ':h:h')
  5. set rtp=$HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after
  6. execute 'set rtp^='.vader
  7. execute 'set rtp^='.plug
  8. let basertp = &rtp
  9. unlet! g:plugs
  10. unlet! g:plug_home
  11. set t_Co=256
  12. colo default
  13. pclose
  14. function! PlugStatusSorted()
  15. PlugStatus
  16. %y
  17. q
  18. normal! P
  19. %sort
  20. g/^$/d
  21. endfunction
  22. let g:vimrc_reloaded = 0
  23. let vimrc = tempname()
  24. call writefile(['let g:vimrc_reloaded += 1'], vimrc)
  25. let $MYVIMRC = vimrc
  26. Execute (plug#end() before plug#begin() should fail):
  27. try
  28. call plug#end()
  29. Assert 0, 'should not reach here'
  30. catch
  31. Assert stridx(v:exception, 'Call plug#begin() first') >= 0
  32. endtry
  33. Execute (plug#begin() without path argument):
  34. call plug#begin()
  35. AssertEqual split(&rtp, ',')[0].'/plugged', g:plug_home
  36. unlet g:plug_home
  37. Execute (plug#begin() without path argument with empty &rtp):
  38. let save_rtp = &rtp
  39. set rtp=
  40. try
  41. call plug#begin()
  42. Assert 0, 'should not reach here'
  43. catch
  44. Assert stridx(v:exception, 'Unable to determine plug home') >= 0, 'Got: '.v:exception
  45. endtry
  46. let &rtp = save_rtp
  47. Execute (plug#begin(path)):
  48. let temp_plugged = tempname()
  49. call plug#begin(temp_plugged.'/')
  50. Assert g:plug_home !~ '[/\\]$', 'Trailing / should be stripped from g:plug_home'
  51. AssertEqual 0, len(g:plugs)
  52. AssertEqual temp_plugged, g:plug_home
  53. AssertEqual basertp, &rtp
  54. Execute (Subsequent plug#begin() calls will reuse g:plug_home):
  55. call plug#begin()
  56. AssertEqual temp_plugged, g:plug_home
  57. Execute (Test Plug command):
  58. " Git repo with branch
  59. Plug 'junegunn/seoul256.vim', 'no-t_co'
  60. AssertEqual 'https://git:@github.com/junegunn/seoul256.vim.git', g:plugs['seoul256.vim'].uri
  61. AssertEqual join([temp_plugged, 'seoul256.vim/'], '/'), g:plugs['seoul256.vim'].dir
  62. AssertEqual 'no-t_co', g:plugs['seoul256.vim'].branch
  63. " Git repo with tag
  64. Plug 'junegunn/goyo.vim', '1.5.3'
  65. AssertEqual 'https://git:@github.com/junegunn/goyo.vim.git', g:plugs['goyo.vim'].uri
  66. AssertEqual join([temp_plugged, 'goyo.vim/'], '/'), g:plugs['goyo.vim'].dir
  67. AssertEqual '1.5.3', g:plugs['goyo.vim'].branch
  68. " Git URI
  69. Plug 'git@github.com:junegunn/vim-emoji.git'
  70. AssertEqual 'git@github.com:junegunn/vim-emoji.git', g:plugs['vim-emoji'].uri
  71. AssertEqual 'master', g:plugs['vim-emoji'].branch
  72. AssertEqual join([temp_plugged, 'vim-emoji/'], '/'), g:plugs['vim-emoji'].dir
  73. " vim-scripts/
  74. Plug 'beauty256'
  75. AssertEqual 'https://git:@github.com/vim-scripts/beauty256.git', g:plugs.beauty256.uri
  76. AssertEqual 'master', g:plugs.beauty256.branch
  77. AssertEqual 4, len(g:plugs)
  78. Execute (Plug command with dictionary option):
  79. Log string(g:plugs)
  80. Plug 'junegunn/seoul256.vim', { 'branch': 'no-t_co', 'rtp': '././' }
  81. AssertEqual join([temp_plugged, 'seoul256.vim/'], '/'), g:plugs['seoul256.vim'].dir
  82. AssertEqual '././', g:plugs['seoul256.vim'].rtp
  83. Log string(g:plugs)
  84. AssertEqual 4, len(g:plugs)
  85. Execute (PlugStatus before installation):
  86. PlugStatus
  87. AssertEqual 4, len(filter(getline(1, line('$')), 'v:val =~ "Not found"'))
  88. q
  89. Execute (PlugClean before installation):
  90. PlugClean
  91. AssertEqual 1, len(filter(getline(1, line('$')), 'v:val =~ "Already clean"'))
  92. q
  93. Execute (plug#end() updates &rtp):
  94. call plug#end()
  95. Assert len(&rtp) > len(basertp)
  96. Execute (Yet, plugins are not available):
  97. Assert empty(globpath(&rtp, 'autoload/emoji.vim'))
  98. Execute (PlugInstall):
  99. PlugInstall
  100. AssertEqual 1, g:vimrc_reloaded
  101. q
  102. Execute (Plugin available after installation):
  103. Assert !empty(globpath(&rtp, 'autoload/emoji.vim'))
  104. Execute (PlugClean after installation):
  105. PlugClean
  106. AssertEqual 1, len(filter(getline(1, line('$')), 'v:val =~ "Already clean"'))
  107. q
  108. Execute (PlugStatus after installation):
  109. PlugStatus
  110. AssertEqual 4, len(filter(getline(1, line('$')), 'v:val =~ "OK"'))
  111. q
  112. Execute (Change tag of goyo.vim):
  113. call plug#begin()
  114. Plug 'junegunn/goyo.vim'
  115. call plug#end()
  116. Execute (PlugStatus):
  117. call PlugStatusSorted()
  118. Expect:
  119. Invalid branch/tag: 1.5.3 (expected: master). Try PlugUpdate.
  120. Finished. 1 error(s).
  121. [=]
  122. x goyo.vim:
  123. Execute (PlugUpdate to set the right branch):
  124. PlugUpdate
  125. call PlugStatusSorted()
  126. AssertEqual 2, g:vimrc_reloaded
  127. Expect:
  128. - goyo.vim: OK
  129. Finished. 0 error(s).
  130. [=]
  131. Execute (Change branch of seoul256.vim):
  132. call plug#begin()
  133. Plug 'junegunn/seoul256.vim'
  134. Plug 'git@github.com:junegunn/vim-emoji.git'
  135. call plug#end()
  136. Execute (PlugStatus):
  137. call PlugStatusSorted()
  138. Expect:
  139. Invalid branch/tag: no-t_co (expected: master). Try PlugUpdate.
  140. - vim-emoji: OK
  141. Finished. 1 error(s).
  142. [==]
  143. x seoul256.vim:
  144. Execute (Change URI of seoul256.vim):
  145. call plug#begin()
  146. Plug 'junegunn.choi/seoul256.vim'
  147. Plug 'git@github.com:junegunn/vim-emoji.git'
  148. call plug#end()
  149. Execute (PlugStatus):
  150. call PlugStatusSorted()
  151. Expect:
  152. Expected: https://git:@github.com/junegunn.choi/seoul256.vim.git
  153. Invalid URI: https://git:@github.com/junegunn/seoul256.vim.git
  154. PlugClean required.
  155. - vim-emoji: OK
  156. Finished. 1 error(s).
  157. [==]
  158. x seoul256.vim:
  159. # TODO: does not work due to inputsave()
  160. # Do (PlugClean):
  161. # :PlugClean\<Enter>y\<Enter>
  162. # ggyG
  163. # q
  164. # PGdd
  165. Execute (PlugClean! to remove seoul256.vim):
  166. PlugClean!
  167. " Three removed, emoji left
  168. AssertEqual 3, len(filter(getline(1, line('$')), 'v:val =~ "^- "'))
  169. AssertEqual 1, len(filter(getline(1, line('$')), 'v:val =~ "Removed"'))
  170. Assert empty(globpath(&rtp, 'colors/seoul256.vim'))
  171. Assert !empty(globpath(&rtp, 'autoload/emoji.vim'))
  172. q
  173. Execute (Change GIT URI of vim-emoji):
  174. call plug#begin()
  175. Plug 'junegunn/seoul256.vim'
  176. Plug 'junegunn/vim-emoji'
  177. call plug#end()
  178. Execute (PlugStatus):
  179. call PlugStatusSorted()
  180. Expect:
  181. Expected: https://git:@github.com/junegunn/vim-emoji.git
  182. Invalid URI: git@github.com:junegunn/vim-emoji.git
  183. Not found. Try PlugInstall.
  184. PlugClean required.
  185. Finished. 2 error(s).
  186. [==]
  187. x seoul256.vim:
  188. x vim-emoji:
  189. Execute (PlugClean! to remove vim-emoji):
  190. PlugClean!
  191. AssertEqual 1, len(filter(getline(1, line('$')), 'v:val =~ "^- "'))
  192. AssertEqual 1, len(filter(getline(1, line('$')), 'v:val =~ "Removed"'))
  193. Assert empty(globpath(&rtp, 'colors/seoul256.vim'))
  194. Assert empty(globpath(&rtp, 'autoload/emoji.vim'))
  195. q
  196. Execute (PlugUpdate to install both again):
  197. PlugUpdate
  198. AssertEqual 2, len(filter(getline(1, line('$')), 'v:val =~ "Cloning into"'))
  199. AssertEqual 3, g:vimrc_reloaded
  200. Assert !empty(globpath(&rtp, 'colors/seoul256.vim')), 'seoul256.vim should be found'
  201. Assert !empty(globpath(&rtp, 'autoload/emoji.vim')), 'vim-emoji should be found'
  202. q
  203. Execute (PlugUpdate only to find out plugins are up-to-date, D key to check):
  204. PlugUpdate
  205. AssertEqual 2, len(filter(getline(1, line('$')), 'v:val =~ "Already up-to-date"'))
  206. AssertEqual 4, g:vimrc_reloaded
  207. normal D
  208. AssertEqual 'No updates.', getline(1)
  209. q
  210. Execute (PlugDiff - 'No updates.'):
  211. PlugDiff
  212. AssertEqual 'No updates.', getline(1)
  213. q
  214. Execute (Rollback recent updates, PlugUpdate, then PlugDiff):
  215. for repo in ['seoul256.vim', 'vim-emoji']
  216. call system(printf('cd %s/%s && git reset HEAD^^ --hard', g:plug_home, repo))
  217. endfor
  218. PlugUpdate
  219. " Now we have updates
  220. normal D
  221. AssertEqual 'Last update:', getline(1)
  222. " Preview commit
  223. silent! wincmd P
  224. AssertEqual 0, &previewwindow
  225. " ]] motion
  226. execute 'normal ]]'
  227. let lnum = line('.')
  228. AssertEqual 3, col('.')
  229. " Open commit preview
  230. execute "normal j\<cr>"
  231. wincmd P
  232. AssertEqual 1, &previewwindow
  233. AssertEqual 'git', &filetype
  234. " Back to plug window
  235. wincmd p
  236. " ]] motion
  237. execute 'normal $]]'
  238. AssertEqual lnum + 4, line('.')
  239. AssertEqual 3, col('.')
  240. " [[ motion
  241. execute 'normal 0[['
  242. AssertEqual lnum, line('.')
  243. AssertEqual 3, col('.')
  244. " q will close preview window as well
  245. normal q
  246. " We no longer have preview window
  247. silent! wincmd P
  248. AssertEqual 0, &previewwindow
  249. " q should not close preview window if it's already open
  250. pedit
  251. PlugDiff
  252. execute "normal ]]j\<cr>"
  253. normal q
  254. silent! wincmd P
  255. AssertEqual 1, &previewwindow
  256. pclose
  257. Execute (Plug window in a new tab):
  258. PlugDiff
  259. tab new new-tab
  260. set buftype=nofile
  261. PlugUpdate
  262. normal D
  263. AssertEqual 'No updates.', getline(1)
  264. q
  265. AssertEqual 'new-tab', expand('%')
  266. q
  267. q
  268. **********************************************************************
  269. ~ On-demand loading / Partial installation/update ~
  270. **********************************************************************
  271. Execute (Trying to execute on-demand commands when plugin is not installed):
  272. call plug#begin()
  273. Plug 'junegunn/vim-easy-align', { 'on': ['EasyAlign', 'LiveEasyAlign'] }
  274. call plug#end()
  275. Assert exists(':EasyAlign')
  276. Assert exists(':LiveEasyAlign')
  277. AssertThrows EasyAlign
  278. AssertThrows LiveEasyAlign
  279. Assert !exists(':EasyAlign')
  280. Assert !exists(':LiveEasyAlign')
  281. Execute (New set of plugins):
  282. call plug#begin()
  283. Plug 'junegunn/vim-fnr' " Depends on vim-pseudocl
  284. Plug 'junegunn/vim-easy-align', { 'on': 'EasyAlign' }
  285. Plug 'junegunn/vim-redis', { 'for': 'redis' }
  286. call plug#end()
  287. Execute (Check commands):
  288. Assert !exists(':FNR'), 'FNR command should not be found'
  289. Assert !exists(':RedisExecute'), 'RedisExecute command should not be found'
  290. Execute (Partial PlugInstall):
  291. PlugInstall vim-fnr vim-easy-align
  292. PlugInstall vim-fnr vim-easy-align 1
  293. q
  294. Execute (Check dependent plugin):
  295. Assert &rtp =~ 'pseudocl', &rtp
  296. Given (Unaligned code):
  297. a=1
  298. aa=2
  299. Execute (Check installed plugins):
  300. Assert exists(':FNR'), 'FNR command should be found'
  301. Assert exists(':EasyAlign'), 'EasyAlign command should be found'
  302. Assert !exists(':RedisExecute'), 'RedisExecute command still should not be found'
  303. %EasyAlign=
  304. Expect (Aligned code):
  305. a = 1
  306. aa = 2
  307. Given (nothing):
  308. Execute (Partial PlugUpdate):
  309. PlugUpdate vim-redis
  310. q
  311. Execute (On-demand loading based on filetypes):
  312. Assert !exists(':RedisExecute'), 'RedisExecute command still should not be found'
  313. set ft=redis
  314. Assert exists(':RedisExecute'), 'RedisExecute command is now found'
  315. Execute (Cleanup):
  316. call system('rm -rf '.temp_plugged)
  317. unlet g:plugs
  318. unlet g:plug_home
  319. unlet g:vimrc_reloaded
  320. unlet temp_plugged vader plug basertp save_rtp repo lnum
  321. delf PlugStatusSorted
  322. Restore