omni_completion_request_test.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (C) 2020 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 unittest import TestCase
  18. from unittest.mock import MagicMock
  19. from hamcrest import assert_that, has_entries
  20. from ycm.client.omni_completion_request import OmniCompletionRequest
  21. def BuildOmnicompletionRequest( results, start_column = 1 ):
  22. omni_completer = MagicMock()
  23. omni_completer.ComputeCandidates = MagicMock( return_value = results )
  24. request_data = {
  25. 'line_num': 1,
  26. 'column_num': 1,
  27. 'start_column': start_column
  28. }
  29. request = OmniCompletionRequest( omni_completer, request_data )
  30. request.Start()
  31. return request
  32. class OmniCompletionRequestTest( TestCase ):
  33. def test_Done_AlwaysTrue( self ):
  34. request = BuildOmnicompletionRequest( [] )
  35. assert_that( request.Done() )
  36. def test_Response_FromOmniCompleter( self ):
  37. results = [ { "word": "test" } ]
  38. request = BuildOmnicompletionRequest( results )
  39. assert_that( request.Response(), has_entries( {
  40. 'line': 1,
  41. 'column': 1,
  42. 'completion_start_column': 1,
  43. 'completions': results
  44. } ) )