hierarchies.test.vim 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. function! SetUp()
  2. let g:ycm_auto_hover = 1
  3. let g:ycm_auto_trigger = 1
  4. let g:ycm_keep_logfiles = 1
  5. let g:ycm_log_level = 'DEBUG'
  6. call youcompleteme#test#setup#SetUp()
  7. endfunction
  8. function! TearDown()
  9. call youcompleteme#test#setup#CleanUp()
  10. endfunction
  11. function! Test_Call_Hierarchy()
  12. call youcompleteme#test#setup#OpenFile( '/test/testdata/cpp/hierarchies.cc', {} )
  13. call cursor( [ 1, 5 ] )
  14. call youcompleteme#hierarchy#StartRequest( 'call' )
  15. call WaitForAssert( { -> assert_equal( len( popup_list() ), 1 ) } )
  16. " Check that `+Function f` is at the start of the only line in the popup.
  17. call WaitForAssert( { -> assert_equal( len( getbufline( winbufnr( popup_list()[ 0 ] ), 1, '$' ) ), 1 ) } )
  18. call assert_match( '^+Function: f', getbufline( winbufnr( popup_list()[ 0 ] ), 1 )[ 0 ] )
  19. call feedkeys( "\<Tab>", "xt" )
  20. " Check that f's callers are present.
  21. call WaitForAssert( { -> assert_equal( len( getbufline( winbufnr( popup_list()[ 0 ] ), 1, '$' ) ), 4 ) } )
  22. call assert_match( '^+Function: f.*:1', getbufline( winbufnr( popup_list()[ 0 ] ), 1 )[ 0 ] )
  23. call assert_match( '^ +Function: g.*:4', getbufline( winbufnr( popup_list()[ 0 ] ), 2 )[ 0 ] )
  24. call assert_match( '^ +Function: g.*:4', getbufline( winbufnr( popup_list()[ 0 ] ), 3 )[ 0 ] )
  25. call assert_match( '^ +Function: h.*:9', getbufline( winbufnr( popup_list()[ 0 ] ), 4 )[ 0 ] )
  26. call feedkeys( "\<Down>\<Tab>", "xt" )
  27. " Check that g's callers are present.
  28. call WaitForAssert( { -> assert_equal( len( getbufline( winbufnr( popup_list()[ 0 ] ), 1, '$' ) ), 5 ) } )
  29. call assert_match( '^+Function: f.*:1', getbufline( winbufnr( popup_list()[ 0 ] ), 1 )[ 0 ] )
  30. call assert_match( '^ -Function: g.*:4', getbufline( winbufnr( popup_list()[ 0 ] ), 2 )[ 0 ] )
  31. call assert_match( '^ -Function: g.*:4', getbufline( winbufnr( popup_list()[ 0 ] ), 3 )[ 0 ] )
  32. call assert_match( '^ +Function: h.*:8', getbufline( winbufnr( popup_list()[ 0 ] ), 4 )[ 0 ] )
  33. call assert_match( '^ +Function: h.*:9', getbufline( winbufnr( popup_list()[ 0 ] ), 5 )[ 0 ] )
  34. " silent, because h has no incoming calls.
  35. silent call feedkeys( "\<Down>\<Down>\<Tab>", "xt" )
  36. " Check that 1st h's callers are present.
  37. call WaitForAssert( { -> assert_equal( len( getbufline( winbufnr( popup_list()[ 0 ] ), 1, '$' ) ), 5 ) } )
  38. call assert_match( '^+Function: f.*:1', getbufline( winbufnr( popup_list()[ 0 ] ), 1 )[ 0 ] )
  39. call assert_match( '^ -Function: g.*:4', getbufline( winbufnr( popup_list()[ 0 ] ), 2 )[ 0 ] )
  40. call assert_match( '^ -Function: g.*:4', getbufline( winbufnr( popup_list()[ 0 ] ), 3 )[ 0 ] )
  41. call assert_match( '^ -Function: h.*:8', getbufline( winbufnr( popup_list()[ 0 ] ), 4 )[ 0 ] )
  42. call assert_match( '^ +Function: h.*:9', getbufline( winbufnr( popup_list()[ 0 ] ), 5 )[ 0 ] )
  43. " silent, because h has no incoming calls.
  44. silent call feedkeys( "\<Down>\<Tab>", "xt" )
  45. " Check that 2nd h's callers are present.
  46. call WaitForAssert( { -> assert_equal( len( getbufline( winbufnr( popup_list()[ 0 ] ), 1, '$' ) ), 5 ) } )
  47. call assert_match( '^+Function: f.*:1', getbufline( winbufnr( popup_list()[ 0 ] ), 1 )[ 0 ] )
  48. call assert_match( '^ -Function: g.*:4', getbufline( winbufnr( popup_list()[ 0 ] ), 2 )[ 0 ] )
  49. call assert_match( '^ -Function: g.*:4', getbufline( winbufnr( popup_list()[ 0 ] ), 3 )[ 0 ] )
  50. call assert_match( '^ -Function: h.*:8', getbufline( winbufnr( popup_list()[ 0 ] ), 4 )[ 0 ] )
  51. call assert_match( '^ -Function: h.*:9', getbufline( winbufnr( popup_list()[ 0 ] ), 5 )[ 0 ] )
  52. " silent, because clangd does not support outgoing calls.
  53. silent call feedkeys( "\<Up>\<Up>\<Up>\<Up>\<S-Tab>", "xt" )
  54. " Try to access callees of f.
  55. call WaitForAssert( { -> assert_equal( len( getbufline( winbufnr( popup_list()[ 0 ] ), 1, '$' ) ), 5 ) } )
  56. call assert_match( '^-Function: f.*:1', getbufline( winbufnr( popup_list()[ 0 ] ), 1 )[ 0 ] )
  57. call assert_match( '^ -Function: g.*:4', getbufline( winbufnr( popup_list()[ 0 ] ), 2 )[ 0 ] )
  58. call assert_match( '^ -Function: g.*:4', getbufline( winbufnr( popup_list()[ 0 ] ), 3 )[ 0 ] )
  59. call assert_match( '^ -Function: h.*:8', getbufline( winbufnr( popup_list()[ 0 ] ), 4 )[ 0 ] )
  60. call assert_match( '^ -Function: h.*:9', getbufline( winbufnr( popup_list()[ 0 ] ), 5 )[ 0 ] )
  61. " silent, because clangd does not support outgoing calls.
  62. silent call feedkeys( "\<Down>\<Down>\<Down>\<Down>\<S-Tab>", "xt" )
  63. " Re-root at h.
  64. call WaitForAssert( { -> assert_equal( len( getbufline( winbufnr( popup_list()[ 0 ] ), 1, '$' ) ), 1 ) } )
  65. call assert_match( '^+Function: h', getbufline( winbufnr( popup_list()[ 0 ] ), 1 )[0] )
  66. " silent, because clangd does not support outgoing calls.
  67. silent call feedkeys( "\<S-Tab>\<Tab>", "xt" )
  68. " Expansion after re-rooting works.
  69. " NOTE: Clangd does not support outgoing calls, hence, we are stuck at just h.
  70. call WaitForAssert( { -> assert_equal( len( getbufline( winbufnr( popup_list()[ 0 ] ), 1, '$' ) ), 1 ) } )
  71. call assert_match( '^-Function: h', getbufline( winbufnr( popup_list()[ 0 ] ), 1 )[ 0 ] )
  72. call feedkeys( "\<C-c>", "xt" )
  73. " Make sure it is closed.
  74. call WaitForAssert( { -> assert_equal( len( popup_list() ), 0 ) } )
  75. %bwipe!
  76. endfunction
  77. function! Test_Type_Hierarchy()
  78. call youcompleteme#test#setup#OpenFile( '/test/testdata/cpp/hierarchies.cc', {} )
  79. call cursor( [ 13, 8 ] )
  80. call youcompleteme#hierarchy#StartRequest( 'type' )
  81. call WaitForAssert( { -> assert_equal( len( popup_list() ), 1 ) } )
  82. " Check that `+Struct: B1` is at the start of the only line in the popup.
  83. call WaitForAssert( { -> assert_equal( len( getbufline( winbufnr( popup_list()[ 0 ] ), 1, '$' ) ), 1 ) } )
  84. call assert_match( '^+Struct: B1', getbufline( winbufnr( popup_list()[ 0 ] ), 1 )[ 0 ] )
  85. call feedkeys( "\<Tab>", "xt" )
  86. " Check that B1's subtypes are present.
  87. call WaitForAssert( { -> assert_equal( len( getbufline( winbufnr( popup_list()[ 0 ] ), 1, '$' ) ), 2 ) } )
  88. call assert_match( '^+Struct: B1.*:13', getbufline( winbufnr( popup_list()[ 0 ] ), 1 )[ 0 ] )
  89. call assert_match( '^ +Struct: D1.*:16', getbufline( winbufnr( popup_list()[ 0 ] ), 2 )[ 0 ] )
  90. " silent, because D1 has no subtypes.
  91. silent call feedkeys( "\<Down>\<Tab>", "xt" )
  92. " Try to access D1's subtypes.
  93. call WaitForAssert( { -> assert_equal( len( getbufline( winbufnr( popup_list()[ 0 ] ), 1, '$' ) ), 2 ) } )
  94. call assert_match( '^+Struct: B1.*:13', getbufline( winbufnr( popup_list()[ 0 ] ), 1 )[ 0 ] )
  95. call assert_match( '^ -Struct: D1.*:16', getbufline( winbufnr( popup_list()[ 0 ] ), 2 )[ 0 ] )
  96. call feedkeys( "\<Up>\<S-Tab>", "xt" )
  97. " Check that B1's supertypes are present.
  98. call WaitForAssert( { -> assert_equal( len( getbufline( winbufnr( popup_list()[ 0 ] ), 1, '$' ) ), 3 ) } )
  99. call assert_match( '^ +Struct: B0.*:12', getbufline( winbufnr( popup_list()[ 0 ] ), 1 )[ 0 ] )
  100. call assert_match( '^-Struct: B1.*:13', getbufline( winbufnr( popup_list()[ 0 ] ), 2 )[ 0 ] )
  101. call assert_match( '^ -Struct: D1.*:16', getbufline( winbufnr( popup_list()[ 0 ] ), 3 )[ 0 ] )
  102. " silent, because there are no supertypes of B0.
  103. silent call feedkeys( "\<Up>\<S-Tab>", "xt" )
  104. " Try to access B0's supertypes.
  105. call WaitForAssert( { -> assert_equal( len( getbufline( winbufnr( popup_list()[ 0 ] ), 1, '$' ) ), 3 ) } )
  106. call assert_match( '^ -Struct: B0.*:12', getbufline( winbufnr( popup_list()[ 0 ] ), 1 )[ 0 ] )
  107. call assert_match( '^-Struct: B1.*:13', getbufline( winbufnr( popup_list()[ 0 ] ), 2 )[ 0 ] )
  108. call assert_match( '^ -Struct: D1.*:16', getbufline( winbufnr( popup_list()[ 0 ] ), 3 )[ 0 ] )
  109. call feedkeys( "\<Tab>", "xt" )
  110. " Re-root at B0: supertypes->subtypes.
  111. call WaitForAssert( { -> assert_equal( len( getbufline( winbufnr( popup_list()[ 0 ] ), 1, '$' ) ), 4 ) } )
  112. call assert_match( '^+Struct: B0.*:12', getbufline( winbufnr( popup_list()[ 0 ] ), 1 )[ 0 ] )
  113. call assert_match( '^ +Struct: B1.*:13', getbufline( winbufnr( popup_list()[ 0 ] ), 2 )[ 0 ] )
  114. call assert_match( '^ +Struct: D0.*:15', getbufline( winbufnr( popup_list()[ 0 ] ), 3 )[ 0 ] )
  115. call assert_match( '^ +Struct: D1.*:16', getbufline( winbufnr( popup_list()[ 0 ] ), 4 )[ 0 ] )
  116. call feedkeys( "\<Down>\<Down>\<Down>\<S-Tab>", "xt" )
  117. " Re-root at D1: subtypes->supertypes.
  118. call WaitForAssert( { -> assert_equal( len( getbufline( winbufnr( popup_list()[ 0 ] ), 1, '$' ) ), 3 ) } )
  119. call assert_match( '^ +Struct: B0.*:12', getbufline( winbufnr( popup_list()[ 0 ] ), 1 )[ 0 ] )
  120. call assert_match( '^ +Struct: B1.*:13', getbufline( winbufnr( popup_list()[ 0 ] ), 2 )[ 0 ] )
  121. call assert_match( '^+Struct: D1.*:16', getbufline( winbufnr( popup_list()[ 0 ] ), 3 )[ 0 ] )
  122. " silent, because there are no subtypes of D1.
  123. silent call feedkeys( "\<Tab>\<Up>\<S-Tab>", "xt" )
  124. " Expansion after re-rooting works.
  125. call WaitForAssert( { -> assert_equal( len( getbufline( winbufnr( popup_list()[ 0 ] ), 1, '$' ) ), 4 ) } )
  126. call assert_match( '^ +Struct: B0.*:12', getbufline( winbufnr( popup_list()[ 0 ] ), 1 )[ 0 ] )
  127. call assert_match( '^ +Struct: B0.*:12', getbufline( winbufnr( popup_list()[ 0 ] ), 2 )[ 0 ] )
  128. call assert_match( '^ -Struct: B1.*:13', getbufline( winbufnr( popup_list()[ 0 ] ), 3 )[ 0 ] )
  129. call assert_match( '^-Struct: D1.*:16', getbufline( winbufnr( popup_list()[ 0 ] ), 4 )[ 0 ] )
  130. call feedkeys( "\<C-c>", "xt" )
  131. " Make sure it is closed.
  132. call WaitForAssert( { -> assert_equal( len( popup_list() ), 0 ) } )
  133. %bwipe!
  134. endfunction