command_request_test.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #
  2. # Copyright (C) 2016 YouCompleteMe Contributors
  3. #
  4. # This file is part of YouCompleteMe.
  5. #
  6. # YouCompleteMe is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # YouCompleteMe is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
  18. from ycm.test_utils import MockVimModule
  19. MockVimModule()
  20. from mock import patch, call
  21. from ycm.client.command_request import CommandRequest
  22. class GoToResponse_QuickFix_test:
  23. """This class tests the generation of QuickFix lists for GoTo responses which
  24. return multiple locations, such as the Python completer and JavaScript
  25. completer. It mostly proves that we use 1-based indexing for the column
  26. number."""
  27. def setUp( self ):
  28. self._request = CommandRequest( [ 'GoToTest' ] )
  29. def tearDown( self ):
  30. self._request = None
  31. def GoTo_EmptyList_test( self ):
  32. self._CheckGoToList( [], [] )
  33. def GoTo_SingleItem_List_test( self ):
  34. self._CheckGoToList( [ {
  35. 'filepath': 'dummy_file',
  36. 'line_num': 10,
  37. 'column_num': 1,
  38. 'description': 'this is some text',
  39. } ], [ {
  40. 'filename': 'dummy_file',
  41. 'text': 'this is some text',
  42. 'lnum': 10,
  43. 'col': 1
  44. } ] )
  45. def GoTo_MultiItem_List_test( self ):
  46. self._CheckGoToList( [ {
  47. 'filepath': 'dummy_file',
  48. 'line_num': 10,
  49. 'column_num': 1,
  50. 'description': 'this is some other text',
  51. }, {
  52. 'filepath': 'dummy_file2',
  53. 'line_num': 1,
  54. 'column_num': 21,
  55. 'description': 'this is some text',
  56. } ], [ {
  57. 'filename': 'dummy_file',
  58. 'text': 'this is some other text',
  59. 'lnum': 10,
  60. 'col': 1
  61. }, {
  62. 'filename': 'dummy_file2',
  63. 'text': 'this is some text',
  64. 'lnum': 1,
  65. 'col': 21
  66. } ] )
  67. @patch( 'vim.eval' )
  68. def _CheckGoToList( self, completer_response, expected_qf_list, vim_eval ):
  69. self._request._response = completer_response
  70. self._request.RunPostCommandActionsIfNeeded()
  71. vim_eval.assert_has_calls( [
  72. call( 'setqflist( {0} )'.format( repr( expected_qf_list ) ) ),
  73. call( 'youcompleteme#OpenGoToList()' ),
  74. ] )