workflow.vader 9.3 KB

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