commands.test.vim 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. function! SetUp()
  2. let g:ycm_use_clangd = 1
  3. let g:ycm_keep_logfiles = 1
  4. let g:ycm_log_level = 'DEBUG'
  5. call youcompleteme#test#setup#SetUp()
  6. endfunction
  7. function! Test_ToggleLogs()
  8. let log_files = pyxeval( 'ycm_state.GetLogfiles()' )
  9. let bcount = len( getbufinfo() )
  10. " default - show
  11. silent exe 'YcmToggleLogs' keys( log_files )[ 0 ]
  12. call assert_equal( bcount + 1, len( getbufinfo() ) )
  13. let win = getbufinfo( keys( log_files )[ 0 ] )[ 0 ].windows[ 0 ]
  14. call assert_equal( &previewheight, winheight( win_id2win( win ) ) )
  15. " default - hide
  16. silent exe 'YcmToggleLogs' keys( log_files )[ 0 ]
  17. " buffer is wiped out
  18. call assert_equal( bcount, len( getbufinfo() ) )
  19. call assert_equal( [], getbufinfo( keys( log_files )[ 0 ] ) )
  20. " show - 10 lines
  21. silent exe '10YcmToggleLogs' keys( log_files )[ 0 ]
  22. call assert_equal( bcount + 1, len( getbufinfo() ) )
  23. let win = getbufinfo( keys( log_files )[ 0 ] )[ 0 ].windows[ 0 ]
  24. call assert_equal( 10, winheight( win_id2win( win ) ) )
  25. " hide
  26. silent exe '10YcmToggleLogs' keys( log_files )[ 0 ]
  27. call assert_equal( bcount, len( getbufinfo() ) )
  28. call assert_equal( [], getbufinfo( keys( log_files )[ 0 ] ) )
  29. " show - 15 cols
  30. silent exe 'vertical 15YcmToggleLogs' keys( log_files )[ 0 ]
  31. call assert_equal( bcount + 1, len( getbufinfo() ) )
  32. let win = getbufinfo( keys( log_files )[ 0 ] )[ 0 ].windows[ 0 ]
  33. call assert_equal( 15, winwidth( win_id2win( win ) ) )
  34. " hide
  35. silent exe 'YcmToggleLogs' keys( log_files )[ 0 ]
  36. call assert_equal( bcount, len( getbufinfo() ) )
  37. call assert_equal( [], getbufinfo( keys( log_files )[ 0 ] ) )
  38. endfunction
  39. function! Test_GetCommandResponse()
  40. call youcompleteme#test#setup#OpenFile( '/test/testdata/python/doc.py', {} )
  41. " detailed_info
  42. call setpos( '.', [ 0, 12, 3 ] )
  43. call assert_equal( "Test_OneLine()\n\nThis is the one line output.",
  44. \ youcompleteme#GetCommandResponse( 'GetDoc' ) )
  45. call setpos( '.', [ 0, 13, 7 ] )
  46. call assert_equal( "Test_MultiLine()\n\nThis is the one line output.\n"
  47. \ . "This is second line.",
  48. \ youcompleteme#GetCommandResponse( 'GetDoc' ) )
  49. " display message
  50. call setpos( '.', [ 0, 12, 10 ] )
  51. call assert_equal( 'def Test_OneLine()',
  52. \ youcompleteme#GetCommandResponse( 'GetType' ) )
  53. " Location
  54. call setpos( '.', [ 0, 12, 10 ] )
  55. call assert_equal( '',
  56. \ youcompleteme#GetCommandResponse( 'GoTo' ) )
  57. " Error
  58. call setpos( '.', [ 0, 12, 10 ] )
  59. call assert_equal( '',
  60. \ youcompleteme#GetCommandResponse( 'NotACommand', 'arg' ) )
  61. " Specify completer
  62. call setpos( '.', [ 0, 13, 7 ] )
  63. call assert_equal( "Test_MultiLine()\n\nThis is the one line output.\n"
  64. \ . "This is second line.",
  65. \ youcompleteme#GetCommandResponse( 'ft=python', 'GetDoc' ) )
  66. " on a command, no error
  67. call setpos( '.', [ 0, 1, 3 ] )
  68. call assert_equal( '', youcompleteme#GetCommandResponse( 'GetDoc' ) )
  69. endfunction
  70. function! Test_GetCommandResponse_FixIt()
  71. call youcompleteme#test#setup#OpenFile( '/test/testdata/cpp/fixit.c', {} )
  72. " fixit returns empty
  73. call setpos( '.', [ 0, 3, 4 ] )
  74. call assert_equal( '',
  75. \ youcompleteme#GetCommandResponse( 'FixIt' ) )
  76. endfunction
  77. function! Test_GetDefinedSubcommands_Native()
  78. call youcompleteme#test#setup#OpenFile( '/test/testdata/cpp/fixit.c', {} )
  79. call assert_equal( 1, count( youcompleteme#GetDefinedSubcommands(),
  80. \ 'GetDoc' ) )
  81. endfunction
  82. function! Test_GetDefinedSubcommands_NoNative()
  83. enew
  84. setf not_a_filetype
  85. call assert_equal( [], youcompleteme#GetDefinedSubcommands() )
  86. " The above call prints ValueError: No semantic completer ...."
  87. messages clear
  88. endfunction