123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687 |
- # encoding: utf-8
- #
- # Copyright (C) 2016 YouCompleteMe contributors
- #
- # 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 __future__ import unicode_literals
- from __future__ import print_function
- from __future__ import division
- from __future__ import absolute_import
- # Not installing aliases from python-future; it's unreliable and slow.
- from builtins import * # noqa
- from future.utils import PY2
- from mock import patch, call
- from nose.tools import eq_
- from hamcrest import contains_string
- from ycm.tests.test_utils import ExpectedFailure, ExtendedMock, MockVimModule
- MockVimModule()
- from ycm.tests import YouCompleteMeInstance
- from ycmd.utils import ToBytes
- from ycmd.request_wrap import RequestWrap
- def ToBytesOnPY2( data ):
- # To test the omnifunc, etc. returning strings, which can be of different
- # types depending on python version, we use ToBytes on PY2 and just the native
- # str on python3. This roughly matches what happens between py2 and py3
- # versions within Vim
- if PY2:
- return ToBytes( data )
- return data
- def BuildRequest( line_num, column_num, contents ):
- # Note: it would be nice to use ycmd.tests.test_utils.BuildRequest directly
- # here, but we can't import ycmd.tests.test_utils because that in turn imports
- # ycm_core, which would cause our "ycm_core not imported" test to fail.
- return {
- 'line_num': line_num,
- 'column_num': column_num,
- 'filepath': '/test',
- 'file_data': {
- '/test': {
- 'contents': contents,
- 'filetypes': [ 'java' ] # We need a filetype with a trigger, so we just
- # use java
- }
- }
- }
- def BuildRequestWrap( line_num, column_num, contents ):
- return RequestWrap( BuildRequest( line_num, column_num, contents ) )
- @YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
- def OmniCompleter_GetCompletions_Cache_List_test( ycm ):
- contents = 'test.'
- request_data = BuildRequestWrap( line_num = 1,
- column_num = 6,
- contents = contents )
- # Make sure there is an omnifunc set up.
- with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
- ycm._omnicomp.OnFileReadyToParse( request_data )
- omnifunc_result = [ ToBytesOnPY2( 'a' ),
- ToBytesOnPY2( 'b' ),
- ToBytesOnPY2( 'cdef' ) ]
- # And get the completions
- with patch( 'vim.eval',
- new_callable = ExtendedMock,
- side_effect = [ 6, omnifunc_result ] ) as vim_eval:
- results = ycm._omnicomp.ComputeCandidates( request_data )
- vim_eval.assert_has_exact_calls( [
- call( 'test_omnifunc(1,"")' ),
- call( "test_omnifunc(0,'')" ),
- ] )
- eq_( results, omnifunc_result )
- @YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
- def OmniCompleter_GetCompletions_Cache_ListFilter_test( ycm ):
- contents = 'test.t'
- request_data = BuildRequestWrap( line_num = 1,
- column_num = 7,
- contents = contents )
- eq_( request_data[ 'query' ], 't' )
- # Make sure there is an omnifunc set up.
- with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
- ycm._omnicomp.OnFileReadyToParse( request_data )
- omnifunc_result = [ ToBytesOnPY2( 'a' ),
- ToBytesOnPY2( 'b' ),
- ToBytesOnPY2( 'cdef' ) ]
- # And get the completions
- with patch( 'vim.eval',
- new_callable = ExtendedMock,
- side_effect = [ 6, omnifunc_result ] ) as vim_eval:
- results = ycm._omnicomp.ComputeCandidates( request_data )
- vim_eval.assert_has_exact_calls( [
- call( 'test_omnifunc(1,"")' ),
- call( "test_omnifunc(0,'t')" ),
- ] )
- eq_( results, [] )
- @YouCompleteMeInstance( { 'cache_omnifunc': 0 } )
- def OmniCompleter_GetCompletions_NoCache_List_test( ycm ):
- contents = 'test.'
- request_data = BuildRequestWrap( line_num = 1,
- column_num = 6,
- contents = contents )
- # Make sure there is an omnifunc set up.
- with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
- ycm._omnicomp.OnFileReadyToParse( request_data )
- omnifunc_result = [ ToBytesOnPY2( 'a' ),
- ToBytesOnPY2( 'b' ),
- ToBytesOnPY2( 'cdef' ) ]
- # And get the completions
- with patch( 'vim.eval',
- new_callable = ExtendedMock,
- side_effect = [ 6, omnifunc_result ] ) as vim_eval:
- results = ycm._omnicomp.ComputeCandidates( request_data )
- vim_eval.assert_has_exact_calls( [
- call( 'test_omnifunc(1,"")' ),
- call( "test_omnifunc(0,'')" ),
- ] )
- eq_( results, omnifunc_result )
- @YouCompleteMeInstance( { 'cache_omnifunc': 0 } )
- def OmniCompleter_GetCompletions_NoCache_ListFilter_test( ycm ):
- contents = 'test.t'
- request_data = BuildRequestWrap( line_num = 1,
- column_num = 7,
- contents = contents )
- eq_( request_data[ 'query' ], 't' )
- # Make sure there is an omnifunc set up.
- with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
- ycm._omnicomp.OnFileReadyToParse( request_data )
- omnifunc_result = [ ToBytesOnPY2( 'a' ),
- ToBytesOnPY2( 'b' ),
- ToBytesOnPY2( 'cdef' ) ]
- # And get the completions
- with patch( 'vim.eval',
- new_callable = ExtendedMock,
- side_effect = [ 6, omnifunc_result ] ) as vim_eval:
- results = ycm._omnicomp.ComputeCandidates( request_data )
- vim_eval.assert_has_exact_calls( [
- call( 'test_omnifunc(1,"")' ),
- call( "test_omnifunc(0,'t')" ),
- ] )
- # actual result is that the results are not filtered, as we expect the
- # omniufunc or vim itself to do this filtering
- eq_( results, omnifunc_result )
- @ExpectedFailure( 'We ignore the result of the call to findstart and use our '
- 'own interpretation of where the identifier should be',
- contains_string( "test_omnifunc(0,'t')" ) )
- @YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
- def OmniCompleter_GetCompletsions_UseFindStart_test( ycm ):
- contents = 'test.t'
- request_data = BuildRequestWrap( line_num = 1,
- column_num = 7,
- contents = contents )
- eq_( request_data[ 'query' ], 't' )
- # Make sure there is an omnifunc set up.
- with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
- ycm._omnicomp.OnFileReadyToParse( request_data )
- omnifunc_result = [ ToBytesOnPY2( 'a' ),
- ToBytesOnPY2( 'b' ),
- ToBytesOnPY2( 'cdef' ) ]
- # And get the completions
- with patch( 'vim.eval',
- new_callable = ExtendedMock,
- side_effect = [ 1, omnifunc_result ] ) as vim_eval:
- results = ycm._omnicomp.ComputeCandidates( request_data )
- vim_eval.assert_has_exact_calls( [
- call( 'test_omnifunc(1,"")' ),
- # Fails here: actual result is that the findstart result (1) is ignored
- # and we use the 't' query as we normally would on the server side
- call( "test_omnifunc(0,'test.t')" ),
- ] )
- eq_( results, omnifunc_result )
- @YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
- def OmniCompleter_GetCompletions_Cache_Object_test( ycm ):
- contents = 'test.t'
- request_data = BuildRequestWrap( line_num = 1,
- column_num = 7,
- contents = contents )
- eq_( request_data[ 'query' ], 't' )
- # Make sure there is an omnifunc set up.
- with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
- ycm._omnicomp.OnFileReadyToParse( request_data )
- omnifunc_result = {
- 'words': [
- ToBytesOnPY2( 'a' ),
- ToBytesOnPY2( 'b' ),
- ToBytesOnPY2( 'CDtEF' )
- ]
- }
- # And get the completions
- with patch( 'vim.eval',
- new_callable = ExtendedMock,
- side_effect = [ 6, omnifunc_result ] ) as vim_eval:
- results = ycm._omnicomp.ComputeCandidates( request_data )
- vim_eval.assert_has_exact_calls( [
- call( 'test_omnifunc(1,"")' ),
- call( "test_omnifunc(0,'t')" ),
- ] )
- eq_( results, [ ToBytesOnPY2( 'CDtEF' ) ] )
- @YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
- def OmniCompleter_GetCompletions_Cache_ObjectList_test( ycm ):
- contents = 'test.tt'
- request_data = BuildRequestWrap( line_num = 1,
- column_num = 8,
- contents = contents )
- eq_( request_data[ 'query' ], 'tt' )
- # Make sure there is an omnifunc set up.
- with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
- ycm._omnicomp.OnFileReadyToParse( request_data )
- omnifunc_result = [
- {
- 'word': ToBytesOnPY2( 'a' ),
- 'abbr': ToBytesOnPY2( 'ABBR'),
- 'menu': ToBytesOnPY2( 'MENU' ),
- 'info': ToBytesOnPY2( 'INFO' ),
- 'kind': ToBytesOnPY2( 'K' )
- },
- {
- 'word': ToBytesOnPY2( 'test' ),
- 'abbr': ToBytesOnPY2( 'ABBRTEST'),
- 'menu': ToBytesOnPY2( 'MENUTEST' ),
- 'info': ToBytesOnPY2( 'INFOTEST' ),
- 'kind': ToBytesOnPY2( 'T' )
- }
- ]
- # And get the completions
- with patch( 'vim.eval',
- new_callable = ExtendedMock,
- side_effect = [ 6, omnifunc_result ] ) as vim_eval:
- results = ycm._omnicomp.ComputeCandidates( request_data )
- vim_eval.assert_has_exact_calls( [
- call( 'test_omnifunc(1,"")' ),
- call( "test_omnifunc(0,'tt')" ),
- ] )
- eq_( results, [ omnifunc_result[ 1 ] ] )
- @YouCompleteMeInstance( { 'cache_omnifunc': 0 } )
- def OmniCompleter_GetCompletions_NoCache_ObjectList_test( ycm ):
- contents = 'test.tt'
- request_data = BuildRequestWrap( line_num = 1,
- column_num = 8,
- contents = contents )
- eq_( request_data[ 'query' ], 'tt' )
- # Make sure there is an omnifunc set up.
- with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
- ycm._omnicomp.OnFileReadyToParse( request_data )
- omnifunc_result = [
- {
- 'word': ToBytesOnPY2( 'a' ),
- 'abbr': ToBytesOnPY2( 'ABBR'),
- 'menu': ToBytesOnPY2( 'MENU' ),
- 'info': ToBytesOnPY2( 'INFO' ),
- 'kind': ToBytesOnPY2( 'K' )
- },
- {
- 'word': ToBytesOnPY2( 'test' ),
- 'abbr': ToBytesOnPY2( 'ABBRTEST'),
- 'menu': ToBytesOnPY2( 'MENUTEST' ),
- 'info': ToBytesOnPY2( 'INFOTEST' ),
- 'kind': ToBytesOnPY2( 'T' )
- }
- ]
- # And get the completions
- with patch( 'vim.eval',
- new_callable = ExtendedMock,
- side_effect = [ 6, omnifunc_result ] ) as vim_eval:
- results = ycm._omnicomp.ComputeCandidates( request_data )
- vim_eval.assert_has_exact_calls( [
- call( 'test_omnifunc(1,"")' ),
- call( "test_omnifunc(0,'tt')" ),
- ] )
- # We don't filter the result - we expect the omnifunc to do that
- # based on the query we supplied (Note: that means no fuzzy matching!)
- eq_( results, omnifunc_result )
- @YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
- def OmniCompleter_GetCompletions_Cache_ObjectListObject_test( ycm ):
- contents = 'test.tt'
- request_data = BuildRequestWrap( line_num = 1,
- column_num = 8,
- contents = contents )
- eq_( request_data[ 'query' ], 'tt' )
- # Make sure there is an omnifunc set up.
- with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
- ycm._omnicomp.OnFileReadyToParse( request_data )
- omnifunc_result = {
- 'words': [
- {
- 'word': ToBytesOnPY2( 'a' ),
- 'abbr': ToBytesOnPY2( 'ABBR'),
- 'menu': ToBytesOnPY2( 'MENU' ),
- 'info': ToBytesOnPY2( 'INFO' ),
- 'kind': ToBytesOnPY2( 'K' )
- },
- {
- 'word': ToBytesOnPY2( 'test' ),
- 'abbr': ToBytesOnPY2( 'ABBRTEST'),
- 'menu': ToBytesOnPY2( 'MENUTEST' ),
- 'info': ToBytesOnPY2( 'INFOTEST' ),
- 'kind': ToBytesOnPY2( 'T' )
- }
- ]
- }
- # And get the completions
- with patch( 'vim.eval',
- new_callable = ExtendedMock,
- side_effect = [ 6, omnifunc_result ] ) as vim_eval:
- results = ycm._omnicomp.ComputeCandidates( request_data )
- vim_eval.assert_has_exact_calls( [
- call( 'test_omnifunc(1,"")' ),
- call( "test_omnifunc(0,'tt')" ),
- ] )
- eq_( results, [ omnifunc_result[ 'words' ][ 1 ] ] )
- @YouCompleteMeInstance( { 'cache_omnifunc': 0 } )
- def OmniCompleter_GetCompletions_NoCache_ObjectListObject_test( ycm ):
- contents = 'test.tt'
- request_data = BuildRequestWrap( line_num = 1,
- column_num = 8,
- contents = contents )
- eq_( request_data[ 'query' ], 'tt' )
- # Make sure there is an omnifunc set up.
- with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
- ycm._omnicomp.OnFileReadyToParse( request_data )
- omnifunc_result = {
- 'words': [
- {
- 'word': ToBytesOnPY2( 'a' ),
- 'abbr': ToBytesOnPY2( 'ABBR'),
- 'menu': ToBytesOnPY2( 'MENU' ),
- 'info': ToBytesOnPY2( 'INFO' ),
- 'kind': ToBytesOnPY2( 'K' )
- },
- {
- 'word': ToBytesOnPY2( 'test' ),
- 'abbr': ToBytesOnPY2( 'ABBRTEST'),
- 'menu': ToBytesOnPY2( 'MENUTEST' ),
- 'info': ToBytesOnPY2( 'INFOTEST' ),
- 'kind': ToBytesOnPY2( 'T' )
- }
- ]
- }
- # And get the completions
- with patch( 'vim.eval',
- new_callable = ExtendedMock,
- side_effect = [ 6, omnifunc_result ] ) as vim_eval:
- results = ycm._omnicomp.ComputeCandidates( request_data )
- vim_eval.assert_has_exact_calls( [
- call( 'test_omnifunc(1,"")' ),
- call( "test_omnifunc(0,'tt')" ),
- ] )
- # No FilterAndSortCandidates for cache_omnifunc=0 (we expect the omnifunc
- # to do the filtering?)
- eq_( results, omnifunc_result[ 'words' ] )
- @YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
- def OmniCompleter_GetCompletions_Cache_List_Unicode_test( ycm ):
- contents = '†åsty_π.'
- request_data = BuildRequestWrap( line_num = 1,
- column_num = 13,
- contents = contents )
- # Make sure there is an omnifunc set up.
- with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
- ycm._omnicomp.OnFileReadyToParse( request_data )
- omnifunc_result = [ ToBytesOnPY2( '†est' ),
- ToBytesOnPY2( 'å_unicode_identifier' ),
- ToBytesOnPY2( 'πππππππ yummy πie' ) ]
- # And get the completions
- with patch( 'vim.eval',
- new_callable = ExtendedMock,
- side_effect = [ 6, omnifunc_result ] ) as vim_eval:
- results = ycm._omnicomp.ComputeCandidates( request_data )
- vim_eval.assert_has_exact_calls( [
- call( 'test_omnifunc(1,"")' ),
- call( "test_omnifunc(0,'')" ),
- ] )
- eq_( results, omnifunc_result )
- @YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
- def OmniCompleter_GetCompletions_NoCache_List_Unicode_test( ycm ):
- contents = '†åsty_π.'
- request_data = BuildRequestWrap( line_num = 1,
- column_num = 13,
- contents = contents )
- # Make sure there is an omnifunc set up.
- with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
- ycm._omnicomp.OnFileReadyToParse( request_data )
- omnifunc_result = [ ToBytesOnPY2( '†est' ),
- ToBytesOnPY2( 'å_unicode_identifier' ),
- ToBytesOnPY2( 'πππππππ yummy πie' ) ]
- # And get the completions
- with patch( 'vim.eval',
- new_callable = ExtendedMock,
- side_effect = [ 6, omnifunc_result ] ) as vim_eval:
- results = ycm._omnicomp.ComputeCandidates( request_data )
- vim_eval.assert_has_exact_calls( [
- call( 'test_omnifunc(1,"")' ),
- call( "test_omnifunc(0,'')" ),
- ] )
- eq_( results, omnifunc_result )
- @ExpectedFailure( 'Filtering on unicode is not supported by the server' )
- @YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
- def OmniCompleter_GetCompletions_Cache_List_Filter_Unicode_test( ycm ):
- contents = '†åsty_π.ππ'
- request_data = BuildRequestWrap( line_num = 1,
- column_num = 17,
- contents = contents )
- # Make sure there is an omnifunc set up.
- with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
- ycm._omnicomp.OnFileReadyToParse( request_data )
- omnifunc_result = [ ToBytesOnPY2( '†est' ),
- ToBytesOnPY2( 'å_unicode_identifier' ),
- ToBytesOnPY2( 'πππππππ yummy πie' ) ]
- # And get the completions
- with patch( 'vim.eval',
- new_callable = ExtendedMock,
- side_effect = [ 6, omnifunc_result ] ) as vim_eval:
- results = ycm._omnicomp.ComputeCandidates( request_data )
- vim_eval.assert_has_exact_calls( [
- call( 'test_omnifunc(1,"")' ),
- call( "test_omnifunc(0,'ππ')" ),
- ] )
- # Fails here: Filtering on unicode is not supported
- eq_( results, [ omnifunc_result[ 2 ] ] )
- @YouCompleteMeInstance( { 'cache_omnifunc': 0 } )
- def OmniCompleter_GetCompletions_NoCache_List_Filter_Unicode_test( ycm ):
- contents = '†åsty_π.ππ'
- request_data = BuildRequestWrap( line_num = 1,
- column_num = 17,
- contents = contents )
- # Make sure there is an omnifunc set up.
- with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
- ycm._omnicomp.OnFileReadyToParse( request_data )
- omnifunc_result = [ ToBytesOnPY2( 'πππππππ yummy πie' ) ]
- # And get the completions
- with patch( 'vim.eval',
- new_callable = ExtendedMock,
- side_effect = [ 6, omnifunc_result ] ) as vim_eval:
- results = ycm._omnicomp.ComputeCandidates( request_data )
- vim_eval.assert_has_exact_calls( [
- call( 'test_omnifunc(1,"")' ),
- call( "test_omnifunc(0,'ππ')" ),
- ] )
- eq_( results, omnifunc_result )
- @ExpectedFailure( 'Filtering on unicode is not supported by the server' )
- @YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
- def OmniCompleter_GetCompletions_Cache_ObjectList_Unicode_test( ycm ):
- contents = '†åsty_π.ππ'
- request_data = BuildRequestWrap( line_num = 1,
- column_num = 17,
- contents = contents )
- eq_( request_data[ 'query' ], 'ππ' )
- # Make sure there is an omnifunc set up.
- with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
- ycm._omnicomp.OnFileReadyToParse( request_data )
- omnifunc_result = [
- {
- 'word': ToBytesOnPY2( 'ålpha∫et' ),
- 'abbr': ToBytesOnPY2( 'å∫∫®'),
- 'menu': ToBytesOnPY2( 'µ´~¨á' ),
- 'info': ToBytesOnPY2( '^~fo' ),
- 'kind': ToBytesOnPY2( '˚' )
- },
- {
- 'word': ToBytesOnPY2( 'π†´ß†π' ),
- 'abbr': ToBytesOnPY2( 'ÅııÂʉÍÊ'),
- 'menu': ToBytesOnPY2( '˜‰ˆËʉÍÊ' ),
- 'info': ToBytesOnPY2( 'ȈÏØʉÍÊ' ),
- 'kind': ToBytesOnPY2( 'Ê' )
- }
- ]
- # And get the completions
- with patch( 'vim.eval',
- new_callable = ExtendedMock,
- side_effect = [ 6, omnifunc_result ] ) as vim_eval:
- results = ycm._omnicomp.ComputeCandidates( request_data )
- vim_eval.assert_has_exact_calls( [
- call( 'test_omnifunc(1,"")' ),
- call( "test_omnifunc(0,'ππ')" ),
- ] )
- # Fails here: Filtering on unicode is not supported
- eq_( results, [ omnifunc_result[ 1 ] ] )
- @YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
- def OmniCompleter_GetCompletions_Cache_ObjectListObject_Unicode_test( ycm ):
- contents = '†åsty_π.t'
- request_data = BuildRequestWrap( line_num = 1,
- column_num = 14,
- contents = contents )
- eq_( request_data[ 'query' ], 't' )
- # Make sure there is an omnifunc set up.
- with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
- ycm._omnicomp.OnFileReadyToParse( request_data )
- omnifunc_result = {
- 'words': [
- {
- 'word': ToBytesOnPY2( 'ålpha∫et' ),
- 'abbr': ToBytesOnPY2( 'å∫∫®'),
- 'menu': ToBytesOnPY2( 'µ´~¨á' ),
- 'info': ToBytesOnPY2( '^~fo' ),
- 'kind': ToBytesOnPY2( '˚' )
- },
- {
- 'word': ToBytesOnPY2( 'π†´ß†π' ),
- 'abbr': ToBytesOnPY2( 'ÅııÂʉÍÊ'),
- 'menu': ToBytesOnPY2( '˜‰ˆËʉÍÊ' ),
- 'info': ToBytesOnPY2( 'ȈÏØʉÍÊ' ),
- 'kind': ToBytesOnPY2( 'Ê' )
- },
- {
- 'word': ToBytesOnPY2( 'test' ),
- 'abbr': ToBytesOnPY2( 'ÅııÂʉÍÊ'),
- 'menu': ToBytesOnPY2( '˜‰ˆËʉÍÊ' ),
- 'info': ToBytesOnPY2( 'ȈÏØʉÍÊ' ),
- 'kind': ToBytesOnPY2( 'Ê' )
- }
- ]
- }
- # And get the completions
- with patch( 'vim.eval',
- new_callable = ExtendedMock,
- side_effect = [ 6, omnifunc_result ] ) as vim_eval:
- results = ycm._omnicomp.ComputeCandidates( request_data )
- vim_eval.assert_has_exact_calls( [
- call( 'test_omnifunc(1,"")' ),
- call( "test_omnifunc(0,'t')" ),
- ] )
- # Note: the filtered results are all unicode objects (not bytes) because
- # they are passed through the FilterAndSortCandidates machinery
- # (via the server)
- eq_( results, [ {
- 'word': 'test',
- 'abbr': 'ÅııÂʉÍÊ',
- 'menu': '˜‰ˆËʉÍÊ',
- 'info': 'ȈÏØʉÍÊ',
- 'kind': 'Ê'
- } ] )
|