completion_request_test.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/usr/bin/env python
  2. #
  3. # Copyright (C) 2015 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 nose.tools import eq_
  20. from ycm.test_utils import MockVimModule
  21. vim_mock = MockVimModule()
  22. import os
  23. from .. import completion_request
  24. class ConvertCompletionResponseToVimDatas_test:
  25. """ This class tests the
  26. completion_request._ConvertCompletionResponseToVimDatas method """
  27. def _Check( self, completion_data, expected_vim_data ):
  28. vim_data = completion_request._ConvertCompletionDataToVimData(
  29. completion_data )
  30. try:
  31. eq_( expected_vim_data, vim_data )
  32. except:
  33. print "Expected:\n'{0}'\nwhen parsing:\n'{1}'\nBut found:\n'{2}'".format(
  34. expected_vim_data,
  35. completion_data,
  36. vim_data )
  37. raise
  38. def All_Fields_test( self ):
  39. self._Check( {
  40. 'insertion_text': 'INSERTION TEXT',
  41. 'menu_text': 'MENU TEXT',
  42. 'extra_menu_info': 'EXTRA MENU INFO',
  43. 'kind': 'K',
  44. 'detailed_info': 'DETAILED INFO',
  45. 'extra_data': {
  46. 'doc_string': 'DOC STRING',
  47. },
  48. }, {
  49. 'word': 'INSERTION TEXT',
  50. 'abbr': 'MENU TEXT',
  51. 'menu': 'EXTRA MENU INFO',
  52. 'kind': 'k',
  53. 'info': 'DETAILED INFO' + os.linesep + 'DOC STRING',
  54. 'dup' : 1,
  55. } )
  56. def Just_Detailed_Info_test( self ):
  57. self._Check( {
  58. 'insertion_text': 'INSERTION TEXT',
  59. 'menu_text': 'MENU TEXT',
  60. 'extra_menu_info': 'EXTRA MENU INFO',
  61. 'kind': 'K',
  62. 'detailed_info': 'DETAILED INFO',
  63. }, {
  64. 'word': 'INSERTION TEXT',
  65. 'abbr': 'MENU TEXT',
  66. 'menu': 'EXTRA MENU INFO',
  67. 'kind': 'k',
  68. 'info': 'DETAILED INFO',
  69. 'dup' : 1,
  70. } )
  71. def Just_Doc_String_test( self ):
  72. self._Check( {
  73. 'insertion_text': 'INSERTION TEXT',
  74. 'menu_text': 'MENU TEXT',
  75. 'extra_menu_info': 'EXTRA MENU INFO',
  76. 'kind': 'K',
  77. 'extra_data': {
  78. 'doc_string': 'DOC STRING',
  79. },
  80. }, {
  81. 'word': 'INSERTION TEXT',
  82. 'abbr': 'MENU TEXT',
  83. 'menu': 'EXTRA MENU INFO',
  84. 'kind': 'k',
  85. 'info': 'DOC STRING',
  86. 'dup' : 1,
  87. } )
  88. def Extra_Info_No_Doc_String_test( self ):
  89. self._Check( {
  90. 'insertion_text': 'INSERTION TEXT',
  91. 'menu_text': 'MENU TEXT',
  92. 'extra_menu_info': 'EXTRA MENU INFO',
  93. 'kind': 'K',
  94. 'extra_data': {
  95. },
  96. }, {
  97. 'word': 'INSERTION TEXT',
  98. 'abbr': 'MENU TEXT',
  99. 'menu': 'EXTRA MENU INFO',
  100. 'kind': 'k',
  101. 'dup' : 1,
  102. } )
  103. def Extra_Info_No_Doc_String_With_Detailed_Info_test( self ):
  104. self._Check( {
  105. 'insertion_text': 'INSERTION TEXT',
  106. 'menu_text': 'MENU TEXT',
  107. 'extra_menu_info': 'EXTRA MENU INFO',
  108. 'kind': 'K',
  109. 'detailed_info': 'DETAILED INFO',
  110. 'extra_data': {
  111. },
  112. }, {
  113. 'word': 'INSERTION TEXT',
  114. 'abbr': 'MENU TEXT',
  115. 'menu': 'EXTRA MENU INFO',
  116. 'kind': 'k',
  117. 'info': 'DETAILED INFO',
  118. 'dup' : 1,
  119. } )