completion_request_test.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. # Copyright (C) 2015-2019 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_id, completion_data, expected_vim_data ):
  31. vim_data = completion_request._ConvertCompletionDataToVimData(
  32. completion_id,
  33. completion_data )
  34. try:
  35. eq_( expected_vim_data, vim_data )
  36. except Exception:
  37. print( "Expected:\n'{}'\nwhen parsing:\n'{}'\nBut found:\n'{}'".format(
  38. expected_vim_data,
  39. completion_data,
  40. vim_data ) )
  41. raise
  42. def AllFields_test( self ):
  43. self._Check( 0, {
  44. 'insertion_text': 'INSERTION TEXT',
  45. 'menu_text': 'MENU TEXT',
  46. 'extra_menu_info': 'EXTRA MENU INFO',
  47. 'kind': 'K',
  48. 'detailed_info': 'DETAILED INFO',
  49. 'extra_data': {
  50. 'doc_string': 'DOC STRING',
  51. },
  52. }, {
  53. 'word' : 'INSERTION TEXT',
  54. 'abbr' : 'MENU TEXT',
  55. 'menu' : 'EXTRA MENU INFO',
  56. 'kind' : 'k',
  57. 'info' : 'DETAILED INFO\nDOC STRING',
  58. 'equal' : 1,
  59. 'dup' : 1,
  60. 'empty' : 1,
  61. 'user_data': '0',
  62. } )
  63. def OnlyInsertionTextField_test( self ):
  64. self._Check( 17, {
  65. 'insertion_text': 'INSERTION TEXT'
  66. }, {
  67. 'word' : 'INSERTION TEXT',
  68. 'abbr' : '',
  69. 'menu' : '',
  70. 'kind' : '',
  71. 'info' : '',
  72. 'equal' : 1,
  73. 'dup' : 1,
  74. 'empty' : 1,
  75. 'user_data': '17',
  76. } )
  77. def JustDetailedInfo_test( self ):
  78. self._Check( 9999999999, {
  79. 'insertion_text': 'INSERTION TEXT',
  80. 'menu_text': 'MENU TEXT',
  81. 'extra_menu_info': 'EXTRA MENU INFO',
  82. 'kind': 'K',
  83. 'detailed_info': 'DETAILED INFO',
  84. }, {
  85. 'word' : 'INSERTION TEXT',
  86. 'abbr' : 'MENU TEXT',
  87. 'menu' : 'EXTRA MENU INFO',
  88. 'kind' : 'k',
  89. 'info' : 'DETAILED INFO',
  90. 'equal' : 1,
  91. 'dup' : 1,
  92. 'empty' : 1,
  93. 'user_data': '9999999999',
  94. } )
  95. def JustDocString_test( self ):
  96. self._Check( 'not_an_int', {
  97. 'insertion_text': 'INSERTION TEXT',
  98. 'menu_text': 'MENU TEXT',
  99. 'extra_menu_info': 'EXTRA MENU INFO',
  100. 'kind': 'K',
  101. 'extra_data': {
  102. 'doc_string': 'DOC STRING',
  103. },
  104. }, {
  105. 'word' : 'INSERTION TEXT',
  106. 'abbr' : 'MENU TEXT',
  107. 'menu' : 'EXTRA MENU INFO',
  108. 'kind' : 'k',
  109. 'info' : 'DOC STRING',
  110. 'equal' : 1,
  111. 'dup' : 1,
  112. 'empty' : 1,
  113. 'user_data': 'not_an_int',
  114. } )
  115. def ExtraInfoNoDocString_test( self ):
  116. self._Check( 0, {
  117. 'insertion_text': 'INSERTION TEXT',
  118. 'menu_text': 'MENU TEXT',
  119. 'extra_menu_info': 'EXTRA MENU INFO',
  120. 'kind': 'K',
  121. 'extra_data': {
  122. },
  123. }, {
  124. 'word' : 'INSERTION TEXT',
  125. 'abbr' : 'MENU TEXT',
  126. 'menu' : 'EXTRA MENU INFO',
  127. 'kind' : 'k',
  128. 'info' : '',
  129. 'equal' : 1,
  130. 'dup' : 1,
  131. 'empty' : 1,
  132. 'user_data': '0',
  133. } )
  134. def NullCharactersInExtraInfoAndDocString_test( self ):
  135. self._Check( '0', {
  136. 'insertion_text': 'INSERTION TEXT',
  137. 'menu_text': 'MENU TEXT',
  138. 'extra_menu_info': 'EXTRA MENU INFO',
  139. 'kind': 'K',
  140. 'detailed_info': 'DETAILED\x00INFO',
  141. 'extra_data': {
  142. 'doc_string': 'DOC\x00STRING'
  143. },
  144. }, {
  145. 'word' : 'INSERTION TEXT',
  146. 'abbr' : 'MENU TEXT',
  147. 'menu' : 'EXTRA MENU INFO',
  148. 'kind' : 'k',
  149. 'info' : 'DETAILEDINFO\nDOCSTRING',
  150. 'equal' : 1,
  151. 'dup' : 1,
  152. 'empty' : 1,
  153. 'user_data': '0',
  154. } )
  155. def ExtraInfoNoDocStringWithDetailedInfo_test( self ):
  156. self._Check( '0', {
  157. 'insertion_text': 'INSERTION TEXT',
  158. 'menu_text': 'MENU TEXT',
  159. 'extra_menu_info': 'EXTRA MENU INFO',
  160. 'kind': 'K',
  161. 'detailed_info': 'DETAILED INFO',
  162. 'extra_data': {
  163. },
  164. }, {
  165. 'word' : 'INSERTION TEXT',
  166. 'abbr' : 'MENU TEXT',
  167. 'menu' : 'EXTRA MENU INFO',
  168. 'kind' : 'k',
  169. 'info' : 'DETAILED INFO',
  170. 'equal' : 1,
  171. 'dup' : 1,
  172. 'empty' : 1,
  173. 'user_data': '0',
  174. } )
  175. def EmptyInsertionText_test( self ):
  176. self._Check( 0, {
  177. 'insertion_text': '',
  178. 'menu_text': 'MENU TEXT',
  179. 'extra_menu_info': 'EXTRA MENU INFO',
  180. 'kind': 'K',
  181. 'detailed_info': 'DETAILED INFO',
  182. 'extra_data': {
  183. 'doc_string': 'DOC STRING',
  184. },
  185. }, {
  186. 'word' : '',
  187. 'abbr' : 'MENU TEXT',
  188. 'menu' : 'EXTRA MENU INFO',
  189. 'kind' : 'k',
  190. 'info' : 'DETAILED INFO\nDOC STRING',
  191. 'equal' : 1,
  192. 'dup' : 1,
  193. 'empty' : 1,
  194. 'user_data': '0',
  195. } )