1
0

completion_request_test.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. # Copyright (C) 2015-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 __future__ import unicode_literals
  18. from __future__ import print_function
  19. from __future__ import division
  20. from __future__ import absolute_import
  21. # Not installing aliases from python-future; it's unreliable and slow.
  22. from builtins import * # noqa
  23. from nose.tools import eq_
  24. from ycm.tests.test_utils import MockVimModule
  25. vim_mock = MockVimModule()
  26. from ycm.client import completion_request
  27. class ConvertCompletionResponseToVimDatas_test( object ):
  28. """ This class tests the
  29. completion_request._ConvertCompletionResponseToVimDatas method """
  30. def _Check( self, completion_data, expected_vim_data ):
  31. vim_data = completion_request.ConvertCompletionDataToVimData(
  32. completion_data )
  33. try:
  34. eq_( expected_vim_data, vim_data )
  35. except:
  36. print( "Expected:\n'{0}'\nwhen parsing:\n'{1}'\nBut found:\n'{2}'".format(
  37. expected_vim_data,
  38. completion_data,
  39. vim_data ) )
  40. raise
  41. def All_Fields_test( self ):
  42. self._Check( {
  43. 'insertion_text': 'INSERTION TEXT',
  44. 'menu_text': 'MENU TEXT',
  45. 'extra_menu_info': 'EXTRA MENU INFO',
  46. 'kind': 'K',
  47. 'detailed_info': 'DETAILED INFO',
  48. 'extra_data': {
  49. 'doc_string': 'DOC STRING',
  50. },
  51. }, {
  52. 'word' : 'INSERTION TEXT',
  53. 'abbr' : 'MENU TEXT',
  54. 'menu' : 'EXTRA MENU INFO',
  55. 'kind' : 'k',
  56. 'info' : 'DETAILED INFO\nDOC STRING',
  57. 'dup' : 1,
  58. 'empty': 1,
  59. } )
  60. def Just_Detailed_Info_test( self ):
  61. self._Check( {
  62. 'insertion_text': 'INSERTION TEXT',
  63. 'menu_text': 'MENU TEXT',
  64. 'extra_menu_info': 'EXTRA MENU INFO',
  65. 'kind': 'K',
  66. 'detailed_info': 'DETAILED INFO',
  67. }, {
  68. 'word' : 'INSERTION TEXT',
  69. 'abbr' : 'MENU TEXT',
  70. 'menu' : 'EXTRA MENU INFO',
  71. 'kind' : 'k',
  72. 'info' : 'DETAILED INFO',
  73. 'dup' : 1,
  74. 'empty': 1,
  75. } )
  76. def Just_Doc_String_test( self ):
  77. self._Check( {
  78. 'insertion_text': 'INSERTION TEXT',
  79. 'menu_text': 'MENU TEXT',
  80. 'extra_menu_info': 'EXTRA MENU INFO',
  81. 'kind': 'K',
  82. 'extra_data': {
  83. 'doc_string': 'DOC STRING',
  84. },
  85. }, {
  86. 'word' : 'INSERTION TEXT',
  87. 'abbr' : 'MENU TEXT',
  88. 'menu' : 'EXTRA MENU INFO',
  89. 'kind' : 'k',
  90. 'info' : 'DOC STRING',
  91. 'dup' : 1,
  92. 'empty': 1,
  93. } )
  94. def Extra_Info_No_Doc_String_test( self ):
  95. self._Check( {
  96. 'insertion_text': 'INSERTION TEXT',
  97. 'menu_text': 'MENU TEXT',
  98. 'extra_menu_info': 'EXTRA MENU INFO',
  99. 'kind': 'K',
  100. 'extra_data': {
  101. },
  102. }, {
  103. 'word' : 'INSERTION TEXT',
  104. 'abbr' : 'MENU TEXT',
  105. 'menu' : 'EXTRA MENU INFO',
  106. 'kind' : 'k',
  107. 'dup' : 1,
  108. 'empty': 1,
  109. } )
  110. def Extra_Info_No_Doc_String_With_Detailed_Info_test( self ):
  111. self._Check( {
  112. 'insertion_text': 'INSERTION TEXT',
  113. 'menu_text': 'MENU TEXT',
  114. 'extra_menu_info': 'EXTRA MENU INFO',
  115. 'kind': 'K',
  116. 'detailed_info': 'DETAILED INFO',
  117. 'extra_data': {
  118. },
  119. }, {
  120. 'word' : 'INSERTION TEXT',
  121. 'abbr' : 'MENU TEXT',
  122. 'menu' : 'EXTRA MENU INFO',
  123. 'kind' : 'k',
  124. 'info' : 'DETAILED INFO',
  125. 'dup' : 1,
  126. 'empty': 1,
  127. } )
  128. def Empty_Insertion_Text_test( self ):
  129. self._Check( {
  130. 'insertion_text': '',
  131. 'menu_text': 'MENU TEXT',
  132. 'extra_menu_info': 'EXTRA MENU INFO',
  133. 'kind': 'K',
  134. 'detailed_info': 'DETAILED INFO',
  135. 'extra_data': {
  136. 'doc_string': 'DOC STRING',
  137. },
  138. }, {
  139. 'word' : '',
  140. 'abbr' : 'MENU TEXT',
  141. 'menu' : 'EXTRA MENU INFO',
  142. 'kind' : 'k',
  143. 'info' : 'DETAILED INFO\nDOC STRING',
  144. 'dup' : 1,
  145. 'empty': 1,
  146. } )
  147. def No_Insertion_Text_test( self ):
  148. self._Check( {
  149. 'menu_text': 'MENU TEXT',
  150. 'extra_menu_info': 'EXTRA MENU INFO',
  151. 'kind': 'K',
  152. 'detailed_info': 'DETAILED INFO',
  153. 'extra_data': {
  154. 'doc_string': 'DOC STRING',
  155. },
  156. }, {
  157. 'word' : '',
  158. 'abbr' : 'MENU TEXT',
  159. 'menu' : 'EXTRA MENU INFO',
  160. 'kind' : 'k',
  161. 'info' : 'DETAILED INFO\nDOC STRING',
  162. 'dup' : 1,
  163. 'empty': 1,
  164. } )