diagnostics.test.vim 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. function! SetUp()
  2. let g:ycm_use_clangd = 1
  3. let g:ycm_confirm_extra_conf = 0
  4. let g:ycm_auto_trigger = 1
  5. let g:ycm_keep_logfiles = 1
  6. let g:ycm_log_level = 'DEBUG'
  7. let g:ycm_always_populate_location_list = 1
  8. " diagnostics take ages
  9. let g:ycm_test_min_delay = 7
  10. call youcompleteme#test#setup#SetUp()
  11. endfunction
  12. function! TearDown()
  13. call youcompleteme#test#setup#CleanUp()
  14. endfunction
  15. function! Test_Changing_Filetype_Refreshes_Diagnostics()
  16. call youcompleteme#test#setup#OpenFile(
  17. \ '/test/testdata/diagnostics/foo.xml',
  18. \ { 'native_ft': 0 } )
  19. call assert_equal( 'xml', &ft )
  20. call assert_true( pyxeval( 'ycm_state._buffers[' . bufnr( '%' ) . ']._async_diags' ) )
  21. call assert_equal( [], sign_getplaced() )
  22. setf typescript
  23. call assert_equal( 'typescript', &ft )
  24. call assert_false( pyxeval( 'ycm_state._buffers[' . bufnr( '%' ) . ']._async_diags' ) )
  25. " Diagnostics are async, so wait for the assert to return 0 for a while.
  26. call WaitForAssert( {-> assert_equal( 1, len( sign_getplaced() ) ) } )
  27. call assert_equal( 1, len( sign_getplaced()[ 0 ][ 'signs' ] ) )
  28. call assert_equal( 'YcmError', sign_getplaced()[ 0 ][ 'signs' ][ 0 ][ 'name' ] )
  29. call assert_false( empty( getloclist( 0 ) ) )
  30. endfunction
  31. function! Test_MessagePoll_After_LocationList()
  32. call youcompleteme#test#setup#OpenFile( '/test/testdata/diagnostics/foo.cpp', {} )
  33. setf cpp
  34. call assert_equal( 'cpp', &ft )
  35. call WaitForAssert( {-> assert_equal( 1, len( sign_getplaced() ) ) } )
  36. call setline( 1, '' )
  37. " Wait for the parse request to be complete otherwise we won't send another
  38. " one when the TextChanged event fires
  39. call WaitFor( {-> pyxeval( 'ycm_state.FileParseRequestReady()' ) } )
  40. doautocmd TextChanged
  41. call WaitForAssert( {-> assert_true( empty( sign_getplaced() ) ) } )
  42. call assert_true( empty( getloclist( 0 ) ) )
  43. endfunction
  44. function! Test_MessagePoll_Multiple_Filetypes()
  45. call youcompleteme#test#setup#OpenFile(
  46. \ '/third_party/ycmd/ycmd/tests/java/testdata/simple_eclipse_project' .
  47. \ '/src/com/test/TestLauncher.java', {} )
  48. call WaitForAssert( {-> assert_true( len( sign_getplaced( '%' )[ 0 ][ 'signs' ] ) ) } )
  49. let java_signs = sign_getplaced( '%' )[ 0 ][ 'signs' ]
  50. silent vsplit testdata/diagnostics/foo.cpp
  51. " Make sure we've left the java buffer
  52. call assert_equal( java_signs, sign_getplaced( '#' )[ 0 ][ 'signs' ] )
  53. " Clangd emits two diagnostics for foo.cpp.
  54. call WaitForAssert( {-> assert_equal( 2, len( sign_getplaced( '%' )[ 0 ][ 'signs' ] ) ) } )
  55. let cpp_signs = sign_getplaced( '%' )[ 0 ][ 'signs' ]
  56. call assert_false( java_signs == cpp_signs )
  57. endfunction