command_test.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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' ], 'python', False, 1, 1 )
  34. assert_that(
  35. # Positional arguments passed to SendCommandRequest.
  36. send_request.call_args[ 0 ],
  37. contains(
  38. contains( 'GoTo' ),
  39. 'python',
  40. has_entries( {
  41. 'options': has_entries( {
  42. 'tab_size': 2,
  43. 'insert_spaces': True,
  44. } ),
  45. 'extra_conf_data': has_entries( {
  46. 'tempname()': '_TEMP_FILE_'
  47. } ),
  48. } )
  49. )
  50. )
  51. @YouCompleteMeInstance( { 'g:ycm_extra_conf_vim_data': [ 'undefined_value' ] } )
  52. def SendCommandRequest_ExtraConfData_UndefinedValue_test( ycm ):
  53. current_buffer = VimBuffer( 'buffer' )
  54. with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
  55. with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
  56. ycm.SendCommandRequest( [ 'GoTo' ], 'python', False, 1, 1 )
  57. assert_that(
  58. # Positional arguments passed to SendCommandRequest.
  59. send_request.call_args[ 0 ],
  60. contains(
  61. contains( 'GoTo' ),
  62. 'python',
  63. has_entries( {
  64. 'options': has_entries( {
  65. 'tab_size': 2,
  66. 'insert_spaces': True,
  67. } )
  68. } )
  69. )
  70. )
  71. @YouCompleteMeInstance()
  72. def SendCommandRequest_BuildRange_NoVisualMarks_test( ycm, *args ):
  73. current_buffer = VimBuffer( 'buffer', contents = [ 'first line',
  74. 'second line' ] )
  75. with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
  76. with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
  77. ycm.SendCommandRequest( [ 'GoTo' ], 'python', True, 1, 2 )
  78. send_request.assert_called_once_with(
  79. [ 'GoTo' ],
  80. 'python',
  81. {
  82. 'options': {
  83. 'tab_size': 2,
  84. 'insert_spaces': True
  85. },
  86. 'range': {
  87. 'start': {
  88. 'line_num': 1,
  89. 'column_num': 1
  90. },
  91. 'end': {
  92. 'line_num': 2,
  93. 'column_num': 12
  94. }
  95. }
  96. }
  97. )
  98. @YouCompleteMeInstance()
  99. def SendCommandRequest_BuildRange_VisualMarks_test( ycm, *args ):
  100. current_buffer = VimBuffer( 'buffer',
  101. contents = [ 'first line',
  102. 'second line' ],
  103. visual_start = [ 1, 4 ],
  104. visual_end = [ 2, 8 ] )
  105. with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
  106. with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
  107. ycm.SendCommandRequest( [ 'GoTo' ], 'python', True, 1, 2 )
  108. send_request.assert_called_once_with(
  109. [ 'GoTo' ],
  110. 'python',
  111. {
  112. 'options': {
  113. 'tab_size': 2,
  114. 'insert_spaces': True
  115. },
  116. 'range': {
  117. 'start': {
  118. 'line_num': 1,
  119. 'column_num': 5
  120. },
  121. 'end': {
  122. 'line_num': 2,
  123. 'column_num': 9
  124. }
  125. }
  126. }
  127. )