Esempio n. 1
0
def OmniCompleter_GetCompletions_ConvertStringsToDictionaries_test(ycm):
    def Omnifunc(findstart, base):
        if findstart:
            return 5
        return [{'word': 'a'}, 'b']

    current_buffer = VimBuffer('buffer',
                               contents=['test.'],
                               filetype=FILETYPE,
                               omnifunc=Omnifunc)

    with MockVimBuffers([current_buffer], [current_buffer], (1, 7)):
        ycm.SendCompletionRequest()
        assert_that(
            ycm.GetCompletionResponse(),
            has_entries({
                'completions':
                ToBytesOnPY2([{
                    'word': 'a'
                }, {
                    'word': 'b'
                }]),
                'completion_start_column':
                6
            }))
Esempio n. 2
0
def OmniCompleter_GetCompletions_AllFiletypesDisabled_ForceSemantic_test(ycm):
    def Omnifunc(findstart, base):
        if findstart:
            return 5
        return ['a', 'b', 'cdef']

    current_buffer = VimBuffer('buffer',
                               contents=['test.'],
                               filetype=FILETYPE,
                               omnifunc=Omnifunc)

    with MockVimBuffers([current_buffer], [current_buffer], (1, 6)):
        ycm.SendCompletionRequest(force_semantic=True)
        assert_that(
            ycm.GetCompletionResponse(),
            has_entries({
                'completions':
                ToBytesOnPY2([{
                    'word': 'a'
                }, {
                    'word': 'b'
                }, {
                    'word': 'cdef'
                }]),
                'completion_start_column':
                6
            }))
Esempio n. 3
0
def OmniCompleter_GetCompletions_MoveCursorPositionAtStartColumn_test(ycm):
    # This omnifunc relies on the cursor being moved at the start column when
    # called the second time like LanguageClient#complete from the
    # LanguageClient-neovim plugin.
    def Omnifunc(findstart, base):
        if findstart:
            return 5
        if vimsupport.CurrentColumn() == 5:
            return ['length']
        return []

    current_buffer = VimBuffer('buffer',
                               contents=['String test', '', 'test.le'],
                               filetype=FILETYPE,
                               omnifunc=Omnifunc)

    with MockVimBuffers([current_buffer], [current_buffer], (3, 7)):
        ycm.SendCompletionRequest()
        assert_that(vimsupport.CurrentLineAndColumn(), contains(2, 7))
        assert_that(
            ycm.GetCompletionResponse(),
            has_entries({
                'completions': ToBytesOnPY2([{
                    'word': 'length'
                }]),
                'completion_start_column': 6
            }))
Esempio n. 4
0
def OmniCompleter_GetCompletions_NoCache_List_Unicode_test(ycm):
    def Omnifunc(findstart, base):
        if findstart:
            return 12
        return ['†est', 'å_unicode_identifier', 'πππππππ yummy πie']

    current_buffer = VimBuffer('buffer',
                               contents=['†åsty_π.'],
                               filetype=FILETYPE,
                               omnifunc=Omnifunc)

    with MockVimBuffers([current_buffer], [current_buffer], (1, 12)):
        ycm.SendCompletionRequest()
        assert_that(
            ycm.GetCompletionResponse(),
            has_entries({
                'completions':
                ToBytesOnPY2([{
                    'word': '†est'
                }, {
                    'word': 'å_unicode_identifier'
                }, {
                    'word': 'πππππππ yummy πie'
                }]),
                'completion_start_column':
                13
            }))
Esempio n. 5
0
def OmniCompleter_GetCompletions_RestoreCursorPositionAfterOmnifuncCall_test(
        ycm):

    # This omnifunc moves the cursor to the test definition like
    # ccomplete#Complete would.
    def Omnifunc(findstart, base):
        vimsupport.SetCurrentLineAndColumn(0, 0)
        if findstart:
            return 5
        return ['length']

    current_buffer = VimBuffer('buffer',
                               contents=['String test', '', 'test.'],
                               filetype=FILETYPE,
                               omnifunc=Omnifunc)

    with MockVimBuffers([current_buffer], [current_buffer], (3, 5)):
        ycm.SendCompletionRequest()
        assert_that(vimsupport.CurrentLineAndColumn(), contains(2, 5))
        assert_that(
            ycm.GetCompletionResponse(),
            has_entries({
                'completions': ToBytesOnPY2([{
                    'word': 'length'
                }]),
                'completion_start_column': 6
            }))
Esempio n. 6
0
def OmniCompleter_GetCompletions_Cache_List_test(ycm):
    def Omnifunc(findstart, base):
        if findstart:
            return 5
        return ['a', 'b', 'cdef']

    current_buffer = VimBuffer('buffer',
                               contents=['test.'],
                               filetype=FILETYPE,
                               omnifunc=Omnifunc)

    with MockVimBuffers([current_buffer], [current_buffer], (1, 5)):
        ycm.SendCompletionRequest()
        assert_that(
            ycm.GetCompletionResponse(),
            has_entries({
                'completions':
                ToBytesOnPY2([{
                    'word': 'a',
                    'equal': 1
                }, {
                    'word': 'b',
                    'equal': 1
                }, {
                    'word': 'cdef',
                    'equal': 1
                }]),
                'completion_start_column':
                6
            }))
