File: commands.test.vim

package info (click to toggle)
vim-youcompleteme 0%2B20200825%2Bgit2afee9d%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,016 kB
  • sloc: python: 9,384; sh: 167; cpp: 51; makefile: 25; ansic: 4; xml: 1
file content (113 lines) | stat: -rw-r--r-- 3,817 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
function! SetUp()
  let g:ycm_use_clangd = 1
  let g:ycm_keep_logfiles = 1
  let g:ycm_log_level = 'DEBUG'
  call youcompleteme#test#setup#SetUp()
endfunction

function! Test_ToggleLogs()
  let log_files = pyxeval( 'ycm_state.GetLogfiles()' )
  let bcount = len( getbufinfo() )

  " default - show
  silent exe 'YcmToggleLogs' keys( log_files )[ 0 ]
  call assert_equal( bcount + 1, len( getbufinfo() ) )
  let win = getbufinfo( keys( log_files )[ 0 ] )[ 0 ].windows[ 0 ]
  call assert_equal( &previewheight, winheight( win_id2win( win ) ) )

  " default - hide
  silent exe 'YcmToggleLogs' keys( log_files )[ 0 ]
  " buffer is wiped out
  call assert_equal( bcount, len( getbufinfo() ) )
  call assert_equal( [], getbufinfo( keys( log_files )[ 0 ] ) )

  " show - 10 lines
  silent exe '10YcmToggleLogs' keys( log_files )[ 0 ]
  call assert_equal( bcount + 1, len( getbufinfo() ) )
  let win = getbufinfo( keys( log_files )[ 0 ] )[ 0 ].windows[ 0 ]
  call assert_equal( 10, winheight( win_id2win( win ) ) )

  " hide
  silent exe '10YcmToggleLogs' keys( log_files )[ 0 ]
  call assert_equal( bcount, len( getbufinfo() ) )
  call assert_equal( [], getbufinfo( keys( log_files )[ 0 ] ) )

  " show - 15 cols
  silent exe 'vertical 15YcmToggleLogs' keys( log_files )[ 0 ]
  call assert_equal( bcount + 1, len( getbufinfo() ) )
  let win = getbufinfo( keys( log_files )[ 0 ] )[ 0 ].windows[ 0 ]
  call assert_equal( 15, winwidth( win_id2win( win ) ) )

  " hide
  silent exe 'YcmToggleLogs' keys( log_files )[ 0 ]
  call assert_equal( bcount, len( getbufinfo() ) )
  call assert_equal( [], getbufinfo( keys( log_files )[ 0 ] ) )


endfunction

function! Test_GetCommandResponse()
  call youcompleteme#test#setup#OpenFile( '/test/testdata/python/doc.py', {} )

  " detailed_info
  call setpos( '.', [ 0, 12, 3 ] )
  call assert_equal( "Test_OneLine()\n\nThis is the one line output.",
                   \ youcompleteme#GetCommandResponse( 'GetDoc' ) )

  call setpos( '.', [ 0, 13, 7 ] )
  call assert_equal( "Test_MultiLine()\n\nThis is the one line output.\n"
                   \ . "This is second line.",
                   \ youcompleteme#GetCommandResponse( 'GetDoc' ) )

  " display message
  call setpos( '.', [ 0, 12, 10 ] )
  call assert_equal( 'def Test_OneLine()',
                   \ youcompleteme#GetCommandResponse( 'GetType' ) )

  " Location
  call setpos( '.', [ 0, 12, 10 ] )
  call assert_equal( '',
                   \ youcompleteme#GetCommandResponse( 'GoTo' ) )

  " Error
  call setpos( '.', [ 0, 12, 10 ] )
  call assert_equal( '',
                   \ youcompleteme#GetCommandResponse( 'NotACommand', 'arg' ) )

  " Specify completer
  call setpos( '.', [ 0, 13, 7 ] )
  call assert_equal( "Test_MultiLine()\n\nThis is the one line output.\n"
                   \ . "This is second line.",
                   \ youcompleteme#GetCommandResponse( 'ft=python', 'GetDoc' ) )

  " on a command, no error
  call setpos( '.', [ 0, 1, 3 ] )
  call assert_equal( '', youcompleteme#GetCommandResponse( 'GetDoc' ) )

endfunction


function! Test_GetCommandResponse_FixIt()
  call youcompleteme#test#setup#OpenFile( '/test/testdata/cpp/fixit.c', {} )

  " fixit returns empty
  call setpos( '.', [ 0, 3, 4 ] )
  call assert_equal( '',
                   \ youcompleteme#GetCommandResponse( 'FixIt' ) )

endfunction

function! Test_GetDefinedSubcommands_Native()
  call youcompleteme#test#setup#OpenFile( '/test/testdata/cpp/fixit.c', {} )
  call assert_equal( 1, count( youcompleteme#GetDefinedSubcommands(),
                             \ 'GetDoc' ) )
endfunction

function! Test_GetDefinedSubcommands_NoNative()
  enew
  setf not_a_filetype
  call assert_equal( [], youcompleteme#GetDefinedSubcommands() )

  " The above call prints ValueError: No semantic completer ...."
  messages clear
endfunction