completion.vim 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. function! CheckCompletionItemsContainsExactly( expected_props, ... )
  2. let prop = 'abbr'
  3. if a:0 > 0
  4. let prop = a:1
  5. endif
  6. let items = complete_info( [ 'items' ] )[ 'items' ]
  7. let abbrs = []
  8. for item in items
  9. call add( abbrs, get( item, prop ) )
  10. endfor
  11. return assert_equal( a:expected_props,
  12. \ abbrs,
  13. \ 'not matched: '
  14. \ .. string( a:expected_props )
  15. \ .. ' against '
  16. \ .. prop
  17. \ .. ' in '
  18. \ .. string( items )
  19. \ .. ' matching '
  20. \ .. string( abbrs ) )
  21. endfunction
  22. function! CheckCompletionItemsHasItems( expected_props, ... )
  23. let prop = 'abbr'
  24. if a:0 > 0
  25. let prop = a:1
  26. endif
  27. let items = complete_info( [ 'items' ] )[ 'items' ]
  28. let abbrs = []
  29. for item in items
  30. call add( abbrs, get( item, prop ) )
  31. endfor
  32. let result = 0
  33. for expected in a:expected_props
  34. if index( abbrs, expected ) < 0
  35. call assert_report( "Didn't find item with "
  36. \ .. prop
  37. \ .. '="'
  38. \ .. expected
  39. \ .. '" in completion list: '
  40. \ .. string( abbrs ) )
  41. let result += 1
  42. endif
  43. endfor
  44. return result
  45. endfunction
  46. function! IndexOfCompletionItemInList( item, ... )
  47. let prop = 'abbr'
  48. if a:0 > 0
  49. let prop = a:1
  50. endif
  51. let items = complete_info( [ 'items' ] )[ 'items' ]
  52. let abbrs = []
  53. let idx = 0
  54. while idx < len( items )
  55. if get( items[ idx ], prop ) == a:item
  56. return idx
  57. endif
  58. let idx += 1
  59. endwhile
  60. call assert_report( 'Did not find item '
  61. \ . string( a:item )
  62. \ . ' in completion info list' )
  63. return -1
  64. endfunction
  65. function! FeedAndCheckMain( keys, func )
  66. call timer_start( 500, a:func )
  67. call feedkeys( a:keys, 'tx!' )
  68. endfunction
  69. function! FeedAndCheckAgain( keys, func )
  70. call timer_start( 500, a:func )
  71. call feedkeys( a:keys )
  72. endfunction
  73. function! WaitForCompletion()
  74. call WaitForAssert( {->
  75. \ assert_true( pyxeval( 'ycm_state.GetCurrentCompletionRequest() is not None' ) )
  76. \ } )
  77. call WaitForAssert( {->
  78. \ assert_true( pyxeval( 'ycm_state.CompletionRequestReady()' ) )
  79. \ } )
  80. redraw
  81. call WaitForAssert( {->
  82. \ assert_true( pumvisible(), 'pumvisible()' )
  83. \ }, 10000 )
  84. endfunction