Added tests for filename_completer, fixed ordering of completions
This commit is contained in:
parent
619e1c0b83
commit
8520c5f5ac
102
python/ycm/completers/general/tests/filename_completer_test.py
Normal file
102
python/ycm/completers/general/tests/filename_completer_test.py
Normal file
@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2014 Davit Samvelyan <davitsamvelyan@gmail.com>
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
import os
|
||||
from nose.tools import eq_
|
||||
from ycm.completers.general.filename_completer import FilenameCompleter
|
||||
from ycm import user_options_store
|
||||
|
||||
test_dir = os.path.dirname( os.path.abspath( __file__ ) )
|
||||
data_dir = os.path.join( test_dir, "testdata", "filename_completer" )
|
||||
file_path = os.path.join( data_dir, "test.cpp" )
|
||||
|
||||
fnc = FilenameCompleter( user_options_store.DefaultOptions() )
|
||||
# We cache include flags for test.cpp file for unit testing.
|
||||
fnc._flags.flags_for_file[ file_path ] = [
|
||||
"-I", os.path.join( data_dir, "include" ),
|
||||
"-I", os.path.join( data_dir, "include", "Qt" ),
|
||||
"-I", os.path.join( data_dir, "include", "QtGui" ),
|
||||
]
|
||||
|
||||
request_data = {
|
||||
'filepath' : file_path,
|
||||
'file_data' : { file_path : { 'filetypes' : 'cpp' } }
|
||||
}
|
||||
|
||||
def GetCompletionData( request_data ):
|
||||
request_data[ 'start_column' ] = len( request_data[ 'line_value' ] )
|
||||
candidates = fnc.ComputeCandidatesInner( request_data )
|
||||
return [ ( c[ 'insertion_text' ], c[ 'extra_menu_info' ] ) for c in candidates ]
|
||||
|
||||
|
||||
|
||||
def QuotedIncludeCompletion_test():
|
||||
request_data[ 'line_value' ] = '#include "'
|
||||
data = GetCompletionData( request_data )
|
||||
eq_( [
|
||||
( 'include', '[Dir]' ),
|
||||
( 'Qt', '[Dir]' ),
|
||||
( 'QtGui', '[File&Dir]' ),
|
||||
( 'QDialog', '[File]' ),
|
||||
( 'QWidget', '[File]' ),
|
||||
( 'test.cpp', '[File]' ),
|
||||
( 'test.hpp', '[File]' ),
|
||||
], data )
|
||||
|
||||
request_data[ 'line_value' ] = '#include "include/'
|
||||
data = GetCompletionData( request_data )
|
||||
eq_( [
|
||||
( 'Qt', '[Dir]' ),
|
||||
( 'QtGui', '[Dir]' ),
|
||||
], data )
|
||||
|
||||
|
||||
def IncludeCompletion_test():
|
||||
request_data[ 'line_value' ] = '#include <'
|
||||
data = GetCompletionData( request_data )
|
||||
eq_( [
|
||||
( 'Qt', '[Dir]' ),
|
||||
( 'QtGui', '[File&Dir]' ),
|
||||
( 'QDialog', '[File]' ),
|
||||
( 'QWidget', '[File]' ),
|
||||
], data )
|
||||
|
||||
request_data[ 'line_value' ] = '#include <QtGui/'
|
||||
data = GetCompletionData( request_data )
|
||||
eq_( [
|
||||
( 'QDialog', '[File]' ),
|
||||
( 'QWidget', '[File]' ),
|
||||
], data )
|
||||
|
||||
|
||||
def SystemPathCompletion_test():
|
||||
request_data[ 'line_value' ] = 'const char* c = "./'
|
||||
data = GetCompletionData( request_data )
|
||||
eq_( [
|
||||
( 'test.cpp', '[File]' ),
|
||||
( 'test.hpp', '[File]' ),
|
||||
( 'include', '[Dir]' ),
|
||||
], data )
|
||||
|
||||
request_data[ 'line_value' ] = 'const char* c = "./include/'
|
||||
data = GetCompletionData( request_data )
|
||||
eq_( [
|
||||
( 'Qt', '[Dir]' ),
|
||||
( 'QtGui', '[Dir]' ),
|
||||
], data )
|
1
python/ycm/completers/general/tests/testdata/filename_completer/include/Qt/QtGui
vendored
Normal file
1
python/ycm/completers/general/tests/testdata/filename_completer/include/Qt/QtGui
vendored
Normal file
@ -0,0 +1 @@
|
||||
// This file includes all QtGui headers
|
0
python/ycm/completers/general/tests/testdata/filename_completer/include/QtGui/QDialog
vendored
Normal file
0
python/ycm/completers/general/tests/testdata/filename_completer/include/QtGui/QDialog
vendored
Normal file
0
python/ycm/completers/general/tests/testdata/filename_completer/include/QtGui/QWidget
vendored
Normal file
0
python/ycm/completers/general/tests/testdata/filename_completer/include/QtGui/QWidget
vendored
Normal file
4
python/ycm/completers/general/tests/testdata/filename_completer/test.cpp
vendored
Normal file
4
python/ycm/completers/general/tests/testdata/filename_completer/test.cpp
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
#include "test.hpp"
|
||||
#include <QtGui>
|
||||
|
||||
const char* c = "";
|
0
python/ycm/completers/general/tests/testdata/filename_completer/test.hpp
vendored
Normal file
0
python/ycm/completers/general/tests/testdata/filename_completer/test.hpp
vendored
Normal file
Loading…
x
Reference in New Issue
Block a user