Esempio n. 7
0
def OmniCompleter_GetCompletions_NoCache_UseFindStart_test(ycm):
    def Omnifunc(findstart, base):
        if findstart:
            return 0
        return ['a', 'b', 'cdef']

    current_buffer = VimBuffer('buffer',
                               contents=['test.t'],
                               filetype=FILETYPE,
                               omnifunc=Omnifunc)

    with MockVimBuffers([current_buffer], [current_buffer], (1, 6)):
        ycm.SendCompletionRequest()
        # Actual result is that the results are not filtered, as we expect the
        # omnifunc or vim itself to do this filtering.
        assert_that(
            ycm.GetCompletionResponse(),
            has_entries({
                'completions':
                ToBytesOnPY2([{
                    'word': 'a'
                }, {
                    'word': 'b'
                }, {
                    'word': 'cdef'
                }]),
                'completion_start_column':
                1
            }))
Esempio n. 8
0
def OmniCompleter_GetCompletions_NoCache_ObjectListObject_test(ycm):
    def Omnifunc(findstart, base):
        if findstart:
            return 5
        return {
            'words': [{
                'word': 'a',
                'abbr': 'ABBR',
                'menu': 'MENU',
                'info': 'INFO',
                'kind': 'K'
            }, {
                'word': 'test',
                'abbr': 'ABBRTEST',
                'menu': 'MENUTEST',
                'info': 'INFOTEST',
                'kind': 'T'
            }]
        }

    current_buffer = VimBuffer('buffer',
                               contents=['test.tt'],
                               filetype=FILETYPE,
                               omnifunc=Omnifunc)

    with MockVimBuffers([current_buffer], [current_buffer], (1, 7)):
        ycm.SendCompletionRequest()
        # No FilterAndSortCandidates for cache_omnifunc=0 (we expect the omnifunc
        # to do the filtering?)
        assert_that(
            ycm.GetCompletionResponse(),
            has_entries({
                'completions':
                ToBytesOnPY2([{
                    'word': 'a',
                    'abbr': 'ABBR',
                    'menu': 'MENU',
                    'info': 'INFO',
                    'kind': 'K',
                    'equal': 1
                }, {
                    'word': 'test',
                    'abbr': 'ABBRTEST',
                    'menu': 'MENUTEST',
                    'info': 'INFOTEST',
                    'kind': 'T',
                    'equal': 1
                }]),
                'completion_start_column':
                6
            }))
def OmniCompleter_GetCompletions_NoCache_ObjectList_test( ycm ):
  def Omnifunc( findstart, base ):
    if findstart:
      return 5
    return [
      {
        'word': 'a',
        'abbr': 'ABBR',
        'menu': 'MENU',
        'info': 'INFO',
        'kind': 'K'
      },
      {
        'word': 'test',
        'abbr': 'ABBRTEST',
        'menu': 'MENUTEST',
        'info': 'INFOTEST',
        'kind': 'T'
      }
    ]

  current_buffer = VimBuffer( 'buffer',
                              contents = [ 'test.tt' ],
                              filetype = FILETYPE,
                              omnifunc = Omnifunc )

  with MockVimBuffers( [ current_buffer ], [ current_buffer ], ( 1, 7 ) ):
    ycm.SendCompletionRequest()
    # 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!).
    assert_that(
      ycm.GetCompletionResponse(),
      has_entries( {
        'completions': ToBytesOnPY2( [ {
          'word': 'a',
          'abbr': 'ABBR',
          'menu': 'MENU',
          'info': 'INFO',
          'kind': 'K'
        }, {
          'word': 'test',
          'abbr': 'ABBRTEST',
          'menu': 'MENUTEST',
          'info': 'INFOTEST',
          'kind': 'T'
        } ] ),
        'completion_start_column': 6
      } )
    )
Esempio n. 10
0
def EventNotification_BufferUnload_BuildRequestForDeletedAndUnsavedBuffers_test(
        ycm):
    current_buffer_file = os.path.realpath('current_βuffer')
    current_buffer = VimBuffer(name=current_buffer_file,
                               number=1,
                               contents=['current_buffer_contents'],
                               filetype='some_filetype',
                               modified=True)

    deleted_buffer_file = os.path.realpath('deleted_βuffer')
    deleted_buffer = VimBuffer(name=deleted_buffer_file,
                               number=2,
                               contents=['deleted_buffer_contents'],
                               filetype='some_filetype',
                               modified=False)

    with patch('ycm.client.event_notification.EventNotification.'
               'PostDataToHandlerAsync') as post_data_to_handler_async:
        with MockVimBuffers([current_buffer, deleted_buffer], current_buffer):
            ycm.OnBufferUnload(ToBytesOnPY2(deleted_buffer_file))

    assert_that(
        # Positional arguments passed to PostDataToHandlerAsync.
        post_data_to_handler_async.call_args[0],
        contains(
            has_entries({
                'filepath':
                deleted_buffer_file,
                'line_num':
                1,
                'column_num':
                1,
                'file_data':
                has_entries({
                    current_buffer_file:
                    has_entries({
                        'contents': 'current_buffer_contents\n',
                        'filetypes': ['some_filetype']
                    }),
                    deleted_buffer_file:
                    has_entries({
                        'contents': 'deleted_buffer_contents\n',
                        'filetypes': ['some_filetype']
                    })
                }),
                'event_name':
                'BufferUnload'
            }), 'event_notification'))
