1
0

finder.test.vim 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. function! SetUp()
  2. let g:ycm_use_clangd = 1
  3. let g:ycm_enable_semantic_highlighting = 1
  4. call youcompleteme#test#setup#SetUp()
  5. nmap <leader><leader>w <Plug>(YCMFindSymbolInWorkspace)
  6. nmap <leader><leader>d <Plug>(YCMFindSymbolInDocument)
  7. endfunction
  8. function! TearDown()
  9. endfunction
  10. function! Test_WorkspaceSymbol_Basic()
  11. call youcompleteme#test#setup#OpenFile(
  12. \ '/test/testdata/cpp/finder_test.cc', {} )
  13. let original_win = winnr()
  14. let b = bufnr()
  15. let l = winlayout()
  16. let popup_id = -1
  17. function! PutQuery( ... )
  18. " Wait for the current buffer to be a prompt buffer
  19. call WaitForAssert( { -> assert_equal( 'prompt', &buftype ) } )
  20. call WaitForAssert( { -> assert_equal( 'i', mode() ) } )
  21. call WaitForAssert( { -> assert_true(
  22. \ youcompleteme#finder#GetState().id != -1 ) } )
  23. " TODO: Wait for the popup to be displayed, and check the contents
  24. call FeedAndCheckAgain( 'xthisisathing', funcref( 'SelectItem' ) )
  25. endfunction
  26. function SelectItem( ... )
  27. let id = youcompleteme#finder#GetState().id
  28. call WaitForAssert( { ->
  29. \ assert_equal( ' [X] Search for symbol: xthisisathing ',
  30. \ popup_getoptions( id ).title ) },
  31. \ 10000 )
  32. call WaitForAssert( { -> assert_equal( 1, line( '$', id ) ) } )
  33. call feedkeys( "\<CR>" )
  34. endfunction
  35. " <Leader> is \ - this calls <Plug>(YCMFindSymbolInWorkspace)
  36. call FeedAndCheckMain( '\\w', funcref( 'PutQuery' ) )
  37. call WaitForAssert( { -> assert_equal( l, winlayout() ) } )
  38. call WaitForAssert( { -> assert_equal( original_win, winnr() ) } )
  39. call assert_equal( b, bufnr() )
  40. call assert_equal( [ 0, 5, 7, 0 ], getpos( '.' ) )
  41. delfunct PutQuery
  42. delfunct SelectItem
  43. silent %bwipe!
  44. endfunction
  45. function! Test_DocumentSymbols_Basic()
  46. call youcompleteme#test#setup#OpenFile(
  47. \ '/test/testdata/cpp/finder_test.cc', {} )
  48. let original_win = winnr()
  49. let b = bufnr()
  50. let l = winlayout()
  51. let popup_id = -1
  52. function! PutQuery( ... )
  53. " Wait for the current buffer to be a prompt buffer
  54. call WaitForAssert( { -> assert_equal( 'prompt', &buftype ) } )
  55. call WaitForAssert( { -> assert_equal( 'i', mode() ) } )
  56. call WaitForAssert( { -> assert_true(
  57. \ youcompleteme#finder#GetState().id != -1 ) } )
  58. " TODO: Wait for the popup to be displayed, and check the contents
  59. call FeedAndCheckAgain( 'xthisisathing', funcref( 'SelectItem' ) )
  60. endfunction
  61. function SelectItem( ... )
  62. let id = youcompleteme#finder#GetState().id
  63. call WaitForAssert( { ->
  64. \ assert_equal( ' [X] Search for symbol: xthisisathing ',
  65. \ popup_getoptions( id ).title ) },
  66. \ 10000 )
  67. call WaitForAssert( { -> assert_equal( 1, line( '$', id ) ) } )
  68. call feedkeys( "\<CR>" )
  69. endfunction
  70. " <Leader> is \ - this calls <Plug>(YCMFindSymbolInDocument)
  71. call FeedAndCheckMain( '\\d', funcref( 'PutQuery' ) )
  72. call WaitForAssert( { -> assert_equal( l, winlayout() ) } )
  73. call WaitForAssert( { -> assert_equal( original_win, winnr() ) } )
  74. call assert_equal( b, bufnr() )
  75. " NOTE: cland returns the position of the decl here not the identifier. This
  76. " is why it's position 3 not 7 as in the Test_WorkspaceSymbol_Basic
  77. call assert_equal( [ 0, 5, 3, 0 ], getpos( '.' ) )
  78. delfunct PutQuery
  79. delfunct SelectItem
  80. silent %bwipe!
  81. endfunction
  82. function! Test_Cancel_DocumentSymbol()
  83. call youcompleteme#test#setup#OpenFile(
  84. \ '/test/testdata/cpp/finder_test.cc', {} )
  85. let original_win = winnr()
  86. let b = bufnr()
  87. let l = winlayout()
  88. " Jump to a different position so that we can ensure we return to the same
  89. " place
  90. normal! G
  91. let p = getpos( '.' )
  92. let popup_id = -1
  93. function! PutQuery( ... )
  94. " Wait for the current buffer to be a prompt buffer
  95. call WaitForAssert( { -> assert_equal( 'prompt', &buftype ) } )
  96. call WaitForAssert( { -> assert_equal( 'i', mode() ) } )
  97. call WaitForAssert( { -> assert_true(
  98. \ youcompleteme#finder#GetState().id != -1 ) } )
  99. call FeedAndCheckAgain( 'xthisisathing', funcref( 'SelectItem' ) )
  100. endfunction
  101. function SelectItem( ... )
  102. let id = youcompleteme#finder#GetState().id
  103. call WaitForAssert( { ->
  104. \ assert_equal( ' [X] Search for symbol: xthisisathing ',
  105. \ popup_getoptions( id ).title ) },
  106. \ 10000 )
  107. call WaitForAssert( { -> assert_equal( 1, line( '$', id ) ) } )
  108. " Cancel - this should stopinsert
  109. call feedkeys( "\<C-c>" )
  110. endfunction
  111. " <Leader> is \ - this calls <Plug>(YCMFindSymbolInDocument)
  112. call FeedAndCheckMain( '\\d', funcref( 'PutQuery' ) )
  113. call WaitForAssert( { -> assert_equal( l, winlayout() ) } )
  114. call WaitForAssert( { -> assert_equal( original_win, winnr() ) } )
  115. call assert_equal( b, bufnr() )
  116. " Retuned to just where we started
  117. call assert_equal( p, getpos( '.' ) )
  118. delfunct PutQuery
  119. delfunct SelectItem
  120. silent %bwipe!
  121. endfunction
  122. function! Test_EmptySearch()
  123. call youcompleteme#test#setup#OpenFile(
  124. \ '/test/testdata/cpp/finder_test.cc', {} )
  125. let original_win = winnr()
  126. let b = bufnr()
  127. let l = winlayout()
  128. let popup_id = -1
  129. function! PutQuery( ... )
  130. " Wait for the current buffer to be a prompt buffer
  131. call WaitForAssert( { -> assert_equal( 'prompt', &buftype ) } )
  132. call WaitForAssert( { -> assert_equal( 'i', mode() ) } )
  133. call WaitForAssert( { -> assert_true(
  134. \ youcompleteme#finder#GetState().id != -1 ) } )
  135. " TODO: Wait for the popup to be displayed, and check the contents
  136. call FeedAndCheckAgain( 'xnothingshouldmatchthisx',
  137. \ funcref( 'SelectNothing' ) )
  138. endfunction
  139. function SelectNothing( ... )
  140. let id = youcompleteme#finder#GetState().id
  141. call WaitForAssert( { ->
  142. \ assert_equal( ' [X] Search for symbol: xnothingshouldmatchthisx ',
  143. \ popup_getoptions( id ).title ) },
  144. \ 10000 )
  145. call WaitForAssert( { -> assert_equal( 1, line( '$', id ) ) } )
  146. call assert_equal( 'No results', getbufline( winbufnr( id ), '$' )[ 0 ] )
  147. call FeedAndCheckAgain( "\<CR>xnotarealthingx",
  148. \ funcref( 'ChangeSearch' ) )
  149. endfunction
  150. function ChangeSearch( ... )
  151. let id = youcompleteme#finder#GetState().id
  152. " Hitting enter with nothing to select clears the prompt, because prompt
  153. " buffer
  154. call WaitForAssert( { ->
  155. \ assert_equal( ' [X] Search for symbol: xnotarealthingx ',
  156. \ popup_getoptions( id ).title ) },
  157. \ 10000 )
  158. call assert_equal( 'No results', getbufline( winbufnr( id ), '$' )[ 0 ] )
  159. call assert_equal( -1, youcompleteme#finder#GetState().selected )
  160. call FeedAndCheckAgain( "\<C-u>xtiat", funcref( 'TestUpDownSelect' ) )
  161. endfunction
  162. let popup_id = -1
  163. function TestUpDownSelect( ... ) closure
  164. let popup_id = youcompleteme#finder#GetState().id
  165. call WaitForAssert( { ->
  166. \ assert_equal( ' [X] Search for symbol: xtiat ',
  167. \ popup_getoptions( popup_id ).title ) },
  168. \ 10000 )
  169. call WaitForAssert( { -> assert_equal( 2, line( '$', popup_id ) ) } )
  170. " FIXME: Doing all these tests with only 2 entries means that it's not
  171. " really checking the behaviour completely accurately, we should at least
  172. " use 3, but that would require crafting a new test file, which is nonzero
  173. " effort. Well, it's probably as much effort as writing this comment...
  174. " Check down movement
  175. call assert_equal( 0, youcompleteme#finder#GetState().selected )
  176. call assert_equal( 'x_this_is_a_thing',
  177. \ youcompleteme#finder#GetState().results[
  178. \ youcompleteme#finder#GetState().selected ].extra_data.name )
  179. call feedkeys( "\<C-j>", 'xt' )
  180. call assert_equal( 1, youcompleteme#finder#GetState().selected )
  181. call assert_equal( 'x_that_is_a_thing',
  182. \ youcompleteme#finder#GetState().results[
  183. \ youcompleteme#finder#GetState().selected ].extra_data.name )
  184. call feedkeys( "\<Down>", 'xt' )
  185. call assert_equal( 0, youcompleteme#finder#GetState().selected )
  186. call assert_equal( 'x_this_is_a_thing',
  187. \ youcompleteme#finder#GetState().results[
  188. \ youcompleteme#finder#GetState().selected ].extra_data.name )
  189. call feedkeys( "\<Tab>", 'xt' )
  190. call assert_equal( 1, youcompleteme#finder#GetState().selected )
  191. call assert_equal( 'x_that_is_a_thing',
  192. \ youcompleteme#finder#GetState().results[
  193. \ youcompleteme#finder#GetState().selected ].extra_data.name )
  194. call feedkeys( "\<C-n>", 'xt' )
  195. call assert_equal( 0, youcompleteme#finder#GetState().selected )
  196. call assert_equal( 'x_this_is_a_thing',
  197. \ youcompleteme#finder#GetState().results[
  198. \ youcompleteme#finder#GetState().selected ].extra_data.name )
  199. " Check up movement and wrapping
  200. call feedkeys( "\<C-k>", 'xt' )
  201. call assert_equal( 1, youcompleteme#finder#GetState().selected )
  202. call assert_equal( 'x_that_is_a_thing',
  203. \ youcompleteme#finder#GetState().results[
  204. \ youcompleteme#finder#GetState().selected ].extra_data.name )
  205. call feedkeys( "\<Up>", 'xt' )
  206. call assert_equal( 0, youcompleteme#finder#GetState().selected )
  207. call assert_equal( 'x_this_is_a_thing',
  208. \ youcompleteme#finder#GetState().results[
  209. \ youcompleteme#finder#GetState().selected ].extra_data.name )
  210. call feedkeys( "\<S-Tab>", 'xt' )
  211. call assert_equal( 1, youcompleteme#finder#GetState().selected )
  212. call assert_equal( 'x_that_is_a_thing',
  213. \ youcompleteme#finder#GetState().results[
  214. \ youcompleteme#finder#GetState().selected ].extra_data.name )
  215. call feedkeys( "\<C-p>", 'xt' )
  216. call assert_equal( 0, youcompleteme#finder#GetState().selected )
  217. call assert_equal( 'x_this_is_a_thing',
  218. \ youcompleteme#finder#GetState().results[
  219. \ youcompleteme#finder#GetState().selected ].extra_data.name )
  220. call feedkeys( "\<Tab>", 'xt' )
  221. call assert_equal( 1, youcompleteme#finder#GetState().selected )
  222. call assert_equal( 'x_that_is_a_thing',
  223. \ youcompleteme#finder#GetState().results[
  224. \ youcompleteme#finder#GetState().selected ].extra_data.name )
  225. call feedkeys( "\<Home>", 'xt' )
  226. call assert_equal( 0, youcompleteme#finder#GetState().selected )
  227. call assert_equal( 'x_this_is_a_thing',
  228. \ youcompleteme#finder#GetState().results[
  229. \ youcompleteme#finder#GetState().selected ].extra_data.name )
  230. call feedkeys( "\<End>", 'xt' )
  231. call assert_equal( 1, youcompleteme#finder#GetState().selected )
  232. call assert_equal( 'x_that_is_a_thing',
  233. \ youcompleteme#finder#GetState().results[
  234. \ youcompleteme#finder#GetState().selected ].extra_data.name )
  235. call feedkeys( "\<End>", 'xt' )
  236. call assert_equal( 1, youcompleteme#finder#GetState().selected )
  237. call assert_equal( 'x_that_is_a_thing',
  238. \ youcompleteme#finder#GetState().results[
  239. \ youcompleteme#finder#GetState().selected ].extra_data.name )
  240. call feedkeys( "\<PageUp>", 'xt' )
  241. call assert_equal( 0, youcompleteme#finder#GetState().selected )
  242. call assert_equal( 'x_this_is_a_thing',
  243. \ youcompleteme#finder#GetState().results[
  244. \ youcompleteme#finder#GetState().selected ].extra_data.name )
  245. call feedkeys( "\<PageDown>", 'xt' )
  246. call assert_equal( 1, youcompleteme#finder#GetState().selected )
  247. call assert_equal( 'x_that_is_a_thing',
  248. \ youcompleteme#finder#GetState().results[
  249. \ youcompleteme#finder#GetState().selected ].extra_data.name )
  250. call feedkeys( "\<CR>" )
  251. endfunction
  252. " <Leader> is \ - this calls <Plug>(YCMFindSymbolInWorkspace)
  253. call FeedAndCheckMain( '\\w', funcref( 'PutQuery' ) )
  254. call WaitForAssert( { -> assert_equal( {}, popup_getpos( popup_id ) ) } )
  255. call WaitForAssert( { -> assert_equal( l, winlayout() ) } )
  256. call WaitForAssert( { -> assert_equal( original_win, winnr() ) } )
  257. call assert_equal( b, bufnr() )
  258. call assert_equal( [ 0, 5, 30, 0 ], getpos( '.' ) )
  259. " We pop up a notification with some text in it
  260. if exists( '*popup_list' )
  261. call assert_equal( 1, len( popup_list() ) )
  262. endif
  263. " Old vim doesn't have popup_list, so hit-test the top-right corner which is
  264. " where we pup the popu
  265. let notification_id = popup_locate( 1, &columns - 1 )
  266. call assert_equal( [ 'Added 2 entries to quickfix list.' ],
  267. \ getbufline( winbufnr( notification_id ), 1, '$' ) )
  268. " Wait for the notification to clear
  269. call WaitForAssert(
  270. \ { -> assert_equal( {}, popup_getpos( notification_id ) ) },
  271. \ 10000 )
  272. delfunct PutQuery
  273. delfunct SelectNothing
  274. delfunct ChangeSearch
  275. delfunct TestUpDownSelect
  276. silent %bwipe!
  277. endfunction
  278. function! Test_LeaveWindow_CancelSearch()
  279. call youcompleteme#test#setup#OpenFile(
  280. \ '/test/testdata/cpp/finder_test.cc', {} )
  281. let original_win = winnr()
  282. let b = bufnr()
  283. let l = winlayout()
  284. " Jump to a different position so that we can ensure we return to the same
  285. " place
  286. normal! G
  287. let p = getpos( '.' )
  288. let popup_id = -1
  289. function! PutQuery( ... )
  290. " Wait for the current buffer to be a prompt buffer
  291. call WaitForAssert( { -> assert_equal( 'prompt', &buftype ) } )
  292. call WaitForAssert( { -> assert_equal( 'i', mode() ) } )
  293. call WaitForAssert( { -> assert_true(
  294. \ youcompleteme#finder#GetState().id != -1 ) } )
  295. call feedkeys( "\<C-w>w" )
  296. endfunction
  297. " <Leader> is \ - this calls <Plug>(YCMFindSymbolInWorkspace)
  298. call FeedAndCheckMain( '\\w', funcref( 'PutQuery' ) )
  299. call WaitForAssert( { -> assert_equal( l, winlayout() ) } )
  300. call WaitForAssert( { -> assert_equal( original_win, winnr() ) } )
  301. call assert_equal( b, bufnr() )
  302. " Retuned to just where we started
  303. call assert_equal( p, getpos( '.' ) )
  304. " No notifiaction
  305. if exists( '*popup_list' )
  306. call assert_equal( 0, len( popup_list() ) )
  307. endif
  308. delfunct PutQuery
  309. silent %bwipe!
  310. endfunction
  311. function! SetUp_Test_NoFileType_NoCompletionIn_PromptBuffer()
  312. call youcompleteme#test#setup#PushGlobal( 'ycm_filetype_whitelist', {
  313. \ '*': 1,
  314. \ 'ycm_nofiletype': 1
  315. \ } )
  316. endfunction
  317. function! TearDown_Test_NoFileType_NoCompletionIn_PromptBuffer()
  318. call youcompleteme#test#setup#PopGlobal( 'ycm_filetype_whitelist' )
  319. endfunction
  320. function! Test_NoFileType_NoCompletionIn_PromptBuffer()
  321. call youcompleteme#test#setup#OpenFile(
  322. \ '/test/testdata/cpp/finder_test.cc', {} )
  323. call test_override( 'char_avail', 1 )
  324. new
  325. call feedkeys(
  326. \ 'iThis is some text and so is xthisisathing x_this_is_a_thing',
  327. \ 'xt' )
  328. wincmd w
  329. let original_win = winnr()
  330. let b = bufnr()
  331. let l = winlayout()
  332. let popup_id = -1
  333. function! PutQuery( ... )
  334. " Wait for the current buffer to be a prompt buffer
  335. call WaitForAssert( { -> assert_equal( 'prompt', &buftype ) } )
  336. call WaitForAssert( { -> assert_equal( 'i', mode() ) } )
  337. call WaitForAssert( { -> assert_true(
  338. \ youcompleteme#finder#GetState().id != -1 ) } )
  339. " TODO: Wait for the popup to be displayed, and check the contents
  340. call FeedAndCheckAgain( 'xthisisathing', funcref( 'CheckNoPopup' ) )
  341. endfunction
  342. function! CheckNoPopup( ... )
  343. let id = youcompleteme#finder#GetState().id
  344. call WaitForAssert( { ->
  345. \ assert_equal( ' [X] Search for symbol: xthisisathing ',
  346. \ popup_getoptions( id ).title ) },
  347. \ 10000 )
  348. call WaitForAssert( { -> assert_equal( 1, line( '$', id ) ) } )
  349. call assert_equal( 'x_this_is_a_thing',
  350. \ youcompleteme#finder#GetState().results[
  351. \ youcompleteme#finder#GetState().selected ].extra_data.name )
  352. " Check there is no PUM - we disable completion in the prompt buffer
  353. call assert_false( pumvisible() )
  354. call feedkeys( "\<CR>" )
  355. endfunction
  356. " <Leader> is \ - this calls <Plug>(YCMFindSymbolInWorkspace)
  357. call FeedAndCheckMain( '\\w', funcref( 'PutQuery' ) )
  358. call WaitForAssert( { -> assert_equal( l, winlayout() ) } )
  359. call WaitForAssert( { -> assert_equal( original_win, winnr() ) } )
  360. call assert_equal( b, bufnr() )
  361. call assert_equal( [ 0, 5, 7, 0 ], getpos( '.' ) )
  362. call test_override( 'ALL', 0 )
  363. silent %bwipe!
  364. delfunct! PutQuery
  365. delfunct! CheckNoPopup
  366. endfunction
  367. " function! Test_MultipleFileTypes()
  368. " call youcompleteme#test#setup#OpenFile(
  369. " \ '/test/testdata/cpp/finder_test.cc', {} )
  370. " split
  371. " call youcompleteme#test#setup#OpenFile( '/test/testdata/python/doc.py', {} )
  372. " wincmd w
  373. "
  374. " let original_win = winnr()
  375. " let b = bufnr()
  376. " let l = winlayout()
  377. "
  378. " function! PutQuery( ... )
  379. " " Wait for the current buffer to be a prompt buffer
  380. " call WaitForAssert( { -> assert_equal( 'prompt', &buftype ) } )
  381. " call WaitForAssert( { -> assert_equal( 'i', mode() ) } )
  382. "
  383. " let popup_id = youcompleteme#finder#GetState().id
  384. " call WaitForAssert( { ->
  385. " \ assert_equal( ' [X] Search for symbol: thiswillnotmatchanything ',
  386. " \ popup_getoptions( popup_id ).title ) },
  387. " \ 10000 )
  388. "
  389. "
  390. " call WaitForAssert( { -> assert_true(
  391. " \ youcompleteme#finder#GetState().id != -1 ) } )
  392. "
  393. " let id = youcompleteme#finder#GetState().id
  394. " call assert_equal( 'No results', getbufline( winbufnr( id ), '$' )[ 0 ] )
  395. " call FeedAndCheckAgain( "\<C-u>xthisisathing", funcref( 'CheckCpp' ) )
  396. " endfunction
  397. "
  398. " function! CheckCpp( ... )
  399. " let popup_id = youcompleteme#finder#GetState().id
  400. "
  401. " " Python can be _really_ slow
  402. " call WaitForAssert( { ->
  403. " \ assert_equal( ' [X] Search for symbol: xthisisathing ',
  404. " \ popup_getoptions( popup_id ).title ) },
  405. " \ 10000 )
  406. "
  407. " call WaitForAssert( { -> assert_equal( 1, line( '$', popup_id ) ) } )
  408. " call assert_equal( 0, youcompleteme#finder#GetState().selected )
  409. " call assert_equal( 'x_this_is_a_thing',
  410. " \ youcompleteme#finder#GetState().results[
  411. " \ youcompleteme#finder#GetState().selected ].extra_data.name )
  412. "
  413. " " Wait for the current buffer to be a prompt buffer
  414. " call WaitForAssert( { -> assert_equal( 'prompt', &buftype ) } )
  415. " call WaitForAssert( { -> assert_equal( 'i', mode() ) } )
  416. "
  417. " call FeedAndCheckAgain(
  418. " \ "\<C-u>Really_Long_Method",
  419. " \ funcref( 'CheckPython' ) )
  420. " endfunction
  421. "
  422. " function! CheckPython( ... )
  423. " let popup_id = youcompleteme#finder#GetState().id
  424. "
  425. " " Python can be _really_ slow
  426. " call WaitForAssert( { ->
  427. " \ assert_equal( ' [X] Search for symbol: Really_Long_Method ',
  428. " \ popup_getoptions( popup_id ).title ) },
  429. " \ 20000 )
  430. "
  431. " call WaitForAssert( { -> assert_equal( 2, line( '$', popup_id ) ) },
  432. " \ 20000 )
  433. " call WaitForAssert( { ->
  434. " \ assert_equal( 0, youcompleteme#finder#GetState().selected )
  435. " \ },
  436. " \ 20000 )
  437. " call assert_equal( 'def Really_Long_Method',
  438. " \ youcompleteme#finder#GetState().results[
  439. " \ youcompleteme#finder#GetState().selected ].description )
  440. "
  441. " " Toggle single-filetype mode
  442. " call FeedAndCheckAgain( "\<C-f>", funcref( 'CheckCppAgain' ) )
  443. " endfunction
  444. "
  445. " function! CheckCppAgain( ... )
  446. " let popup_id = youcompleteme#finder#GetState().id
  447. "
  448. " " Python can be _really_ slow
  449. " call WaitForAssert( { ->
  450. " \ assert_equal( ' [X] Search for symbol: Really_Long_Method ',
  451. " \ popup_getoptions( popup_id ).title ) },
  452. " \ 20000 )
  453. "
  454. " call WaitForAssert( { -> assert_true(
  455. " \ youcompleteme#finder#GetState().id != -1 ) } )
  456. "
  457. " let id = youcompleteme#finder#GetState().id
  458. " call assert_equal( 'No results', getbufline( winbufnr( id ), '$' )[ 0 ] )
  459. "
  460. " " And back to multiple filetypes
  461. " call FeedAndCheckAgain( "\<C-f>", funcref( 'CheckPythonAgain' ) )
  462. " endfunction
  463. "
  464. " function! CheckPythonAgain( ... )
  465. " let popup_id = youcompleteme#finder#GetState().id
  466. "
  467. " " Python can be _really_ slow
  468. " call WaitForAssert( { ->
  469. " \ assert_equal( ' [X] Search for symbol: Really_Long_Method ',
  470. " \ popup_getoptions( popup_id ).title ) },
  471. " \ 20000 )
  472. "
  473. " call WaitForAssert( { -> assert_equal( 2, line( '$', popup_id ) ) },
  474. " \ 20000 )
  475. " call assert_equal( 0, youcompleteme#finder#GetState().selected )
  476. " call assert_equal( 'def Really_Long_Method',
  477. " \ youcompleteme#finder#GetState().results[
  478. " \ youcompleteme#finder#GetState().selected ].description )
  479. "
  480. " call feedkeys( "\<C-c>" )
  481. " endfunction
  482. "
  483. "
  484. " " <Leader> is \ - this calls <Plug>(YCMFindSymbolInWorkspace)
  485. " call FeedAndCheckMain( '\\wthiswillnotmatchanything', funcref( 'PutQuery' ) )
  486. "
  487. " call WaitForAssert( { -> assert_equal( l, winlayout() ) } )
  488. " call WaitForAssert( { -> assert_equal( original_win, winnr() ) } )
  489. " call assert_equal( b, bufnr() )
  490. " endfunction
  491. "
  492. " function! Test_MultipleFileTypes_CurrentNotSemantic()
  493. " call youcompleteme#test#setup#OpenFile(
  494. " \ '/test/testdata/cpp/finder_test.cc', {} )
  495. " split
  496. " call youcompleteme#test#setup#OpenFile( '/test/testdata/python/doc.py', {} )
  497. " split
  498. " " Current buffer is a ycm_nofiletype, which ycm is blacklisted in
  499. " " but otherwise we behave the same as before with the exception that we open
  500. " " the python file in the current window
  501. "
  502. " let original_win = winnr()
  503. " let b = bufnr()
  504. " let l = winlayout()
  505. "
  506. " function! PutQuery( ... )
  507. " " Wait for the current buffer to be a prompt buffer
  508. " call WaitForAssert( { -> assert_equal( 'prompt', &buftype ) } )
  509. " call WaitForAssert( { -> assert_equal( 'i', mode() ) } )
  510. "
  511. " call WaitForAssert( { -> assert_true(
  512. " \ youcompleteme#finder#GetState().id != -1 ) } )
  513. "
  514. " let popup_id = youcompleteme#finder#GetState().id
  515. " call WaitForAssert( { ->
  516. " \ assert_equal( ' [X] Search for symbol: thiswillnotmatchanything ',
  517. " \ popup_getoptions( popup_id ).title ) },
  518. " \ 10000 )
  519. "
  520. "
  521. " let id = youcompleteme#finder#GetState().id
  522. " call assert_equal( 'No results', getbufline( winbufnr( id ), '$' )[ 0 ] )
  523. " call FeedAndCheckAgain( "\<C-u>xthisisathing", funcref( 'CheckCpp' ) )
  524. " endfunction
  525. "
  526. " function! CheckCpp( ... )
  527. " let popup_id = youcompleteme#finder#GetState().id
  528. "
  529. " " Python can be _really_ slow
  530. " call WaitForAssert( { ->
  531. " \ assert_equal( ' [X] Search for symbol: xthisisathing ',
  532. " \ popup_getoptions( popup_id ).title ) },
  533. " \ 10000 )
  534. "
  535. " call WaitForAssert( { -> assert_equal( 1, line( '$', popup_id ) ) } )
  536. " call assert_equal( 0, youcompleteme#finder#GetState().selected )
  537. " call assert_equal( 'x_this_is_a_thing',
  538. " \ youcompleteme#finder#GetState().results[
  539. " \ youcompleteme#finder#GetState().selected ].extra_data.name )
  540. "
  541. " " Wait for the current buffer to be a prompt buffer
  542. " call WaitForAssert( { -> assert_equal( 'prompt', &buftype ) } )
  543. " call WaitForAssert( { -> assert_equal( 'i', mode() ) } )
  544. "
  545. " call FeedAndCheckAgain(
  546. " \ "\<C-u>Really_Long_Method",
  547. " \ funcref( 'CheckPython' ) )
  548. " endfunction
  549. "
  550. " function! CheckPython( ... )
  551. " let popup_id = youcompleteme#finder#GetState().id
  552. "
  553. " " Python can be _really_ slow
  554. " call WaitForAssert( { ->
  555. " \ assert_equal( ' [X] Search for symbol: Really_Long_Method ',
  556. " \ popup_getoptions( popup_id ).title ) },
  557. " \ 10000 )
  558. "
  559. " call WaitForAssert( { -> assert_equal( 2, line( '$', popup_id ) ) },
  560. " \ 10000 )
  561. " call assert_equal( 0, youcompleteme#finder#GetState().selected )
  562. " call assert_equal( 'def Really_Long_Method',
  563. " \ youcompleteme#finder#GetState().results[
  564. " \ youcompleteme#finder#GetState().selected ].description )
  565. "
  566. " call feedkeys( "\<CR>")
  567. " endfunction
  568. "
  569. "
  570. " " <Leader> is \ - this calls <Plug>(YCMFindSymbolInWorkspace)
  571. " call FeedAndCheckMain( '\\wthiswillnotmatchanything', funcref( 'PutQuery' ) )
  572. "
  573. " " We pop up a notification with some text in it
  574. " if exists( '*popup_list' )
  575. " call assert_equal( 1, len( popup_list() ) )
  576. " endif
  577. "
  578. " " Old vim doesn't have popup_list, so hit-test the top-right corner which is
  579. " " where we pup the popu
  580. " let notification_id = popup_locate( 1, &columns - 1 )
  581. " call assert_equal( [ 'Added 2 entries to quickfix list.' ],
  582. " \ getbufline( winbufnr( notification_id ), 1, '$' ) )
  583. " " Wait for the notification to clear
  584. " call WaitForAssert(
  585. " \ { -> assert_equal( {}, popup_getpos( notification_id ) ) },
  586. " \ 10000 )
  587. "
  588. " call WaitForAssert( { -> assert_equal( l, winlayout() ) } )
  589. " call WaitForAssert( { -> assert_equal( original_win, winnr() ) } )
  590. " call assert_equal( bufnr( 'doc.py' ), bufnr() )
  591. " call assert_equal( [ 0, 16, 5, 0 ], getpos( '.' ) )
  592. " endfunction
  593. "
  594. " function! Test_WorkspaceSymbol_NormalModeChange()
  595. " call youcompleteme#test#setup#OpenFile(
  596. " \ '/test/testdata/cpp/finder_test.cc', {} )
  597. "
  598. " let original_win = winnr()
  599. " let b = bufnr()
  600. " let l = winlayout()
  601. "
  602. " let popup_id = -1
  603. "
  604. " function! PutQuery( ... )
  605. " " Wait for the current buffer to be a prompt buffer
  606. " call WaitForAssert( { -> assert_equal( 'prompt', &buftype ) } )
  607. " call WaitForAssert( { -> assert_equal( 'i', mode() ) } )
  608. "
  609. " call WaitForAssert( { -> assert_true(
  610. " \ youcompleteme#finder#GetState().id != -1 ) } )
  611. "
  612. " let popup_id = youcompleteme#finder#GetState().id
  613. " call WaitForAssert( { ->
  614. " \ assert_equal( ' [X] Search for symbol: thiswillnotmatchanything ',
  615. " \ popup_getoptions( popup_id ).title ) },
  616. " \ 10000 )
  617. "
  618. " let id = youcompleteme#finder#GetState().id
  619. " call assert_equal( 'No results', getbufline( winbufnr( id ), '$' )[ 0 ] )
  620. " call FeedAndCheckAgain( "\<C-u>xthisisathing", funcref( 'ChangeQuery' ) )
  621. " endfunction
  622. "
  623. " function ChangeQuery( ... )
  624. " let id = youcompleteme#finder#GetState().id
  625. "
  626. " call WaitForAssert( { ->
  627. " \ assert_equal( ' [X] Search for symbol: xthisisathing ',
  628. " \ popup_getoptions( id ).title ) },
  629. " \ 10000 )
  630. "
  631. " call WaitForAssert( { -> assert_equal( 1, line( '$', id ) ) } )
  632. " call assert_equal( 0, youcompleteme#finder#GetState().selected )
  633. " call assert_equal( 'x_this_is_a_thing',
  634. " \ youcompleteme#finder#GetState().results[
  635. " \ youcompleteme#finder#GetState().selected ].extra_data.name )
  636. "
  637. " " Wait for the current buffer to be a prompt buffer
  638. " call WaitForAssert( { -> assert_equal( 'prompt', &buftype ) } )
  639. " call WaitForAssert( { -> assert_equal( 'i', mode() ) } )
  640. "
  641. " call FeedAndCheckAgain( "\<Esc>bcwthatisathing",
  642. " \ funcref( 'SelectNewItem' ) )
  643. " endfunction
  644. "
  645. " function SelectNewItem( ... )
  646. " let id = youcompleteme#finder#GetState().id
  647. "
  648. " call WaitForAssert( { ->
  649. " \ assert_equal( ' [X] Search for symbol: thatisathing ',
  650. " \ popup_getoptions( id ).title ) },
  651. " \ 10000 )
  652. "
  653. " call WaitForAssert( { -> assert_equal( 1, line( '$', id ) ) } )
  654. " call assert_equal( 0, youcompleteme#finder#GetState().selected )
  655. " call assert_equal( 'x_that_is_a_thing',
  656. " \ youcompleteme#finder#GetState().results[
  657. " \ youcompleteme#finder#GetState().selected ].extra_data.name )
  658. "
  659. " call feedkeys( "\<CR>" )
  660. " endfunction
  661. "
  662. " " <Leader> is \ - this calls <Plug>(YCMFindSymbolInWorkspace)
  663. " call FeedAndCheckMain( '\\wthiswillnotmatchanything', funcref( 'PutQuery' ) )
  664. "
  665. " call WaitForAssert( { -> assert_equal( l, winlayout() ) } )
  666. " call WaitForAssert( { -> assert_equal( original_win, winnr() ) } )
  667. " call assert_equal( b, bufnr() )
  668. " call assert_equal( [ 0, 5, 28, 0 ], getpos( '.' ) )
  669. "
  670. " delfunct PutQuery
  671. " delfunct SelectNewItem
  672. " delfunct ChangeQuery
  673. " silent %bwipe!
  674. " endfunction