Skip to content

Commit

Permalink
Fix Vim tests
Browse files Browse the repository at this point in the history
Broken by ycm-core/ycmd#1720 - Add diagnostic type to output
Inexplicable syntax errors
Missing semantic_highlighting groups lead to unexpected output
Improve diagnostic test failure messages - print the popup positions
  • Loading branch information
puremourning committed Dec 28, 2023
1 parent 39a9974 commit ddef8b9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
5 changes: 5 additions & 0 deletions python/ycm/semantic_highlighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
'regexp': 'String',
'operator': 'Operator',
'unknown': 'Normal',

# These are not part of the spec, but are used by clangd
'bracket': 'Normal',
# These are not part of the spec, but are used by jdt.ls
'annotation': 'Macro',
}
REPORTED_MISSING_TYPES = set()

Expand Down
32 changes: 19 additions & 13 deletions test/diagnostics.test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function! Test_Disable_Diagnostics_Update_In_insert_Mode()
call WaitForAssert( {-> assert_true( len( sign_getplaced(
\ '%',
\ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] ) ) } )
call FeedAndCheckAgain( "A\<CR>", funcref( 'CheckNoPropsAfterNewLine' )
call FeedAndCheckAgain( "A\<CR>", funcref( 'CheckNoPropsAfterNewLine' ) )
endfunction

function! CheckNoPropsAfterNewLine( id ) closure
Expand All @@ -103,7 +103,7 @@ function! Test_Disable_Diagnostics_Update_In_insert_Mode()
\ 1, { 'end_lnum': -1,
\ 'types': [ 'YcmVirtDiagWarning',
\ 'YcmVirtDiagError',
\ 'YcmVirtDiagPadding' ] } ) ) ) )
\ 'YcmVirtDiagPadding' ] } ) ) ) } )
endfunction

call FeedAndCheckMain( 'imain(',
Expand All @@ -121,14 +121,14 @@ function! Test_Changing_Filetype_Refreshes_Diagnostics()
\ '/test/testdata/diagnostics/foo.xml',
\ { 'native_ft': 0 } )

call assert_equal( 'xml', &ft )
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', &ft )
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.
Expand All @@ -151,7 +151,7 @@ function! Test_MessagePoll_After_LocationList()
\ '/test/testdata/diagnostics/foo.cpp', {} )

setf cpp
call assert_equal( 'cpp', &ft )
call assert_equal( 'cpp', &filetype )
call WaitForAssert( {-> assert_equal( 2, len( sign_getplaced(
\ '%',
\ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] ) ) } )
Expand Down Expand Up @@ -251,7 +251,7 @@ function! Test_ShowDetailedDiagnostic_CmdLine()

call assert_equal(
\ "Format specifies type 'char *' but the argument has type 'int' "
\ . '(fix available)',
\ . '(fix available) [-Wformat]',
\ trim( output ) )

%bwipe!
Expand All @@ -264,8 +264,11 @@ function! Test_ShowDetailedDiagnostic_PopupAtCursor()
call cursor( [ 3, 1 ] )
YcmShowDetailedDiagnostic popup

let id = popup_locate( 4, 1 )
call assert_notequal( 0, id, "Couldn't find 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()
Expand All @@ -274,13 +277,13 @@ function! Test_ShowDetailedDiagnostic_PopupAtCursor()

call youcompleteme#test#popup#CheckPopupPosition( id, {
\ 'visible': 1,
\ 'col': 1,
\ 'col': 16,
\ 'line': 4,
\ } )
call assert_equal(
\ [
\ "Format specifies type 'char *' but the argument has type 'int' "
\ . '(fix available)',
\ . '(fix available) [-Wformat]',
\ ],
\ getbufline( winbufnr(id), 1, '$' ) )

Expand Down Expand Up @@ -315,8 +318,11 @@ function! Test_ShowDetailedDiagnostic_Popup_WithCharacters()
call cursor( [ 4, 1 ] )
YcmShowDetailedDiagnostic popup

let id = popup_locate( 5, 1 )
call assert_notequal( 0, id, "Couldn't find 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()
Expand All @@ -325,7 +331,7 @@ function! Test_ShowDetailedDiagnostic_Popup_WithCharacters()

call youcompleteme#test#popup#CheckPopupPosition( id, {
\ 'visible': 1,
\ 'col': 1,
\ 'col': 7,
\ 'line': 5,
\ } )
call assert_match(
Expand Down
9 changes: 9 additions & 0 deletions test/lib/autoload/youcompleteme/test/popup.vim
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,12 @@ function! youcompleteme#test#popup#ScreenPos( winid, row, col )
let [ w_row, w_col ] = win_screenpos( a:winid )
return { 'row': w_row + a:row, 'col': w_col + a:col }
endfunction


function! youcompleteme#test#popup#DumpPopups() abort
let output = 'Popups:'
for winid in popup_list()
let output .= ' [' . string( winid ) . '@' . string( popup_getpos( winid ) ) . ']'
endfor
return output
endfunction

0 comments on commit ddef8b9

Please sign in to comment.