omni_completer_test.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. # encoding: utf-8
  2. #
  3. # Copyright (C) 2016-2018 YouCompleteMe contributors
  4. #
  5. # This file is part of YouCompleteMe.
  6. #
  7. # YouCompleteMe is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # YouCompleteMe is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
  19. from __future__ import unicode_literals
  20. from __future__ import print_function
  21. from __future__ import division
  22. from __future__ import absolute_import
  23. # Not installing aliases from python-future; it's unreliable and slow.
  24. from builtins import * # noqa
  25. from hamcrest import assert_that, contains, empty, has_entries
  26. from ycm.tests.test_utils import ( MockVimBuffers, MockVimModule, ToBytesOnPY2,
  27. VimBuffer )
  28. MockVimModule()
  29. from ycm import vimsupport
  30. from ycm.tests import YouCompleteMeInstance
  31. FILETYPE = 'ycmtest'
  32. TRIGGERS = {
  33. 'ycmtest': [ '.' ]
  34. }
  35. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 1,
  36. 'g:ycm_semantic_triggers': TRIGGERS } )
  37. def OmniCompleter_GetCompletions_Cache_List_test( ycm ):
  38. def Omnifunc( findstart, base ):
  39. if findstart:
  40. return 5
  41. return [ 'a', 'b', 'cdef' ]
  42. current_buffer = VimBuffer( 'buffer',
  43. contents = [ 'test.' ],
  44. filetype = FILETYPE,
  45. omnifunc = Omnifunc )
  46. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 5 ) ):
  47. ycm.SendCompletionRequest()
  48. assert_that(
  49. ycm.GetCompletionResponse(),
  50. has_entries( {
  51. 'completions': ToBytesOnPY2( [ 'a', 'b', 'cdef' ] ),
  52. 'completion_start_column': 6
  53. } )
  54. )
  55. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 1,
  56. 'g:ycm_semantic_triggers': TRIGGERS } )
  57. def OmniCompleter_GetCompletions_Cache_ListFilter_test( ycm ):
  58. def Omnifunc( findstart, base ):
  59. if findstart:
  60. return 5
  61. return [ 'a', 'b', 'cdef' ]
  62. current_buffer = VimBuffer( 'buffer',
  63. contents = [ 'test.t' ],
  64. filetype = FILETYPE,
  65. omnifunc = Omnifunc )
  66. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 6 ) ):
  67. ycm.SendCompletionRequest()
  68. assert_that(
  69. ycm.GetCompletionResponse(),
  70. has_entries( {
  71. 'completions': empty(),
  72. 'completion_start_column': 6
  73. } )
  74. )
  75. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 0,
  76. 'g:ycm_semantic_triggers': TRIGGERS } )
  77. def OmniCompleter_GetCompletions_NoCache_List_test( ycm ):
  78. def Omnifunc( findstart, base ):
  79. if findstart:
  80. return 5
  81. return [ 'a', 'b', 'cdef' ]
  82. current_buffer = VimBuffer( 'buffer',
  83. contents = [ 'test.' ],
  84. filetype = FILETYPE,
  85. omnifunc = Omnifunc )
  86. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 5 ) ):
  87. ycm.SendCompletionRequest()
  88. assert_that(
  89. ycm.GetCompletionResponse(),
  90. has_entries( {
  91. 'completions': ToBytesOnPY2( [ 'a', 'b', 'cdef' ] ),
  92. 'completion_start_column': 6
  93. } )
  94. )
  95. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 0,
  96. 'g:ycm_semantic_triggers': TRIGGERS } )
  97. def OmniCompleter_GetCompletions_NoCache_ListFilter_test( ycm ):
  98. def Omnifunc( findstart, base ):
  99. if findstart:
  100. return 5
  101. return [ 'a', 'b', 'cdef' ]
  102. current_buffer = VimBuffer( 'buffer',
  103. contents = [ 'test.t' ],
  104. filetype = FILETYPE,
  105. omnifunc = Omnifunc )
  106. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 6 ) ):
  107. ycm.SendCompletionRequest()
  108. # Actual result is that the results are not filtered, as we expect the
  109. # omnifunc or vim itself to do this filtering.
  110. assert_that(
  111. ycm.GetCompletionResponse(),
  112. has_entries( {
  113. 'completions': ToBytesOnPY2( [ 'a', 'b', 'cdef' ] ),
  114. 'completion_start_column': 6
  115. } )
  116. )
  117. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 0,
  118. 'g:ycm_semantic_triggers': TRIGGERS } )
  119. def OmniCompleter_GetCompletions_NoCache_UseFindStart_test( ycm ):
  120. def Omnifunc( findstart, base ):
  121. if findstart:
  122. return 0
  123. return [ 'a', 'b', 'cdef' ]
  124. current_buffer = VimBuffer( 'buffer',
  125. contents = [ 'test.t' ],
  126. filetype = FILETYPE,
  127. omnifunc = Omnifunc )
  128. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 6 ) ):
  129. ycm.SendCompletionRequest()
  130. # Actual result is that the results are not filtered, as we expect the
  131. # omnifunc or vim itself to do this filtering.
  132. assert_that(
  133. ycm.GetCompletionResponse(),
  134. has_entries( {
  135. 'completions': ToBytesOnPY2( [ 'a', 'b', 'cdef' ] ),
  136. 'completion_start_column': 1
  137. } )
  138. )
  139. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 1,
  140. 'g:ycm_semantic_triggers': TRIGGERS } )
  141. def OmniCompleter_GetCompletions_Cache_UseFindStart_test( ycm ):
  142. def Omnifunc( findstart, base ):
  143. if findstart:
  144. return 0
  145. return [ 'a', 'b', 'cdef' ]
  146. current_buffer = VimBuffer( 'buffer',
  147. contents = [ 'test.t' ],
  148. filetype = FILETYPE,
  149. omnifunc = Omnifunc )
  150. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 6 ) ):
  151. ycm.SendCompletionRequest()
  152. # There are no results because the query 'test.t' doesn't match any
  153. # candidate (and cache_omnifunc=1, so we FilterAndSortCandidates).
  154. assert_that(
  155. ycm.GetCompletionResponse(),
  156. has_entries( {
  157. 'completions': empty(),
  158. 'completion_start_column': 1
  159. } )
  160. )
  161. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 1,
  162. 'g:ycm_semantic_triggers': TRIGGERS } )
  163. def OmniCompleter_GetCompletions_Cache_Object_test( ycm ):
  164. def Omnifunc( findstart, base ):
  165. if findstart:
  166. return 5
  167. return { 'words': [ 'a', 'b', 'CDtEF' ] }
  168. current_buffer = VimBuffer( 'buffer',
  169. contents = [ 'test.t' ],
  170. filetype = FILETYPE,
  171. omnifunc = Omnifunc )
  172. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 6 ) ):
  173. ycm.SendCompletionRequest()
  174. assert_that(
  175. ycm.GetCompletionResponse(),
  176. has_entries( {
  177. 'completions': [ 'CDtEF' ],
  178. 'completion_start_column': 6
  179. } )
  180. )
  181. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 1,
  182. 'g:ycm_semantic_triggers': TRIGGERS } )
  183. def OmniCompleter_GetCompletions_Cache_ObjectList_test( ycm ):
  184. def Omnifunc( findstart, base ):
  185. if findstart:
  186. return 5
  187. return [
  188. {
  189. 'word': 'a',
  190. 'abbr': 'ABBR',
  191. 'menu': 'MENU',
  192. 'info': 'INFO',
  193. 'kind': 'K'
  194. },
  195. {
  196. 'word': 'test',
  197. 'abbr': 'ABBRTEST',
  198. 'menu': 'MENUTEST',
  199. 'info': 'INFOTEST',
  200. 'kind': 'T'
  201. }
  202. ]
  203. current_buffer = VimBuffer( 'buffer',
  204. contents = [ 'test.tt' ],
  205. filetype = FILETYPE,
  206. omnifunc = Omnifunc )
  207. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 7 ) ):
  208. ycm.SendCompletionRequest()
  209. assert_that(
  210. ycm.GetCompletionResponse(),
  211. has_entries( {
  212. 'completions': contains( {
  213. 'word': 'test',
  214. 'abbr': 'ABBRTEST',
  215. 'menu': 'MENUTEST',
  216. 'info': 'INFOTEST',
  217. 'kind': 'T'
  218. } ),
  219. 'completion_start_column': 6
  220. } )
  221. )
  222. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 0,
  223. 'g:ycm_semantic_triggers': TRIGGERS } )
  224. def OmniCompleter_GetCompletions_NoCache_ObjectList_test( ycm ):
  225. def Omnifunc( findstart, base ):
  226. if findstart:
  227. return 5
  228. return [
  229. {
  230. 'word': 'a',
  231. 'abbr': 'ABBR',
  232. 'menu': 'MENU',
  233. 'info': 'INFO',
  234. 'kind': 'K'
  235. },
  236. {
  237. 'word': 'test',
  238. 'abbr': 'ABBRTEST',
  239. 'menu': 'MENUTEST',
  240. 'info': 'INFOTEST',
  241. 'kind': 'T'
  242. }
  243. ]
  244. current_buffer = VimBuffer( 'buffer',
  245. contents = [ 'test.tt' ],
  246. filetype = FILETYPE,
  247. omnifunc = Omnifunc )
  248. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 7 ) ):
  249. ycm.SendCompletionRequest()
  250. # We don't filter the result - we expect the omnifunc to do that
  251. # based on the query we supplied (Note: that means no fuzzy matching!).
  252. assert_that(
  253. ycm.GetCompletionResponse(),
  254. has_entries( {
  255. 'completions': ToBytesOnPY2( [ {
  256. 'word': 'a',
  257. 'abbr': 'ABBR',
  258. 'menu': 'MENU',
  259. 'info': 'INFO',
  260. 'kind': 'K'
  261. }, {
  262. 'word': 'test',
  263. 'abbr': 'ABBRTEST',
  264. 'menu': 'MENUTEST',
  265. 'info': 'INFOTEST',
  266. 'kind': 'T'
  267. } ] ),
  268. 'completion_start_column': 6
  269. } )
  270. )
  271. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 1,
  272. 'g:ycm_semantic_triggers': TRIGGERS } )
  273. def OmniCompleter_GetCompletions_Cache_ObjectListObject_test( ycm ):
  274. def Omnifunc( findstart, base ):
  275. if findstart:
  276. return 5
  277. return { 'words': [
  278. {
  279. 'word': 'a',
  280. 'abbr': 'ABBR',
  281. 'menu': 'MENU',
  282. 'info': 'INFO',
  283. 'kind': 'K'
  284. },
  285. {
  286. 'word': 'test',
  287. 'abbr': 'ABBRTEST',
  288. 'menu': 'MENUTEST',
  289. 'info': 'INFOTEST',
  290. 'kind': 'T'
  291. }
  292. ] }
  293. current_buffer = VimBuffer( 'buffer',
  294. contents = [ 'test.tt' ],
  295. filetype = FILETYPE,
  296. omnifunc = Omnifunc )
  297. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 7 ) ):
  298. ycm.SendCompletionRequest()
  299. assert_that(
  300. ycm.GetCompletionResponse(),
  301. has_entries( {
  302. 'completions': ToBytesOnPY2( [ {
  303. 'word': 'test',
  304. 'abbr': 'ABBRTEST',
  305. 'menu': 'MENUTEST',
  306. 'info': 'INFOTEST',
  307. 'kind': 'T'
  308. } ] ),
  309. 'completion_start_column': 6
  310. } )
  311. )
  312. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 0,
  313. 'g:ycm_semantic_triggers': TRIGGERS } )
  314. def OmniCompleter_GetCompletions_NoCache_ObjectListObject_test( ycm ):
  315. def Omnifunc( findstart, base ):
  316. if findstart:
  317. return 5
  318. return { 'words': [
  319. {
  320. 'word': 'a',
  321. 'abbr': 'ABBR',
  322. 'menu': 'MENU',
  323. 'info': 'INFO',
  324. 'kind': 'K'
  325. },
  326. {
  327. 'word': 'test',
  328. 'abbr': 'ABBRTEST',
  329. 'menu': 'MENUTEST',
  330. 'info': 'INFOTEST',
  331. 'kind': 'T'
  332. }
  333. ] }
  334. current_buffer = VimBuffer( 'buffer',
  335. contents = [ 'test.tt' ],
  336. filetype = FILETYPE,
  337. omnifunc = Omnifunc )
  338. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 7 ) ):
  339. ycm.SendCompletionRequest()
  340. # No FilterAndSortCandidates for cache_omnifunc=0 (we expect the omnifunc
  341. # to do the filtering?)
  342. assert_that(
  343. ycm.GetCompletionResponse(),
  344. has_entries( {
  345. 'completions': ToBytesOnPY2( [ {
  346. 'word': 'a',
  347. 'abbr': 'ABBR',
  348. 'menu': 'MENU',
  349. 'info': 'INFO',
  350. 'kind': 'K'
  351. }, {
  352. 'word': 'test',
  353. 'abbr': 'ABBRTEST',
  354. 'menu': 'MENUTEST',
  355. 'info': 'INFOTEST',
  356. 'kind': 'T'
  357. } ] ),
  358. 'completion_start_column': 6
  359. } )
  360. )
  361. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 1,
  362. 'g:ycm_semantic_triggers': TRIGGERS } )
  363. def OmniCompleter_GetCompletions_Cache_List_Unicode_test( ycm ):
  364. def Omnifunc( findstart, base ):
  365. if findstart:
  366. return 12
  367. return [ '†est', 'å_unicode_identifier', 'πππππππ yummy πie' ]
  368. current_buffer = VimBuffer( 'buffer',
  369. contents = [ '†åsty_π.' ],
  370. filetype = FILETYPE,
  371. omnifunc = Omnifunc )
  372. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 12 ) ):
  373. ycm.SendCompletionRequest()
  374. assert_that(
  375. ycm.GetCompletionResponse(),
  376. has_entries( {
  377. 'completions': [ 'å_unicode_identifier',
  378. 'πππππππ yummy πie',
  379. '†est' ],
  380. 'completion_start_column': 13
  381. } )
  382. )
  383. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 0,
  384. 'g:ycm_semantic_triggers': TRIGGERS } )
  385. def OmniCompleter_GetCompletions_NoCache_List_Unicode_test( ycm ):
  386. def Omnifunc( findstart, base ):
  387. if findstart:
  388. return 12
  389. return [ '†est', 'å_unicode_identifier', 'πππππππ yummy πie' ]
  390. current_buffer = VimBuffer( 'buffer',
  391. contents = [ '†åsty_π.' ],
  392. filetype = FILETYPE,
  393. omnifunc = Omnifunc )
  394. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 12 ) ):
  395. ycm.SendCompletionRequest()
  396. assert_that(
  397. ycm.GetCompletionResponse(),
  398. has_entries( {
  399. 'completions': ToBytesOnPY2( [ '†est',
  400. 'å_unicode_identifier',
  401. 'πππππππ yummy πie' ] ),
  402. 'completion_start_column': 13
  403. } )
  404. )
  405. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 1,
  406. 'g:ycm_semantic_triggers': TRIGGERS } )
  407. def OmniCompleter_GetCompletions_Cache_List_Filter_Unicode_test( ycm ):
  408. def Omnifunc( findstart, base ):
  409. if findstart:
  410. return 12
  411. return [ '†est', 'å_unicode_identifier', 'πππππππ yummy πie' ]
  412. current_buffer = VimBuffer( 'buffer',
  413. contents = [ '†åsty_π.ππ' ],
  414. filetype = FILETYPE,
  415. omnifunc = Omnifunc )
  416. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 17 ) ):
  417. ycm.SendCompletionRequest()
  418. assert_that(
  419. ycm.GetCompletionResponse(),
  420. has_entries( {
  421. 'completions': [ 'πππππππ yummy πie' ],
  422. 'completion_start_column': 13
  423. } )
  424. )
  425. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 0,
  426. 'g:ycm_semantic_triggers': TRIGGERS } )
  427. def OmniCompleter_GetCompletions_NoCache_List_Filter_Unicode_test( ycm ):
  428. def Omnifunc( findstart, base ):
  429. if findstart:
  430. return 12
  431. return [ 'πππππππ yummy πie' ]
  432. current_buffer = VimBuffer( 'buffer',
  433. contents = [ '†åsty_π.ππ' ],
  434. filetype = FILETYPE,
  435. omnifunc = Omnifunc )
  436. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 17 ) ):
  437. ycm.SendCompletionRequest()
  438. assert_that(
  439. ycm.GetCompletionResponse(),
  440. has_entries( {
  441. 'completions': ToBytesOnPY2( [ 'πππππππ yummy πie' ] ),
  442. 'completion_start_column': 13
  443. } )
  444. )
  445. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 1,
  446. 'g:ycm_semantic_triggers': TRIGGERS } )
  447. def OmniCompleter_GetCompletions_Cache_ObjectList_Unicode_test( ycm ):
  448. def Omnifunc( findstart, base ):
  449. if findstart:
  450. return 12
  451. return [
  452. {
  453. 'word': 'ålpha∫et',
  454. 'abbr': 'å∫∫®',
  455. 'menu': 'µ´~¨á',
  456. 'info': '^~fo',
  457. 'kind': '˚'
  458. },
  459. {
  460. 'word': 'π†´ß†π',
  461. 'abbr': 'ÅııÂʉÍÊ',
  462. 'menu': '˜‰ˆËʉÍÊ',
  463. 'info': 'ȈÏØʉÍÊ',
  464. 'kind': 'Ê'
  465. }
  466. ]
  467. current_buffer = VimBuffer( 'buffer',
  468. contents = [ '†åsty_π.ππ' ],
  469. filetype = FILETYPE,
  470. omnifunc = Omnifunc )
  471. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 17 ) ):
  472. ycm.SendCompletionRequest()
  473. assert_that(
  474. ycm.GetCompletionResponse(),
  475. has_entries( {
  476. 'completions': [ {
  477. 'word': 'π†´ß†π',
  478. 'abbr': 'ÅııÂʉÍÊ',
  479. 'menu': '˜‰ˆËʉÍÊ',
  480. 'info': 'ȈÏØʉÍÊ',
  481. 'kind': 'Ê'
  482. } ],
  483. 'completion_start_column': 13
  484. } )
  485. )
  486. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 1,
  487. 'g:ycm_semantic_triggers': TRIGGERS } )
  488. def OmniCompleter_GetCompletions_Cache_ObjectListObject_Unicode_test( ycm ):
  489. def Omnifunc( findstart, base ):
  490. if findstart:
  491. return 12
  492. return {
  493. 'words': [
  494. {
  495. 'word': 'ålpha∫et',
  496. 'abbr': 'å∫∫®',
  497. 'menu': 'µ´~¨á',
  498. 'info': '^~fo',
  499. 'kind': '˚'
  500. },
  501. {
  502. 'word': 'π†´ß†π',
  503. 'abbr': 'ÅııÂʉÍÊ',
  504. 'menu': '˜‰ˆËʉÍÊ',
  505. 'info': 'ȈÏØʉÍÊ',
  506. 'kind': 'Ê'
  507. },
  508. {
  509. 'word': 'test',
  510. 'abbr': 'ÅııÂʉÍÊ',
  511. 'menu': '˜‰ˆËʉÍÊ',
  512. 'info': 'ȈÏØʉÍÊ',
  513. 'kind': 'Ê'
  514. }
  515. ]
  516. }
  517. current_buffer = VimBuffer( 'buffer',
  518. contents = [ '†åsty_π.t' ],
  519. filetype = FILETYPE,
  520. omnifunc = Omnifunc )
  521. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 13 ) ):
  522. ycm.SendCompletionRequest()
  523. assert_that(
  524. ycm.GetCompletionResponse(),
  525. has_entries( {
  526. 'completions': contains( {
  527. 'word': 'test',
  528. 'abbr': 'ÅııÂʉÍÊ',
  529. 'menu': '˜‰ˆËʉÍÊ',
  530. 'info': 'ȈÏØʉÍÊ',
  531. 'kind': 'Ê'
  532. }, {
  533. 'word': 'ålpha∫et',
  534. 'abbr': 'å∫∫®',
  535. 'menu': 'µ´~¨á',
  536. 'info': '^~fo',
  537. 'kind': '˚'
  538. } ),
  539. 'completion_start_column': 13
  540. } )
  541. )
  542. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 1,
  543. 'g:ycm_semantic_triggers': TRIGGERS } )
  544. def OmniCompleter_GetCompletions_RestoreCursorPositionAfterOmnifuncCall_test(
  545. ycm ):
  546. # This omnifunc moves the cursor to the test definition like
  547. # ccomplete#Complete would.
  548. def Omnifunc( findstart, base ):
  549. if findstart:
  550. return 5
  551. vimsupport.SetCurrentLineAndColumn( 0, 0 )
  552. return [ 'length' ]
  553. current_buffer = VimBuffer( 'buffer',
  554. contents = [ 'String test',
  555. '',
  556. 'test.' ],
  557. filetype = FILETYPE,
  558. omnifunc = Omnifunc )
  559. with MockVimBuffers( [ current_buffer ], current_buffer, ( 3, 5 ) ):
  560. ycm.SendCompletionRequest()
  561. assert_that(
  562. vimsupport.CurrentLineAndColumn(),
  563. contains( 2, 5 )
  564. )
  565. assert_that(
  566. ycm.GetCompletionResponse(),
  567. has_entries( {
  568. 'completions': ToBytesOnPY2( [ 'length' ] ),
  569. 'completion_start_column': 6
  570. } )
  571. )
  572. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 0,
  573. 'g:ycm_semantic_triggers': TRIGGERS } )
  574. def OmniCompleter_GetCompletions_NoCache_NoSemanticTrigger_test( ycm ):
  575. def Omnifunc( findstart, base ):
  576. if findstart:
  577. return 0
  578. return [ 'test' ]
  579. current_buffer = VimBuffer( 'buffer',
  580. contents = [ 'te' ],
  581. filetype = FILETYPE,
  582. omnifunc = Omnifunc )
  583. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 3 ) ):
  584. ycm.SendCompletionRequest()
  585. assert_that(
  586. ycm.GetCompletionResponse(),
  587. has_entries( {
  588. 'completions': empty(),
  589. 'completion_start_column': 1
  590. } )
  591. )
  592. @YouCompleteMeInstance( { 'g:ycm_cache_omnifunc': 0,
  593. 'g:ycm_semantic_triggers': TRIGGERS } )
  594. def OmniCompleter_GetCompletions_NoCache_ForceSemantic_test( ycm ):
  595. def Omnifunc( findstart, base ):
  596. if findstart:
  597. return 0
  598. return [ 'test' ]
  599. current_buffer = VimBuffer( 'buffer',
  600. contents = [ 'te' ],
  601. filetype = FILETYPE,
  602. omnifunc = Omnifunc )
  603. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 3 ) ):
  604. ycm.SendCompletionRequest( force_semantic = True )
  605. assert_that(
  606. ycm.GetCompletionResponse(),
  607. has_entries( {
  608. 'completions': ToBytesOnPY2( [ 'test' ] ),
  609. 'completion_start_column': 1
  610. } )
  611. )
  612. @YouCompleteMeInstance( {
  613. 'g:ycm_cache_omnifunc': 0,
  614. 'g:ycm_filetype_specific_completion_to_disable': { FILETYPE: 1 },
  615. 'g:ycm_semantic_triggers': TRIGGERS } )
  616. def OmniCompleter_GetCompletions_FiletypeDisabled_SemanticTrigger_test( ycm ):
  617. def Omnifunc( findstart, base ):
  618. if findstart:
  619. return 5
  620. return [ 'a', 'b', 'cdef' ]
  621. current_buffer = VimBuffer( 'buffer',
  622. contents = [ 'test.' ],
  623. filetype = FILETYPE,
  624. omnifunc = Omnifunc )
  625. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 6 ) ):
  626. ycm.SendCompletionRequest()
  627. assert_that(
  628. ycm.GetCompletionResponse(),
  629. has_entries( {
  630. 'completions': empty(),
  631. 'completion_start_column': 6
  632. } )
  633. )
  634. @YouCompleteMeInstance( {
  635. 'g:ycm_cache_omnifunc': 0,
  636. 'g:ycm_filetype_specific_completion_to_disable': { '*': 1 },
  637. 'g:ycm_semantic_triggers': TRIGGERS } )
  638. def OmniCompleter_GetCompletions_AllFiletypesDisabled_SemanticTrigger_test(
  639. ycm ):
  640. def Omnifunc( findstart, base ):
  641. if findstart:
  642. return 5
  643. return [ 'a', 'b', 'cdef' ]
  644. current_buffer = VimBuffer( 'buffer',
  645. contents = [ 'test.' ],
  646. filetype = FILETYPE,
  647. omnifunc = Omnifunc )
  648. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 6 ) ):
  649. ycm.SendCompletionRequest()
  650. assert_that(
  651. ycm.GetCompletionResponse(),
  652. has_entries( {
  653. 'completions': empty(),
  654. 'completion_start_column': 6
  655. } )
  656. )
  657. @YouCompleteMeInstance( {
  658. 'g:ycm_cache_omnifunc': 0,
  659. 'g:ycm_filetype_specific_completion_to_disable': { FILETYPE: 1 },
  660. 'g:ycm_semantic_triggers': TRIGGERS } )
  661. def OmniCompleter_GetCompletions_FiletypeDisabled_ForceSemantic_test( ycm ):
  662. def Omnifunc( findstart, base ):
  663. if findstart:
  664. return 5
  665. return [ 'a', 'b', 'cdef' ]
  666. current_buffer = VimBuffer( 'buffer',
  667. contents = [ 'test.' ],
  668. filetype = FILETYPE,
  669. omnifunc = Omnifunc )
  670. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 6 ) ):
  671. ycm.SendCompletionRequest( force_semantic = True )
  672. assert_that(
  673. ycm.GetCompletionResponse(),
  674. has_entries( {
  675. 'completions': ToBytesOnPY2( [ 'a', 'b', 'cdef' ] ),
  676. 'completion_start_column': 6
  677. } )
  678. )
  679. @YouCompleteMeInstance( {
  680. 'g:ycm_cache_omnifunc': 0,
  681. 'g:ycm_filetype_specific_completion_to_disable': { '*': 1 },
  682. 'g:ycm_semantic_triggers': TRIGGERS } )
  683. def OmniCompleter_GetCompletions_AllFiletypesDisabled_ForceSemantic_test( ycm ):
  684. def Omnifunc( findstart, base ):
  685. if findstart:
  686. return 5
  687. return [ 'a', 'b', 'cdef' ]
  688. current_buffer = VimBuffer( 'buffer',
  689. contents = [ 'test.' ],
  690. filetype = FILETYPE,
  691. omnifunc = Omnifunc )
  692. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 6 ) ):
  693. ycm.SendCompletionRequest( force_semantic = True )
  694. assert_that(
  695. ycm.GetCompletionResponse(),
  696. has_entries( {
  697. 'completions': ToBytesOnPY2( [ 'a', 'b', 'cdef' ] ),
  698. 'completion_start_column': 6
  699. } )
  700. )