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/>.
|
|
|
|
|
2013-10-14 18:29:00 -04:00
|
|
|
from ..server_utils import SetUpPythonPath
|
|
|
|
SetUpPythonPath()
|
2013-10-26 15:15:56 -04:00
|
|
|
import time
|
|
|
|
import httplib
|
2013-11-15 19:21:06 -05:00
|
|
|
from .test_utils import ( Setup, BuildRequest, PathToTestFile,
|
|
|
|
ChangeSpecificOptions )
|
2013-09-20 20:24:34 -04:00
|
|
|
from webtest import TestApp
|
2013-10-26 15:15:56 -04:00
|
|
|
from nose.tools import eq_, with_setup
|
2013-10-26 19:22:43 -04:00
|
|
|
from hamcrest import ( assert_that, has_item, has_items, has_entry,
|
2013-10-26 15:15:56 -04:00
|
|
|
contains_inanyorder )
|
2013-10-08 19:21:43 -04:00
|
|
|
from ..responses import BuildCompletionData, UnknownExtraConf
|
2013-10-26 15:15:56 -04:00
|
|
|
from .. import handlers
|
2013-09-20 20:24:34 -04:00
|
|
|
import bottle
|
|
|
|
|
|
|
|
bottle.debug( True )
|
|
|
|
|
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
|
|
|
@with_setup( Setup )
|
|
|
|
def GetCompletions_IdentifierCompleter_Works_test():
|
2013-10-14 18:29:00 -04:00
|
|
|
app = TestApp( handlers.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-10-09 00:30:53 -04:00
|
|
|
@with_setup( Setup )
|
|
|
|
def GetCompletions_CsCompleter_Works_test():
|
2013-10-14 18:29:00 -04:00
|
|
|
app = TestApp( handlers.app )
|
2013-10-09 00:30:53 -04:00
|
|
|
filepath = PathToTestFile( 'testy/Program.cs' )
|
|
|
|
contents = open( filepath ).read()
|
|
|
|
event_data = BuildRequest( filepath = filepath,
|
|
|
|
filetype = 'cs',
|
|
|
|
contents = contents,
|
|
|
|
event_name = 'FileReadyToParse' )
|
|
|
|
|
|
|
|
app.post_json( '/event_notification', event_data )
|
|
|
|
|
|
|
|
# We need to wait until the server has started up.
|
2013-10-09 16:17:53 -04:00
|
|
|
while True:
|
|
|
|
result = app.post_json( '/run_completer_command',
|
|
|
|
BuildRequest( completer_target = 'filetype_default',
|
|
|
|
command_arguments = ['ServerRunning'],
|
|
|
|
filetype = 'cs' ) ).json
|
|
|
|
if result:
|
|
|
|
break
|
|
|
|
time.sleep( 0.2 )
|
2013-10-09 00:30:53 -04:00
|
|
|
|
|
|
|
completion_data = BuildRequest( filepath = filepath,
|
|
|
|
filetype = 'cs',
|
|
|
|
contents = contents,
|
|
|
|
line_num = 8,
|
|
|
|
column_num = 11,
|
|
|
|
start_column = 11 )
|
|
|
|
|
|
|
|
results = app.post_json( '/completions', completion_data ).json
|
|
|
|
assert_that( results, has_items( CompletionEntryMatcher( 'CursorLeft' ),
|
|
|
|
CompletionEntryMatcher( 'CursorSize' ) ) )
|
|
|
|
|
2013-10-26 15:30:49 -04:00
|
|
|
# We need to turn off the CS server so that it doesn't stick around
|
|
|
|
app.post_json( '/run_completer_command',
|
|
|
|
BuildRequest( completer_target = 'filetype_default',
|
|
|
|
command_arguments = ['StopServer'],
|
|
|
|
filetype = 'cs' ) )
|
|
|
|
|
2013-10-09 00:30:53 -04:00
|
|
|
|
2013-09-30 16:40:25 -04:00
|
|
|
@with_setup( Setup )
|
2013-10-08 19:21:43 -04:00
|
|
|
def GetCompletions_ClangCompleter_WorksWithExplicitFlags_test():
|
2013-10-14 18:29:00 -04:00
|
|
|
app = TestApp( handlers.app )
|
2013-09-30 16:40:25 -04:00
|
|
|
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-10-08 19:21:43 -04:00
|
|
|
assert_that( results, has_items( CompletionEntryMatcher( 'c' ),
|
|
|
|
CompletionEntryMatcher( 'x' ),
|
|
|
|
CompletionEntryMatcher( 'y' ) ) )
|
|
|
|
|
|
|
|
|
|
|
|
@with_setup( Setup )
|
|
|
|
def GetCompletions_ClangCompleter_UnknownExtraConfException_test():
|
2013-10-14 18:29:00 -04:00
|
|
|
app = TestApp( handlers.app )
|
2013-10-08 19:21:43 -04:00
|
|
|
filepath = PathToTestFile( 'basic.cpp' )
|
|
|
|
completion_data = BuildRequest( filepath = filepath,
|
|
|
|
filetype = 'cpp',
|
|
|
|
contents = open( filepath ).read(),
|
|
|
|
force_semantic = True )
|
|
|
|
|
|
|
|
response = app.post_json( '/completions',
|
|
|
|
completion_data,
|
|
|
|
expect_errors = True )
|
|
|
|
|
|
|
|
eq_( response.status_code, httplib.INTERNAL_SERVER_ERROR )
|
|
|
|
assert_that( response.json,
|
|
|
|
has_entry( 'exception',
|
|
|
|
has_entry( 'TYPE', UnknownExtraConf.__name__ ) ) )
|
|
|
|
|
|
|
|
|
|
|
|
@with_setup( Setup )
|
|
|
|
def GetCompletions_ClangCompleter_WorksWhenExtraConfExplicitlyAllowed_test():
|
2013-10-14 18:29:00 -04:00
|
|
|
app = TestApp( handlers.app )
|
2013-10-08 19:21:43 -04:00
|
|
|
app.post_json( '/load_extra_conf_file',
|
|
|
|
{ 'filepath': PathToTestFile( '.ycm_extra_conf.py' ) } )
|
|
|
|
|
|
|
|
filepath = PathToTestFile( 'basic.cpp' )
|
|
|
|
completion_data = BuildRequest( filepath = filepath,
|
|
|
|
filetype = 'cpp',
|
|
|
|
contents = open( filepath ).read(),
|
|
|
|
line_num = 10,
|
|
|
|
column_num = 6,
|
|
|
|
start_column = 6 )
|
|
|
|
|
|
|
|
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-11-17 16:45:39 -05:00
|
|
|
@with_setup( Setup )
|
|
|
|
def GetCompletions_ClangCompleter_ExceptionWhenNoFlagsFromExtraConf_test():
|
|
|
|
app = TestApp( handlers.app )
|
|
|
|
app.post_json( '/load_extra_conf_file',
|
|
|
|
{ 'filepath': PathToTestFile(
|
|
|
|
'noflags/.ycm_extra_conf.py' ) } )
|
|
|
|
|
|
|
|
filepath = PathToTestFile( 'noflags/basic.cpp' )
|
|
|
|
completion_data = BuildRequest( filepath = filepath,
|
|
|
|
filetype = 'cpp',
|
|
|
|
contents = open( filepath ).read(),
|
|
|
|
line_num = 10,
|
|
|
|
column_num = 6,
|
|
|
|
start_column = 6 )
|
|
|
|
|
|
|
|
response = app.post_json( '/completions',
|
|
|
|
completion_data,
|
|
|
|
expect_errors = True )
|
|
|
|
eq_( response.status_code, httplib.INTERNAL_SERVER_ERROR )
|
|
|
|
assert_that( response.json,
|
|
|
|
has_entry( 'exception',
|
|
|
|
has_entry( 'TYPE', RuntimeError.__name__ ) ) )
|
|
|
|
|
2013-09-30 16:40:25 -04:00
|
|
|
|
2013-10-09 23:20:34 -04:00
|
|
|
@with_setup( Setup )
|
|
|
|
def GetCompletions_ClangCompleter_ForceSemantic_OnlyFileteredCompletions_test():
|
2013-10-14 18:29:00 -04:00
|
|
|
app = TestApp( handlers.app )
|
2013-10-09 23:20:34 -04:00
|
|
|
contents = """
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int foobar;
|
|
|
|
int floozar;
|
|
|
|
int gooboo;
|
|
|
|
int bleble;
|
|
|
|
|
|
|
|
fooar
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
# 0-based line and column!
|
|
|
|
completion_data = BuildRequest( filepath = '/foo.cpp',
|
|
|
|
filetype = 'cpp',
|
|
|
|
force_semantic = True,
|
|
|
|
contents = contents,
|
|
|
|
line_num = 8,
|
|
|
|
column_num = 7,
|
|
|
|
start_column = 7,
|
|
|
|
query = 'fooar',
|
|
|
|
compilation_flags = ['-x', 'c++'] )
|
|
|
|
|
|
|
|
results = app.post_json( '/completions', completion_data ).json
|
|
|
|
assert_that( results,
|
|
|
|
contains_inanyorder( CompletionEntryMatcher( 'foobar' ),
|
|
|
|
CompletionEntryMatcher( 'floozar' ) ) )
|
|
|
|
|
|
|
|
|
2013-10-07 16:09:34 -04:00
|
|
|
@with_setup( Setup )
|
|
|
|
def GetCompletions_ForceSemantic_Works_test():
|
2013-10-14 18:29:00 -04:00
|
|
|
app = TestApp( handlers.app )
|
2013-10-07 16:09:34 -04:00
|
|
|
|
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-10-26 19:22:43 -04:00
|
|
|
@with_setup( Setup )
|
|
|
|
def GetCompletions_ClangCompleter_ClientDataGivenToExtraConf_test():
|
|
|
|
app = TestApp( handlers.app )
|
|
|
|
app.post_json( '/load_extra_conf_file',
|
|
|
|
{ 'filepath': PathToTestFile(
|
|
|
|
'client_data/.ycm_extra_conf.py' ) } )
|
|
|
|
|
|
|
|
filepath = PathToTestFile( 'client_data/main.cpp' )
|
|
|
|
completion_data = BuildRequest( filepath = filepath,
|
|
|
|
filetype = 'cpp',
|
|
|
|
contents = open( filepath ).read(),
|
|
|
|
line_num = 8,
|
|
|
|
column_num = 6,
|
|
|
|
start_column = 6,
|
|
|
|
extra_conf_data = {
|
|
|
|
'flags': ['-x', 'c++']
|
|
|
|
})
|
|
|
|
|
|
|
|
results = app.post_json( '/completions', completion_data ).json
|
|
|
|
assert_that( results, has_item( CompletionEntryMatcher( 'x' ) ) )
|
|
|
|
|
|
|
|
|
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-10-14 18:29:00 -04:00
|
|
|
app = TestApp( handlers.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():
|
2013-10-14 18:29:00 -04:00
|
|
|
app = TestApp( handlers.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-11-15 19:21:06 -05:00
|
|
|
@with_setup( Setup )
|
|
|
|
def GetCompletions_UltiSnipsCompleter_UnusedWhenOffWithOption_test():
|
|
|
|
ChangeSpecificOptions( { 'use_ultisnips_completer': False } )
|
|
|
|
app = TestApp( handlers.app )
|
|
|
|
|
|
|
|
event_data = BuildRequest(
|
|
|
|
event_name = 'BufferVisit',
|
|
|
|
ultisnips_snippets = [
|
|
|
|
{'trigger': 'foo', 'description': 'bar'},
|
|
|
|
{'trigger': 'zoo', 'description': 'goo'},
|
|
|
|
] )
|
|
|
|
|
|
|
|
app.post_json( '/event_notification', event_data )
|
|
|
|
|
|
|
|
completion_data = BuildRequest( contents = 'oo ',
|
|
|
|
query = 'oo',
|
|
|
|
column_num = 2 )
|
|
|
|
|
|
|
|
eq_( [], app.post_json( '/completions', completion_data ).json )
|
|
|
|
|
|
|
|
|