1
0

basic_test.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #!/usr/bin/env python
  2. #
  3. # Copyright (C) 2013 Strahinja Val Markovic <val@markovic.io>
  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 webtest import TestApp
  20. from .. import ycmd
  21. from ..responses import BuildCompletionData
  22. from nose.tools import ok_, eq_, with_setup
  23. import bottle
  24. bottle.debug( True )
  25. # 'contents' should be just one line of text
  26. def RequestDataForFileWithContents( filename, contents ):
  27. return {
  28. 'filetypes': ['foo'],
  29. 'filepath': filename,
  30. 'line_value': contents,
  31. 'file_data': {
  32. filename: {
  33. 'contents': contents,
  34. 'filetypes': ['foo']
  35. }
  36. }
  37. }
  38. def Setup():
  39. ycmd.SetServerStateToDefaults()
  40. @with_setup( Setup )
  41. def GetCompletions_IdentifierCompleter_Works_test():
  42. app = TestApp( ycmd.app )
  43. event_data = RequestDataForFileWithContents( '/foo/bar', 'foo foogoo ba' )
  44. event_data.update( {
  45. 'event_name': 'FileReadyToParse',
  46. } )
  47. app.post_json( '/event_notification', event_data )
  48. completion_data = RequestDataForFileWithContents( '/foo/bar',
  49. 'oo foo foogoo ba' )
  50. completion_data.update( {
  51. 'query': 'oo',
  52. 'line_num': 0,
  53. 'column_num': 2,
  54. 'start_column': 0,
  55. } )
  56. eq_( [ BuildCompletionData( 'foo' ),
  57. BuildCompletionData( 'foogoo' ) ],
  58. app.post_json( '/get_completions', completion_data ).json )
  59. @with_setup( Setup )
  60. def GetCompletions_IdentifierCompleter_SyntaxKeywordsAdded_test():
  61. app = TestApp( ycmd.app )
  62. event_data = RequestDataForFileWithContents( '/foo/bar', '' )
  63. event_data.update( {
  64. 'event_name': 'FileReadyToParse',
  65. 'syntax_keywords': ['foo', 'bar', 'zoo']
  66. } )
  67. app.post_json( '/event_notification', event_data )
  68. completion_data = RequestDataForFileWithContents( '/foo/bar',
  69. 'oo ' )
  70. completion_data.update( {
  71. 'query': 'oo',
  72. 'line_num': 0,
  73. 'column_num': 2,
  74. 'start_column': 0,
  75. } )
  76. eq_( [ BuildCompletionData( 'foo' ),
  77. BuildCompletionData( 'zoo' ) ],
  78. app.post_json( '/get_completions', completion_data ).json )
  79. @with_setup( Setup )
  80. def GetCompletions_UltiSnipsCompleter_Works_test():
  81. app = TestApp( ycmd.app )
  82. event_data = RequestDataForFileWithContents( '/foo/bar', '' )
  83. event_data.update( {
  84. 'event_name': 'BufferVisit',
  85. 'ultisnips_snippets': [
  86. {'trigger': 'foo', 'description': 'bar'},
  87. {'trigger': 'zoo', 'description': 'goo'},
  88. ]
  89. } )
  90. app.post_json( '/event_notification', event_data )
  91. completion_data = RequestDataForFileWithContents( '/foo/bar', 'oo ' )
  92. completion_data.update( {
  93. 'query': 'oo',
  94. 'line_num': 0,
  95. 'column_num': 2,
  96. 'start_column': 0,
  97. } )
  98. eq_( [ BuildCompletionData( 'foo', '<snip> bar' ),
  99. BuildCompletionData( 'zoo', '<snip> goo' ) ],
  100. app.post_json( '/get_completions', completion_data ).json )
  101. @with_setup( Setup )
  102. def RunCompleterCommand_GoTo_Jedi_ZeroBasedLineAndColumn_test():
  103. app = TestApp( ycmd.app )
  104. contents = """
  105. def foo():
  106. pass
  107. foo()
  108. """
  109. goto_data = {
  110. 'completer_target': 'filetype_default',
  111. 'command_arguments': ['GoToDefinition'],
  112. 'line_num': 4,
  113. 'column_num': 0,
  114. 'filetypes': ['python'],
  115. 'filepath': '/foo.py',
  116. 'line_value': contents,
  117. 'file_data': {
  118. '/foo.py': {
  119. 'contents': contents,
  120. 'filetypes': ['python']
  121. }
  122. }
  123. }
  124. # 0-based line and column!
  125. eq_( {
  126. 'filepath': '/foo.py',
  127. 'line_num': 1,
  128. 'column_num': 4
  129. },
  130. app.post_json( '/run_completer_command', goto_data ).json )
  131. @with_setup( Setup )
  132. def FiletypeCompletionAvailable_Works_test():
  133. app = TestApp( ycmd.app )
  134. request_data = {
  135. 'filetypes': ['cpp']
  136. }
  137. ok_( app.post_json( '/filetype_completion_available',
  138. request_data ).json )
  139. @with_setup( Setup )
  140. def UserOptions_Works_test():
  141. app = TestApp( ycmd.app )
  142. options = app.get( '/user_options' ).json
  143. ok_( len( options ) )
  144. options[ 'foobar' ] = 'zoo'
  145. app.post_json( '/user_options', options )
  146. eq_( options, app.get( '/user_options' ).json )