omni_completion_request_tests.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 mock import MagicMock
  18. from nose.tools import eq_
  19. from hamcrest import assert_that, has_entries
  20. from ycm.client.omni_completion_request import OmniCompletionRequest
  21. def BuildOmnicompletionRequest( results ):
  22. omni_completer = MagicMock()
  23. omni_completer.ComputeCandidates = MagicMock( return_value = results )
  24. request = OmniCompletionRequest( omni_completer, None )
  25. request.Start()
  26. return request;
  27. def Done_AlwaysTrue_test():
  28. request = BuildOmnicompletionRequest( [] )
  29. eq_( request.Done(), True )
  30. def Response_FromOmniCompleter_test():
  31. results = [ { "word": "test" } ]
  32. request = BuildOmnicompletionRequest( results )
  33. eq_( request.Response(), results )
  34. def RawResponse_ConvertedFromOmniCompleter_test():
  35. vim_results = [
  36. { "word": "WORD", "abbr": "ABBR", "menu": "MENU",
  37. "kind": "KIND", "info": "INFO" },
  38. { "word": "WORD2", "abbr": "ABBR2", "menu": "MENU2",
  39. "kind": "KIND2", "info": "INFO" },
  40. { "word": "WORD", "abbr": "ABBR", },
  41. { },
  42. ]
  43. expected_results = [
  44. has_entries( { "insertion_text": "WORD", "menu_text": "ABBR",
  45. "extra_menu_info": "MENU", "kind": [ "KIND" ],
  46. "detailed_info": "INFO" } ),
  47. has_entries( { "insertion_text": "WORD2", "menu_text": "ABBR2",
  48. "extra_menu_info": "MENU2", "kind": [ "KIND2" ],
  49. "detailed_info": "INFO" } ),
  50. has_entries( { "insertion_text": "WORD", "menu_text": "ABBR", } ),
  51. has_entries( { } ),
  52. ]
  53. request = BuildOmnicompletionRequest( vim_results )
  54. results = request.RawResponse()
  55. eq_( len( results ), len( expected_results ) )
  56. for result, expected_result in zip( results, expected_results ):
  57. assert_that( result, expected_result )