2013-09-20 20:24:34 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright (C) 2013 Strahinja Val Markovic <val@markovic.io>
|
|
|
|
#
|
|
|
|
# This file is part of YouCompleteMe.
|
|
|
|
#
|
|
|
|
# YouCompleteMe is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# YouCompleteMe is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
from webtest import TestApp
|
2013-09-24 17:04:08 -04:00
|
|
|
from .. import ycmd
|
2013-09-20 20:24:34 -04:00
|
|
|
from ..responses import BuildCompletionData
|
2013-09-25 13:56:46 -04:00
|
|
|
from nose.tools import ok_, eq_, with_setup
|
2013-10-03 13:14:31 -04:00
|
|
|
from hamcrest import ( assert_that, has_items, has_entry, contains,
|
|
|
|
contains_string, has_entries )
|
2013-09-20 20:24:34 -04:00
|
|
|
import bottle
|
|
|
|
|
|
|
|
bottle.debug( True )
|
|
|
|
|
2013-10-04 20:34:20 -04:00
|
|
|
# TODO: Split this file into multiple files.
|
|
|
|
|
2013-10-07 16:55:29 -04:00
|
|
|
def BuildRequest( **kwargs ):
|
|
|
|
filepath = kwargs[ 'filepath' ] if 'filepath' in kwargs else '/foo'
|
|
|
|
contents = kwargs[ 'contents' ] if 'contents' in kwargs else ''
|
|
|
|
filetype = kwargs[ 'filetype' ] if 'filetype' in kwargs else 'foo'
|
|
|
|
|
|
|
|
request = {
|
2013-10-07 16:09:34 -04:00
|
|
|
'query': '',
|
|
|
|
'line_num': 0,
|
|
|
|
'column_num': 0,
|
|
|
|
'start_column': 0,
|
2013-10-07 16:55:29 -04:00
|
|
|
'filetypes': [ filetype ],
|
|
|
|
'filepath': filepath,
|
|
|
|
'line_value': contents,
|
2013-09-20 20:24:34 -04:00
|
|
|
'file_data': {
|
2013-10-07 16:55:29 -04:00
|
|
|
filepath: {
|
|
|
|
'contents': contents,
|
|
|
|
'filetypes': [ filetype ]
|
2013-09-20 20:24:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-07 16:55:29 -04:00
|
|
|
for key, value in kwargs.iteritems():
|
|
|
|
if key in [ 'contents', 'filetype', 'filepath' ]:
|
|
|
|
continue
|
|
|
|
request[ key ] = value
|
|
|
|
|
|
|
|
if key == 'line_num':
|
|
|
|
lines = contents.splitlines()
|
|
|
|
if len( lines ) > 1:
|
|
|
|
# NOTE: assumes 0-based line_num
|
|
|
|
request[ 'line_value' ] = lines[ value ]
|
|
|
|
|
|
|
|
return request
|
|
|
|
|
2013-09-24 13:04:22 -04:00
|
|
|
|
2013-09-30 16:40:25 -04:00
|
|
|
# TODO: Make the other tests use this helper too instead of BuildCompletionData
|
|
|
|
def CompletionEntryMatcher( insertion_text ):
|
|
|
|
return has_entry( 'insertion_text', insertion_text )
|
|
|
|
|
|
|
|
|
2013-09-25 13:56:46 -04:00
|
|
|
def Setup():
|
|
|
|
ycmd.SetServerStateToDefaults()
|
|
|
|
|
|
|
|
|
|
|
|
@with_setup( Setup )
|
|
|
|
def GetCompletions_IdentifierCompleter_Works_test():
|
2013-09-24 17:04:08 -04:00
|
|
|
app = TestApp( ycmd.app )
|
2013-10-07 16:55:29 -04:00
|
|
|
event_data = BuildRequest( contents = 'foo foogoo ba',
|
|
|
|
event_name = 'FileReadyToParse' )
|
2013-09-24 13:04:22 -04:00
|
|
|
|
2013-09-20 20:24:34 -04:00
|
|
|
app.post_json( '/event_notification', event_data )
|
|
|
|
|
2013-10-07 16:55:29 -04:00
|
|
|
completion_data = BuildRequest( contents = 'oo foo foogoo ba',
|
|
|
|
query = 'oo',
|
|
|
|
column_num = 2 )
|
2013-09-20 20:24:34 -04:00
|
|
|
|
|
|
|
eq_( [ BuildCompletionData( 'foo' ),
|
|
|
|
BuildCompletionData( 'foogoo' ) ],
|
2013-10-02 15:23:26 -04:00
|
|
|
app.post_json( '/completions', completion_data ).json )
|
2013-09-20 20:24:34 -04:00
|
|
|
|
|
|
|
|
2013-09-30 16:40:25 -04:00
|
|
|
@with_setup( Setup )
|
|
|
|
def GetCompletions_ClangCompleter_Works_test():
|
|
|
|
app = TestApp( ycmd.app )
|
|
|
|
contents = """
|
|
|
|
struct Foo {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
char c;
|
|
|
|
};
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
Foo foo;
|
|
|
|
foo.
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2013-10-07 16:55:29 -04:00
|
|
|
# 0-based line and column!
|
|
|
|
completion_data = BuildRequest( filepath = '/foo.cpp',
|
|
|
|
filetype = 'cpp',
|
|
|
|
contents = contents,
|
|
|
|
line_num = 10,
|
|
|
|
column_num = 6,
|
|
|
|
start_column = 6,
|
|
|
|
compilation_flags = ['-x', 'c++'] )
|
2013-09-30 16:40:25 -04:00
|
|
|
|
2013-10-02 15:23:26 -04:00
|
|
|
results = app.post_json( '/completions', completion_data ).json
|
2013-09-30 16:40:25 -04:00
|
|
|
assert_that( results, has_items( CompletionEntryMatcher( 'c' ),
|
|
|
|
CompletionEntryMatcher( 'x' ),
|
|
|
|
CompletionEntryMatcher( 'y' ) ) )
|
|
|
|
|
|
|
|
|
2013-10-07 16:09:34 -04:00
|
|
|
@with_setup( Setup )
|
|
|
|
def GetCompletions_ForceSemantic_Works_test():
|
|
|
|
app = TestApp( ycmd.app )
|
|
|
|
|
2013-10-07 16:55:29 -04:00
|
|
|
completion_data = BuildRequest( filetype = 'python',
|
|
|
|
force_semantic = True )
|
2013-10-07 16:09:34 -04:00
|
|
|
|
|
|
|
results = app.post_json( '/completions', completion_data ).json
|
|
|
|
assert_that( results, has_items( CompletionEntryMatcher( 'abs' ),
|
|
|
|
CompletionEntryMatcher( 'open' ),
|
|
|
|
CompletionEntryMatcher( 'bool' ) ) )
|
|
|
|
|
|
|
|
|
2013-09-25 13:56:46 -04:00
|
|
|
@with_setup( Setup )
|
2013-09-23 18:31:11 -04:00
|
|
|
def GetCompletions_IdentifierCompleter_SyntaxKeywordsAdded_test():
|
2013-09-24 17:04:08 -04:00
|
|
|
app = TestApp( ycmd.app )
|
2013-10-07 16:55:29 -04:00
|
|
|
event_data = BuildRequest( event_name = 'FileReadyToParse',
|
|
|
|
syntax_keywords = ['foo', 'bar', 'zoo'] )
|
2013-09-23 18:31:11 -04:00
|
|
|
|
|
|
|
app.post_json( '/event_notification', event_data )
|
|
|
|
|
2013-10-07 16:55:29 -04:00
|
|
|
completion_data = BuildRequest( contents = 'oo ',
|
|
|
|
query = 'oo',
|
|
|
|
column_num = 2 )
|
2013-09-23 18:31:11 -04:00
|
|
|
|
|
|
|
eq_( [ BuildCompletionData( 'foo' ),
|
|
|
|
BuildCompletionData( 'zoo' ) ],
|
2013-10-02 15:23:26 -04:00
|
|
|
app.post_json( '/completions', completion_data ).json )
|
2013-09-23 18:31:11 -04:00
|
|
|
|
|
|
|
|
2013-09-25 13:56:46 -04:00
|
|
|
@with_setup( Setup )
|
|
|
|
def GetCompletions_UltiSnipsCompleter_Works_test():
|
|
|
|
app = TestApp( ycmd.app )
|
2013-10-07 16:55:29 -04:00
|
|
|
event_data = BuildRequest(
|
|
|
|
event_name = 'BufferVisit',
|
|
|
|
ultisnips_snippets = [
|
2013-09-25 13:56:46 -04:00
|
|
|
{'trigger': 'foo', 'description': 'bar'},
|
|
|
|
{'trigger': 'zoo', 'description': 'goo'},
|
2013-10-07 16:55:29 -04:00
|
|
|
] )
|
2013-09-25 13:56:46 -04:00
|
|
|
|
|
|
|
app.post_json( '/event_notification', event_data )
|
|
|
|
|
2013-10-07 16:55:29 -04:00
|
|
|
completion_data = BuildRequest( contents = 'oo ',
|
|
|
|
query = 'oo',
|
|
|
|
column_num = 2 )
|
2013-09-25 13:56:46 -04:00
|
|
|
|
|
|
|
eq_( [ BuildCompletionData( 'foo', '<snip> bar' ),
|
|
|
|
BuildCompletionData( 'zoo', '<snip> goo' ) ],
|
2013-10-02 15:23:26 -04:00
|
|
|
app.post_json( '/completions', completion_data ).json )
|
2013-09-25 13:56:46 -04:00
|
|
|
|
|
|
|
|
2013-09-27 16:52:04 -04:00
|
|
|
@with_setup( Setup )
|
|
|
|
def RunCompleterCommand_GoTo_Jedi_ZeroBasedLineAndColumn_test():
|
|
|
|
app = TestApp( ycmd.app )
|
|
|
|
contents = """
|
|
|
|
def foo():
|
|
|
|
pass
|
|
|
|
|
|
|
|
foo()
|
|
|
|
"""
|
|
|
|
|
2013-10-07 16:55:29 -04:00
|
|
|
goto_data = BuildRequest( completer_target = 'filetype_default',
|
|
|
|
command_arguments = ['GoToDefinition'],
|
|
|
|
line_num = 4,
|
|
|
|
contents = contents,
|
|
|
|
filetype = 'python',
|
|
|
|
filepath = '/foo.py' )
|
2013-09-27 16:52:04 -04:00
|
|
|
|
|
|
|
# 0-based line and column!
|
|
|
|
eq_( {
|
|
|
|
'filepath': '/foo.py',
|
|
|
|
'line_num': 1,
|
|
|
|
'column_num': 4
|
|
|
|
},
|
|
|
|
app.post_json( '/run_completer_command', goto_data ).json )
|
|
|
|
|
|
|
|
|
2013-09-27 17:59:00 -04:00
|
|
|
@with_setup( Setup )
|
|
|
|
def RunCompleterCommand_GoTo_Clang_ZeroBasedLineAndColumn_test():
|
|
|
|
app = TestApp( ycmd.app )
|
|
|
|
contents = """
|
|
|
|
struct Foo {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
char c;
|
|
|
|
};
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
Foo foo;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2013-10-07 16:55:29 -04:00
|
|
|
goto_data = BuildRequest( completer_target = 'filetype_default',
|
|
|
|
command_arguments = ['GoToDefinition'],
|
|
|
|
compilation_flags = ['-x', 'c++'],
|
|
|
|
line_num = 9,
|
|
|
|
column_num = 2,
|
|
|
|
contents = contents,
|
|
|
|
filetype = 'cpp' )
|
2013-09-27 17:59:00 -04:00
|
|
|
|
|
|
|
# 0-based line and column!
|
|
|
|
eq_( {
|
2013-10-07 16:55:29 -04:00
|
|
|
'filepath': '/foo',
|
2013-09-27 17:59:00 -04:00
|
|
|
'line_num': 1,
|
|
|
|
'column_num': 7
|
|
|
|
},
|
|
|
|
app.post_json( '/run_completer_command', goto_data ).json )
|
|
|
|
|
|
|
|
|
2013-09-27 19:20:35 -04:00
|
|
|
@with_setup( Setup )
|
|
|
|
def DefinedSubcommands_Works_test():
|
|
|
|
app = TestApp( ycmd.app )
|
2013-10-07 16:55:29 -04:00
|
|
|
subcommands_data = BuildRequest( completer_target = 'python' )
|
2013-09-27 19:20:35 -04:00
|
|
|
|
|
|
|
eq_( [ 'GoToDefinition',
|
|
|
|
'GoToDeclaration',
|
|
|
|
'GoToDefinitionElseDeclaration' ],
|
|
|
|
app.post_json( '/defined_subcommands', subcommands_data ).json )
|
|
|
|
|
|
|
|
|
|
|
|
@with_setup( Setup )
|
|
|
|
def DefinedSubcommands_WorksWhenNoExplicitCompleterTargetSpecified_test():
|
|
|
|
app = TestApp( ycmd.app )
|
2013-10-07 16:55:29 -04:00
|
|
|
subcommands_data = BuildRequest( filetype = 'python' )
|
2013-09-27 19:20:35 -04:00
|
|
|
|
|
|
|
eq_( [ 'GoToDefinition',
|
|
|
|
'GoToDeclaration',
|
|
|
|
'GoToDefinitionElseDeclaration' ],
|
|
|
|
app.post_json( '/defined_subcommands', subcommands_data ).json )
|
|
|
|
|
|
|
|
|
2013-10-03 13:14:31 -04:00
|
|
|
@with_setup( Setup )
|
2013-10-03 16:15:43 -04:00
|
|
|
def Diagnostics_ClangCompleter_ZeroBasedLineAndColumn_test():
|
2013-10-03 13:14:31 -04:00
|
|
|
app = TestApp( ycmd.app )
|
|
|
|
contents = """
|
|
|
|
struct Foo {
|
|
|
|
int x // semicolon missing here!
|
|
|
|
int y;
|
|
|
|
int c;
|
|
|
|
int d;
|
|
|
|
};
|
|
|
|
"""
|
|
|
|
|
2013-10-07 16:55:29 -04:00
|
|
|
event_data = BuildRequest( compilation_flags = ['-x', 'c++'],
|
|
|
|
event_name = 'FileReadyToParse',
|
|
|
|
contents = contents,
|
|
|
|
filetype = 'cpp' )
|
2013-10-03 13:14:31 -04:00
|
|
|
|
2013-10-03 16:15:43 -04:00
|
|
|
results = app.post_json( '/event_notification', event_data ).json
|
2013-10-03 13:14:31 -04:00
|
|
|
assert_that( results,
|
|
|
|
contains(
|
|
|
|
has_entries( { 'text': contains_string( "expected ';'" ),
|
|
|
|
'line_num': 2,
|
|
|
|
'column_num': 7 } ) ) )
|
|
|
|
|
|
|
|
|
2013-10-03 17:49:51 -04:00
|
|
|
@with_setup( Setup )
|
|
|
|
def GetDetailedDiagnostic_ClangCompleter_Works_test():
|
|
|
|
app = TestApp( ycmd.app )
|
|
|
|
contents = """
|
|
|
|
struct Foo {
|
|
|
|
int x // semicolon missing here!
|
|
|
|
int y;
|
|
|
|
int c;
|
|
|
|
int d;
|
|
|
|
};
|
|
|
|
"""
|
|
|
|
|
2013-10-07 16:55:29 -04:00
|
|
|
diag_data = BuildRequest( compilation_flags = ['-x', 'c++'],
|
|
|
|
line_num = 2,
|
|
|
|
contents = contents,
|
|
|
|
filetype = 'cpp' )
|
2013-10-03 17:49:51 -04:00
|
|
|
|
|
|
|
event_data = diag_data.copy()
|
|
|
|
event_data.update( {
|
|
|
|
'event_name': 'FileReadyToParse',
|
|
|
|
} )
|
|
|
|
|
|
|
|
app.post_json( '/event_notification', event_data )
|
|
|
|
results = app.post_json( '/detailed_diagnostic', diag_data ).json
|
|
|
|
assert_that( results,
|
|
|
|
has_entry( 'message', contains_string( "expected ';'" ) ) )
|
|
|
|
|
|
|
|
|
2013-09-25 13:56:46 -04:00
|
|
|
@with_setup( Setup )
|
2013-09-20 20:24:34 -04:00
|
|
|
def FiletypeCompletionAvailable_Works_test():
|
2013-09-24 17:04:08 -04:00
|
|
|
app = TestApp( ycmd.app )
|
2013-09-20 20:24:34 -04:00
|
|
|
request_data = {
|
2013-10-04 18:21:30 -04:00
|
|
|
'filetypes': ['python']
|
2013-09-20 20:24:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ok_( app.post_json( '/filetype_completion_available',
|
|
|
|
request_data ).json )
|
2013-09-24 15:53:44 -04:00
|
|
|
|
|
|
|
|
2013-09-25 13:56:46 -04:00
|
|
|
@with_setup( Setup )
|
2013-09-24 15:53:44 -04:00
|
|
|
def UserOptions_Works_test():
|
2013-09-24 17:04:08 -04:00
|
|
|
app = TestApp( ycmd.app )
|
2013-09-24 15:53:44 -04:00
|
|
|
options = app.get( '/user_options' ).json
|
|
|
|
ok_( len( options ) )
|
|
|
|
|
|
|
|
options[ 'foobar' ] = 'zoo'
|
|
|
|
|
|
|
|
app.post_json( '/user_options', options )
|
|
|
|
eq_( options, app.get( '/user_options' ).json )
|
|
|
|
|