Esempio n. 11
0
def OmniCompleter_GetCompletions_NoCache_ForceSemantic_test(ycm):
    def Omnifunc(findstart, base):
        if findstart:
            return 0
        return ['test']

    current_buffer = VimBuffer('buffer',
                               contents=['te'],
                               filetype=FILETYPE,
                               omnifunc=Omnifunc)

    with MockVimBuffers([current_buffer], [current_buffer], (1, 3)):
        ycm.SendCompletionRequest(force_semantic=True)
        assert_that(
            ycm.GetCompletionResponse(),
            has_entries({
                'completions': ToBytesOnPY2(['test']),
                'completion_start_column': 1
            }))
Esempio n. 12
0
def OmniCompleter_GetCompletions_NoCache_List_Filter_Unicode_test(ycm):
    def Omnifunc(findstart, base):
        if findstart:
            return 12
        return ['πππππππ yummy πie']

    current_buffer = VimBuffer('buffer',
                               contents=['†åsty_π.ππ'],
                               filetype='java',
                               omnifunc=Omnifunc)

    with MockVimBuffers([current_buffer], current_buffer, (1, 17)):
        ycm.SendCompletionRequest()
        assert_that(
            ycm.GetCompletionResponse(),
            has_entries({
                'completions': ToBytesOnPY2(['πππππππ yummy πie']),
                'completion_start_column': 13
            }))
Esempio n. 13
0
def StartColumnCompliance(ycm, omnifunc_start_column, ycm_completions,
                          ycm_start_column):
    def Omnifunc(findstart, base):
        if findstart:
            return omnifunc_start_column
        return ['foo']

    current_buffer = VimBuffer('buffer',
                               contents=['fo'],
                               filetype=FILETYPE,
                               omnifunc=Omnifunc)

    with MockVimBuffers([current_buffer], [current_buffer], (1, 2)):
        ycm.SendCompletionRequest(force_semantic=True)
        assert_that(
            ycm.GetCompletionResponse(),
            has_entries({
                'completions': ToBytesOnPY2(ycm_completions),
                'completion_start_column': ycm_start_column
            }))
Esempio n. 14
0
def OmniCompleter_GetCompletions_Cache_ObjectList_Unicode_test( ycm ):
  def Omnifunc( findstart, base ):
    if findstart:
      return 12
    return [
      {
        'word': 'ålpha∫et',
        'abbr': 'å∫∫®',
        'menu': 'µ´~¨á',
        'info': '^~fo',
        'kind': '˚'
      },
      {
        'word': 'π†´ß†π',
        'abbr': 'ÅııÂʉÍÊ',
        'menu': '˜‰ˆËʉÍÊ',
        'info': 'ȈÏØʉÍÊ',
        'kind': 'Ê'
      }
    ]

  current_buffer = VimBuffer( 'buffer',
                              contents = [ '†åsty_π.ππ' ],
                              filetype = FILETYPE,
                              omnifunc = Omnifunc )

  with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 17 ) ):
    ycm.SendCompletionRequest()
    assert_that(
      ycm.GetCompletionResponse(),
      has_entries( {
        'completions': ToBytesOnPY2( [ {
          'word': 'π†´ß†π',
          'abbr': 'ÅııÂʉÍÊ',
          'menu': '˜‰ˆËʉÍÊ',
          'info': 'ȈÏØʉÍÊ',
          'kind': 'Ê'
        } ] ),
        'completion_start_column': 13
      } )
    )
def OmniCompleter_GetCompletions_Cache_ObjectListObject_test( ycm ):
  def Omnifunc( findstart, base ):
    if findstart:
      return 5
    return { 'words': [
      {
        'word': 'a',
        'abbr': 'ABBR',
        'menu': 'MENU',
        'info': 'INFO',
        'kind': 'K'
      },
      {
        'word': 'test',
        'abbr': 'ABBRTEST',
        'menu': 'MENUTEST',
        'info': 'INFOTEST',
        'kind': 'T'
      }
    ] }

  current_buffer = VimBuffer( 'buffer',
                              contents = [ 'test.tt' ],
                              filetype = 'java',
                              omnifunc = Omnifunc )

  with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 7 ) ):
    ycm.SendCompletionRequest()
    assert_that(
      ycm.GetCompletionResponse(),
      has_entries( {
        'completions': ToBytesOnPY2( [ {
          'word': 'test',
          'abbr': 'ABBRTEST',
          'menu': 'MENUTEST',
          'info': 'INFOTEST',
          'kind': 'T'
        } ] ),
        'completion_start_column': 6
      } )
    )