command_request_test.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # Copyright (C) 2016 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 ycm.test_utils import MockVimModule
  18. MockVimModule()
  19. from mock import patch, call
  20. from ycm.client.command_request import CommandRequest
  21. class GoToResponse_QuickFix_test:
  22. """This class tests the generation of QuickFix lists for GoTo responses which
  23. return multiple locations, such as the Python completer and JavaScript
  24. completer. It mostly proves that we use 1-based indexing for the column
  25. number."""
  26. def setUp( self ):
  27. self._request = CommandRequest( [ 'GoToTest' ] )
  28. def tearDown( self ):
  29. self._request = None
  30. def GoTo_EmptyList_test( self ):
  31. self._CheckGoToList( [], [] )
  32. def GoTo_SingleItem_List_test( self ):
  33. self._CheckGoToList( [ {
  34. 'filepath': 'dummy_file',
  35. 'line_num': 10,
  36. 'column_num': 1,
  37. 'description': 'this is some text',
  38. } ], [ {
  39. 'filename': 'dummy_file',
  40. 'text': 'this is some text',
  41. 'lnum': 10,
  42. 'col': 1
  43. } ] )
  44. def GoTo_MultiItem_List_test( self ):
  45. self._CheckGoToList( [ {
  46. 'filepath': 'dummy_file',
  47. 'line_num': 10,
  48. 'column_num': 1,
  49. 'description': 'this is some other text',
  50. }, {
  51. 'filepath': 'dummy_file2',
  52. 'line_num': 1,
  53. 'column_num': 21,
  54. 'description': 'this is some text',
  55. } ], [ {
  56. 'filename': 'dummy_file',
  57. 'text': 'this is some other text',
  58. 'lnum': 10,
  59. 'col': 1
  60. }, {
  61. 'filename': 'dummy_file2',
  62. 'text': 'this is some text',
  63. 'lnum': 1,
  64. 'col': 21
  65. } ] )
  66. @patch( 'vim.eval' )
  67. def _CheckGoToList( self, completer_response, expected_qf_list, vim_eval ):
  68. self._request._response = completer_response
  69. self._request.RunPostCommandActionsIfNeeded()
  70. vim_eval.assert_has_calls( [
  71. call( 'setqflist( {0} )'.format( repr( expected_qf_list ) ) ),
  72. call( 'youcompleteme#OpenGoToList()' ),
  73. ] )