1
0

omni_completion_request_tests.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env python
  2. #
  3. # Copyright (C) 2016 YouCompleteMe contributors
  4. #
  5. # This file is part of YouCompleteMe.
  6. #
  7. # YouCompleteMe is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # YouCompleteMe is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
  19. from mock import MagicMock
  20. from nose.tools import eq_
  21. from hamcrest import assert_that, has_entries
  22. from ycm.client.omni_completion_request import OmniCompletionRequest
  23. def BuildOmnicompletionRequest( results ):
  24. omni_completer = MagicMock()
  25. omni_completer.ComputeCandidates = MagicMock( return_value = results )
  26. request = OmniCompletionRequest( omni_completer, None )
  27. request.Start()
  28. return request;
  29. def Done_AlwaysTrue_test():
  30. request = BuildOmnicompletionRequest( [] )
  31. eq_( request.Done(), True )
  32. def Response_FromOmniCompleter_test():
  33. results = [ { "word": "test" } ]
  34. request = BuildOmnicompletionRequest( results )
  35. eq_( request.Response(), results )
  36. def RawResponse_ConvertedFromOmniCompleter_test():
  37. vim_results = [
  38. { "word": "WORD", "abbr": "ABBR", "menu": "MENU",
  39. "kind": "KIND", "info": "INFO" },
  40. { "word": "WORD2", "abbr": "ABBR2", "menu": "MENU2",
  41. "kind": "KIND2", "info": "INFO" },
  42. { "word": "WORD", "abbr": "ABBR", },
  43. { },
  44. ]
  45. expected_results = [
  46. has_entries( { "insertion_text": "WORD", "menu_text": "ABBR",
  47. "extra_menu_info": "MENU", "kind": [ "KIND" ],
  48. "detailed_info": "INFO" } ),
  49. has_entries( { "insertion_text": "WORD2", "menu_text": "ABBR2",
  50. "extra_menu_info": "MENU2", "kind": [ "KIND2" ],
  51. "detailed_info": "INFO" } ),
  52. has_entries( { "insertion_text": "WORD", "menu_text": "ABBR", } ),
  53. has_entries( { } ),
  54. ]
  55. request = BuildOmnicompletionRequest( vim_results )
  56. results = request.RawResponse()
  57. eq_( len( results ), len( expected_results ) )
  58. for result, expected_result in zip( results, expected_results ):
  59. assert_that( result, expected_result )