command_test.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. # Copyright (C) 2016-2018 YouCompleteMe contributors
  2. #
  3. # This file is part of YouCompleteMe.
  4. #
  5. # YouCompleteMe is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # YouCompleteMe is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
  17. from __future__ import unicode_literals
  18. from __future__ import print_function
  19. from __future__ import division
  20. from __future__ import absolute_import
  21. # Not installing aliases from python-future; it's unreliable and slow.
  22. from builtins import * # noqa
  23. from ycm.tests.test_utils import MockVimModule, MockVimBuffers, VimBuffer
  24. MockVimModule()
  25. from hamcrest import assert_that, contains, has_entries
  26. from mock import patch
  27. from ycm.tests import YouCompleteMeInstance
  28. @YouCompleteMeInstance( { 'g:ycm_extra_conf_vim_data': [ 'tempname()' ] } )
  29. def SendCommandRequest_ExtraConfVimData_Works_test( ycm ):
  30. current_buffer = VimBuffer( 'buffer' )
  31. with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
  32. with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
  33. ycm.SendCommandRequest( [ 'GoTo' ], 'aboveleft', False, 1, 1 )
  34. assert_that(
  35. # Positional arguments passed to SendCommandRequest.
  36. send_request.call_args[ 0 ],
  37. contains(
  38. contains( 'GoTo' ),
  39. 'aboveleft',
  40. 'same-buffer',
  41. has_entries( {
  42. 'options': has_entries( {
  43. 'tab_size': 2,
  44. 'insert_spaces': True,
  45. } ),
  46. 'extra_conf_data': has_entries( {
  47. 'tempname()': '_TEMP_FILE_'
  48. } ),
  49. } )
  50. )
  51. )
  52. @YouCompleteMeInstance( { 'g:ycm_extra_conf_vim_data': [ 'undefined_value' ] } )
  53. def SendCommandRequest_ExtraConfData_UndefinedValue_test( ycm ):
  54. current_buffer = VimBuffer( 'buffer' )
  55. with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
  56. with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
  57. ycm.SendCommandRequest( [ 'GoTo' ], 'belowright', False, 1, 1 )
  58. assert_that(
  59. # Positional arguments passed to SendCommandRequest.
  60. send_request.call_args[ 0 ],
  61. contains(
  62. contains( 'GoTo' ),
  63. 'belowright',
  64. 'same-buffer',
  65. has_entries( {
  66. 'options': has_entries( {
  67. 'tab_size': 2,
  68. 'insert_spaces': True,
  69. } )
  70. } )
  71. )
  72. )
  73. @YouCompleteMeInstance()
  74. def SendCommandRequest_BuildRange_NoVisualMarks_test( ycm, *args ):
  75. current_buffer = VimBuffer( 'buffer', contents = [ 'first line',
  76. 'second line' ] )
  77. with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
  78. with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
  79. ycm.SendCommandRequest( [ 'GoTo' ], '', True, 1, 2 )
  80. send_request.assert_called_once_with(
  81. [ 'GoTo' ],
  82. '',
  83. 'same-buffer',
  84. {
  85. 'options': {
  86. 'tab_size': 2,
  87. 'insert_spaces': True
  88. },
  89. 'range': {
  90. 'start': {
  91. 'line_num': 1,
  92. 'column_num': 1
  93. },
  94. 'end': {
  95. 'line_num': 2,
  96. 'column_num': 12
  97. }
  98. }
  99. }
  100. )
  101. @YouCompleteMeInstance()
  102. def SendCommandRequest_BuildRange_VisualMarks_test( ycm, *args ):
  103. current_buffer = VimBuffer( 'buffer',
  104. contents = [ 'first line',
  105. 'second line' ],
  106. visual_start = [ 1, 4 ],
  107. visual_end = [ 2, 8 ] )
  108. with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
  109. with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
  110. ycm.SendCommandRequest( [ 'GoTo' ], 'tab', True, 1, 2 )
  111. send_request.assert_called_once_with(
  112. [ 'GoTo' ],
  113. 'tab',
  114. 'same-buffer',
  115. {
  116. 'options': {
  117. 'tab_size': 2,
  118. 'insert_spaces': True
  119. },
  120. 'range': {
  121. 'start': {
  122. 'line_num': 1,
  123. 'column_num': 5
  124. },
  125. 'end': {
  126. 'line_num': 2,
  127. 'column_num': 9
  128. }
  129. }
  130. }
  131. )
  132. @YouCompleteMeInstance()
  133. def SendCommandRequest_IgnoreFileTypeOption_test( ycm, *args ):
  134. current_buffer = VimBuffer( 'buffer' )
  135. with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
  136. expected_args = (
  137. [ 'GoTo' ],
  138. '',
  139. 'same-buffer',
  140. {
  141. 'options': {
  142. 'tab_size': 2,
  143. 'insert_spaces': True
  144. },
  145. }
  146. )
  147. with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
  148. ycm.SendCommandRequest( [ 'ft=ycm:ident', 'GoTo' ], '', False, 1, 1 )
  149. send_request.assert_called_once_with( *expected_args )
  150. with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
  151. ycm.SendCommandRequest( [ 'GoTo', 'ft=python' ], '', False, 1, 1 )
  152. send_request.assert_called_once_with( *expected_args )