123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466 |
- function! SetUp()
- let g:ycm_use_clangd = 1
- let g:ycm_confirm_extra_conf = 0
- let g:ycm_auto_trigger = 1
- let g:ycm_keep_logfiles = 1
- let g:ycm_log_level = 'DEBUG'
- let g:ycm_always_populate_location_list = 1
- let g:ycm_enable_semantic_highlighting = 1
- let g:ycm_auto_hover = ''
- " diagnostics take ages
- let g:ycm_test_min_delay = 7
- call youcompleteme#test#setup#SetUp()
- endfunction
- function! TearDown()
- call youcompleteme#test#setup#CleanUp()
- endfunction
- function! Test_Diagnostics_Update_In_Insert_Mode()
- call youcompleteme#test#setup#OpenFile(
- \ '/test/testdata/cpp/new_file.cpp', {} )
- " Required to trigger TextChangedI
- " https://github.com/vim/vim/issues/4665#event-2480928194
- call test_override( 'char_avail', 1 )
- " Must do the checks in a timer callback because we need to stay in insert
- " mode until done.
- function! Check( id ) closure
- call WaitForAssert( {-> assert_true( len( sign_getplaced(
- \ '%',
- \ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] ) ) } )
- call feedkeys( "\<ESC>" )
- endfunction
- call FeedAndCheckMain( 'imain(', funcref( 'Check' ) )
- call test_override( 'ALL', 0 )
- endfunction
- function! SetUp_Test_Disable_Diagnostics_Update_In_insert_Mode()
- call youcompleteme#test#setup#PushGlobal(
- \ 'ycm_update_diagnostics_in_insert_mode', 0 )
- endfunction
- function! Test_Disable_Diagnostics_Update_In_insert_Mode()
- call youcompleteme#test#setup#OpenFile(
- \ '/test/testdata/cpp/new_file.cpp', {} )
- " Required to trigger TextChangedI
- " https://github.com/vim/vim/issues/4665#event-2480928194
- call test_override( 'char_avail', 1 )
- " Must do the checks in a timer callback because we need to stay in insert
- " mode until done.
- function! CheckNoDiagUIAfterOpenParenthesis( id ) closure
- call WaitForAssert( {->
- \ assert_true(
- \ py3eval(
- \ 'len( ycm_state.CurrentBuffer()._diag_interface._diagnostics )'
- \ ) ) } )
- call WaitForAssert( {-> assert_false( len( sign_getplaced(
- \ '%',
- \ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] ) ) } )
- call FeedAndCheckAgain( " \<BS>\<BS>\<BS>)",
- \ funcref( 'CheckNoDiagUIAfterClosingPatenthesis' ) )
- endfunction
- function! CheckNoDiagUIAfterClosingPatenthesis( id ) closure
- call WaitForAssert( {->
- \ assert_true(
- \ py3eval(
- \ 'len( ycm_state.CurrentBuffer()._diag_interface._diagnostics )'
- \ ) ) } )
- call WaitForAssert( {-> assert_false( len( sign_getplaced(
- \ '%',
- \ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] ) ) } )
- call feedkeys( "\<ESC>" )
- call FeedAndCheckAgain( "\<ESC>",
- \ funcref( 'CheckDiagUIRefreshedAfterLeavingInsertMode' ) )
- endfunction
- function! CheckDiagUIRefreshedAfterLeavingInsertMode( id ) closure
- call WaitForAssert( {->
- \ assert_true(
- \ py3eval(
- \ 'len( ycm_state.CurrentBuffer()._diag_interface._diagnostics )'
- \ ) ) } )
- call WaitForAssert( {-> assert_true( len( sign_getplaced(
- \ '%',
- \ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] ) ) } )
- call FeedAndCheckAgain( "A\<CR>", funcref( 'CheckNoPropsAfterNewLine' ) )
- endfunction
- function! CheckNoPropsAfterNewLine( id ) closure
- call WaitForAssert( {->
- \ assert_true(
- \ py3eval(
- \ 'len( ycm_state.CurrentBuffer()._diag_interface._diagnostics )'
- \ ) ) } )
- call WaitForAssert( {-> assert_false( len( prop_list(
- \ 1, { 'end_lnum': -1,
- \ 'types': [ 'YcmVirtDiagWarning',
- \ 'YcmVirtDiagError',
- \ 'YcmVirtDiagPadding' ] } ) ) ) } )
- endfunction
- call FeedAndCheckMain( 'imain(',
- \ funcref( 'CheckNoDiagUIAfterOpenParenthesis' ) )
- call test_override( 'ALL', 0 )
- endfunction
- function! TearDown_Test_Disable_Diagnostics_Update_In_insert_Mode()
- call youcompleteme#test#setup#PopGlobal(
- \ 'ycm_update_diagnostics_in_insert_mode' )
- endfunction
- function! Test_Changing_Filetype_Refreshes_Diagnostics()
- call youcompleteme#test#setup#OpenFile(
- \ '/test/testdata/diagnostics/foo.xml',
- \ { 'native_ft': 0 } )
- call assert_equal( 'xml', &filetype )
- call assert_false(
- \ pyxeval( 'ycm_state._buffers[' . bufnr( '%' ) . ']._async_diags' ) )
- call assert_true( empty( sign_getplaced(
- \ '%',
- \ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] ) )
- setf typescript
- call assert_equal( 'typescript', &filetype )
- call assert_false(
- \ pyxeval( 'ycm_state._buffers[' . bufnr( '%' ) . ']._async_diags' ) )
- " Diagnostics are async, so wait for the assert to return 0 for a while.
- call WaitForAssert( {-> assert_equal( 1, len( sign_getplaced(
- \ '%',
- \ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] ) ) } )
- call assert_equal( 1, len( sign_getplaced(
- \ '%',
- \ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] ) )
- call assert_equal(
- \ 'YcmError',
- \ sign_getplaced(
- \ '%',
- \ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ][ 0 ][ 'name' ] )
- call assert_false( empty( getloclist( 0 ) ) )
- endfunction
- function! Test_MessagePoll_After_LocationList()
- call youcompleteme#test#setup#OpenFile(
- \ '/test/testdata/diagnostics/foo.cpp', {} )
- setf cpp
- call assert_equal( 'cpp', &filetype )
- call WaitForAssert( {-> assert_equal( 2, len( sign_getplaced(
- \ '%',
- \ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] ) ) } )
- call setline( 1, '' )
- " Wait for the parse request to be complete otherwise we won't send another
- " one when the TextChanged event fires
- call WaitFor( {-> pyxeval( 'ycm_state.FileParseRequestReady()' ) } )
- doautocmd TextChanged
- call WaitForAssert( {-> assert_true( empty( sign_getplaced(
- \ '%',
- \ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] ) ) } )
- call assert_true( empty( getloclist( 0 ) ) )
- endfunction
- function! Test_MessagePoll_Multiple_Filetypes()
- call youcompleteme#test#setup#OpenFile(
- \ '/third_party/ycmd/ycmd/tests/java/testdata/simple_eclipse_project' .
- \ '/src/com/test/TestLauncher.java', {} )
- call WaitForAssert( {->
- \ assert_true( len( sign_getplaced(
- \ '%',
- \ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] ) ) } )
- let java_signs = sign_getplaced(
- \ '%',
- \ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ]
- silent vsplit testdata/diagnostics/foo.cpp
- " Make sure we've left the java buffer
- call assert_equal( java_signs,
- \ sign_getplaced( '#', { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] )
- " Clangd emits two diagnostics for foo.cpp.
- call WaitForAssert( {->
- \ assert_equal(
- \ 2,
- \ len( sign_getplaced(
- \ '%',
- \ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] ) ) } )
- let cpp_signs = sign_getplaced( '%',
- \ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ]
- call assert_false( java_signs == cpp_signs )
- endfunction
- function! Test_BufferWithoutAssociatedFile_HighlightingWorks()
- enew
- call setbufline( '%', 1, 'iiii' )
- setf c
- call WaitForAssert( {->
- \ assert_true( len( sign_getplaced(
- \ '%',
- \ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] ) ) } )
- let expected_properties = [
- \ { 'id': 4,
- \ 'col': 1,
- \ 'end': 1,
- \ 'type': 'YcmErrorProperty',
- \ 'length': 0,
- \ 'start': 1 },
- \ { 'id': 3,
- \ 'col': 1,
- \ 'end': 1,
- \ 'type': 'YcmErrorProperty',
- \ 'length': 0,
- \ 'start': 1 },
- \ { 'id': 2,
- \ 'col': 1,
- \ 'end': 1,
- \ 'type': 'YcmErrorProperty',
- \ 'length': 4,
- \ 'start': 1 },
- \ { 'id': 1,
- \ 'col': 1,
- \ 'end': 1,
- \ 'type': 'YcmErrorProperty',
- \ 'length': 4,
- \ 'start': 1 } ]
- call CheckListOfDicts( prop_list( 1 ), expected_properties )
- endfunction
- function! Test_ThirdPartyDeletesItsTextProperty()
- enew
- call prop_type_add( 'ThirdPartyProperty', { 'highlight': 'Error' } )
- call prop_add( 1, 1, { 'type': 'ThirdPartyProperty', 'bufnr': bufnr('%'), 'id': 42 } )
- call prop_type_delete( 'ThirdPartyProperty' )
- py3 from ycm.vimsupport import GetTextProperties, GetIntValue
- call assert_equal( [], py3eval( 'GetTextProperties( GetIntValue( """bufnr( "%" )""" ) )' ) )
- endfunction
- function! Test_ShowDetailedDiagnostic_CmdLine()
- call youcompleteme#test#setup#OpenFile(
- \ '/test/testdata/cpp/fixit.cpp', {} )
- call cursor( [ 3, 1 ] )
- redir => output
- YcmShowDetailedDiagnostic
- redir END
- call assert_equal(
- \ "Format specifies type 'char *' but the argument has type 'int' "
- \ . '(fix available) [-Wformat]',
- \ trim( output ) )
- %bwipe!
- endfunction
- function! Test_ShowDetailedDiagnostic_PopupAtCursor()
- call youcompleteme#test#setup#OpenFile(
- \ '/test/testdata/cpp/fixit.cpp', {} )
- call cursor( [ 3, 1 ] )
- YcmShowDetailedDiagnostic popup
- let id = popup_locate( 4, 16 )
- call assert_notequal(
- \ 0,
- \ id,
- \ "Couldn't find popup! " .. youcompleteme#test#popup#DumpPopups() )
- if exists( '*popup_list' )
- let popups = popup_list()
- call assert_equal( 1, len( popups ) )
- endif
- call youcompleteme#test#popup#CheckPopupPosition( id, {
- \ 'visible': 1,
- \ 'col': 16,
- \ 'line': 4,
- \ } )
- call assert_equal(
- \ [
- \ "Format specifies type 'char *' but the argument has type 'int' "
- \ . '(fix available) [-Wformat]',
- \ ],
- \ getbufline( winbufnr(id), 1, '$' ) )
- " From vim's test_popupwin.vim
- " trigger the check for last_cursormoved by going into insert mode
- call test_override( 'char_avail', 1 )
- call feedkeys( "ji\<Esc>", 'xt' )
- call assert_equal( {}, popup_getpos( id ) )
- call test_override( 'ALL', 0 )
- %bwipe!
- endfunction
- function! Test_ShowDetailedDiagnostic_Popup_WithCharacters()
- let f = tempname() . '.cc'
- execut 'edit' f
- call setline( 1, [
- \ 'struct Foo {};',
- \ 'template<char...> Foo operator""_foo() { return {}; }',
- \ 'int main() {',
- \ '""_foo',
- \ '}',
- \ ] )
- call youcompleteme#test#setup#WaitForInitialParse( {} )
- call WaitForAssert( {->
- \ assert_true(
- \ py3eval(
- \ 'len( ycm_state.CurrentBuffer()._diag_interface._diagnostics )'
- \ ) ) } )
- call cursor( [ 4, 1 ] )
- YcmShowDetailedDiagnostic popup
- let id = popup_locate( 5, 7 )
- call assert_notequal(
- \ 0,
- \ id,
- \ "Couldn't find popup! " .. youcompleteme#test#popup#DumpPopups() )
- if exists( '*popup_list' )
- let popups = popup_list()
- call assert_equal( 1, len( popups ) )
- endif
- call youcompleteme#test#popup#CheckPopupPosition( id, {
- \ 'visible': 1,
- \ 'col': 7,
- \ 'line': 5,
- \ } )
- call assert_match(
- \ "^No matching literal operator for call to 'operator\"\"_foo'.*",
- \ getbufline( winbufnr(id), 1, '$' )[ 0 ] )
- " From vim's test_popupwin.vim
- " trigger the check for last_cursormoved by going into insert mode
- call test_override( 'char_avail', 1 )
- call feedkeys( "ji\<Esc>", 'xt' )
- call assert_equal( {}, popup_getpos( id ) )
- call test_override( 'ALL', 0 )
- %bwipe!
- endfunction
- function! Test_ShowDetailedDiagnostic_Popup_MultilineDiagNotFromStartOfLine()
- let f = tempname() . '.cc'
- execut 'edit' f
- call setline( 1, [
- \ 'int main () {',
- \ ' int a \',
- \ '=\',
- \ '=',
- \ '3;',
- \ '}',
- \ ] )
- call youcompleteme#test#setup#WaitForInitialParse( {} )
- call WaitForAssert( {->
- \ assert_true(
- \ py3eval(
- \ 'len( ycm_state.CurrentBuffer()._diag_interface._diagnostics )'
- \ ) ) } )
- call test_override( 'char_avail', 1 )
- for cursor_pos in [ [ 2, 9 ], [ 3, 1], [ 4, 1 ] ]
- call cursor( cursor_pos )
- YcmShowDetailedDiagnostic popup
- call assert_equal( len( popup_list() ), 1 )
- let id = popup_list()[ 0 ]
- call assert_notequal( 0, id, "Couldn't find popup!" )
- call assert_equal( [ 3, 10 ], win_screenpos( id ) )
- call youcompleteme#test#popup#CheckPopupPosition( id, {
- \ 'visible': 1,
- \ 'col': 10,
- \ 'line': 3,
- \ } )
- call assert_match(
- \ "^Invalid '==' at end of declaration; did you mean '='?.*",
- \ getbufline( winbufnr(id), 1, '$' )[ 0 ] )
- " From vim's test_popupwin.vim
- " trigger the check for last_cursormoved by going into insert mode
- call feedkeys( "ji\<Esc>", 'xt' )
- call assert_equal( {}, popup_getpos( id ) )
- endfor
- call test_override( 'ALL', 0 )
- %bwipe!
- endfunction
- function! Test_ShowDetailedDiagnostic_Popup_MultilineDiagFromStartOfLine()
- let f = tempname() . '.cc'
- execut 'edit' f
- call setline( 1, [
- \ 'int main () {',
- \ 'const int &&',
- \ ' /* */',
- \ ' rd = 1;',
- \ 'rd = 4;',
- \ '}',
- \ ] )
- call youcompleteme#test#setup#WaitForInitialParse( {} )
- call WaitForAssert( {->
- \ assert_true(
- \ py3eval(
- \ 'len( ycm_state.CurrentBuffer()._diag_interface._diagnostics )'
- \ ) ) } )
- call test_override( 'char_avail', 1 )
- for cursor_pos in [ [ 2, 1 ], [ 3, 9 ], [ 4, 5 ] ]
- call cursor( cursor_pos )
- YcmShowDetailedDiagnostic popup
- call assert_equal( 1, len( popup_list() ) )
- let id = popup_list()[ 0 ]
- call assert_notequal( 0, id, "Couldn't find popup!" )
- call assert_equal( [ 3, 13 ], win_screenpos( id ) )
- call youcompleteme#test#popup#CheckPopupPosition( id, {
- \ 'visible': 1,
- \ 'col': 13,
- \ 'line': 3,
- \ } )
- call assert_match(
- \ "^Variable 'rd' declared const here.*",
- \ getbufline( winbufnr(id), 1, '$' )[ 0 ] )
- " From vim's test_popupwin.vim
- " trigger the check for last_cursormoved by going into insert mode
- call feedkeys( "ji\<Esc>ki\<Esc>", 'xt' )
- call assert_equal( {}, popup_getpos( id ) )
- endfor
- call test_override( 'ALL', 0 )
- %bwipe!
- endfunction
- function! Test_ShowDetailedDiagnostic_Popup_MultipleDiagsPerLine_SameMessage()
- let f = tempname() . '.cc'
- execut 'edit' f
- call setline( 1, [ 'void f(){a;a;}', ] )
- call youcompleteme#test#setup#WaitForInitialParse( {} )
- call WaitForAssert( {->
- \ assert_true(
- \ py3eval(
- \ 'len( ycm_state.CurrentBuffer()._diag_interface._diagnostics )'
- \ ) ) } )
- YcmShowDetailedDiagnostic popup
- let popup_list = popup_list()
- call assert_equal( 1, len( popup_list ) )
- call popup_close( popup_list[ 0 ] )
- endfunction
|