Ejemplo n.º 1
0
def FilterToCompletedCompletions_OldVim_NonMatchIsntReturned_test( *args ):
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  completions = [ _BuildCompletion( "A" ) ]

  result = ycm_state._FilterToMatchingCompletions( completions, False )

  assert_that( list( result ), empty() )
def FilterToCompletedCompletions_OldVim_ShortTextDoesntRaise_test():
    ycm_state = YouCompleteMe(MagicMock(spec_set=dict))
    vimsupport.VimVersionAtLeast = MagicMock(return_value=False)
    vimsupport.TextBeforeCursor = MagicMock(return_value="X")
    completions = [_BuildCompletion("AAA")]

    ycm_state._FilterToMatchingCompletions(completions, False)
Ejemplo n.º 3
0
def FilterToCompletedCompletions_OldVim_ShortTextDoesntRaise_test():
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  vimsupport.VimVersionAtLeast = MagicMock( return_value = False )
  vimsupport.TextBeforeCursor = MagicMock( return_value = "X" )
  completions = [ _BuildCompletion( "AAA" ) ]

  ycm_state._FilterToMatchingCompletions( completions, False )
Ejemplo n.º 4
0
def FilterToCompletedCompletions_OldVim_ExactMatchIsReturned_test( *args ):
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  completions = [ _BuildCompletion( "Test" ) ]

  result = ycm_state._FilterToMatchingCompletions( completions, False )

  eq_( list( result ), completions )
Ejemplo n.º 5
0
def YouCompleteMe_NoPythonInterpreterFound_test(post_vim_message, *args):
    with UserOptions({}):
        try:
            with patch('ycmd.utils.ReadFile', side_effect=IOError):
                ycm = YouCompleteMe()

            assert_that(ycm.IsServerAlive(), equal_to(False))
            post_vim_message.assert_called_once_with(
                "Unable to start the ycmd server. Cannot find Python 2.7 or 3.4+. "
                "Set the 'g:ycm_server_python_interpreter' option to a Python "
                "interpreter path. "
                "Correct the error then restart the server with ':YcmRestartServer'."
            )

            post_vim_message.reset_mock()

            SetVariableValue('g:ycm_server_python_interpreter',
                             _PathToPythonUsedDuringBuild())
            ycm.RestartServer()

            assert_that(ycm.IsServerAlive(), equal_to(True))
            post_vim_message.assert_called_once_with(
                'Restarting ycmd server...')
        finally:
            WaitUntilReady()
            StopServer(ycm)
Ejemplo n.º 6
0
def YouCompleteMe_InvalidPythonInterpreterPath_test(post_vim_message):
    with UserOptions(
        {'g:ycm_server_python_interpreter': '/invalid/python/path'}):
        try:
            ycm = YouCompleteMe()

            assert_that(ycm.IsServerAlive(), equal_to(False))
            post_vim_message.assert_called_once_with(
                "Unable to start the ycmd server. "
                "Path in 'g:ycm_server_python_interpreter' option does not point "
                "to a valid Python 2.7 or 3.4+. "
                "Correct the error then restart the server with ':YcmRestartServer'."
            )

            post_vim_message.reset_mock()

            SetVariableValue('g:ycm_server_python_interpreter',
                             _PathToPythonUsedDuringBuild())
            ycm.RestartServer()

            assert_that(ycm.IsServerAlive(), equal_to(True))
            post_vim_message.assert_called_once_with(
                'Restarting ycmd server...')
        finally:
            WaitUntilReady()
            StopServer(ycm)
Ejemplo n.º 7
0
def OnCompleteDone_WithActionCallsIt_test( *args ):
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  action = MagicMock()
  ycm_state._complete_done_hooks[ "txt" ] = action
  ycm_state.OnCompleteDone()

  assert action.called
Ejemplo n.º 8
0
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ShortTextDoesntRaise_test():
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  vimsupport.VimVersionAtLeast = MagicMock( return_value = False )
  vimsupport.TextBeforeCursor = MagicMock( return_value = "X" )
  completions = [ _BuildCompletion( "AAA" ) ]

  ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
Ejemplo n.º 9
0
def GetRequiredNamespaceImport_ReturnNamespaceFromExtraData_test():
  namespace = "A_NAMESPACE"
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )

  eq_( namespace, ycm_state._GetRequiredNamespaceImport(
    _BuildCompletion( namespace )
  ))
Ejemplo n.º 10
0
def FilterToCompletedCompletions_OldVim_NonMatchIsntReturned_test( *args ):
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  completions = [ _BuildCompletion( "A" ) ]

  result = ycm_state._FilterToMatchingCompletions( completions, False )

  assert_that( list( result ), empty() )
Ejemplo n.º 11
0
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_NonMatchIsntReturned_test( *args ):
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  completions = [ _BuildCompletion( "A" ) ]

  result = ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText( completions )

  eq_( result, False )
    def setUp(self):
        options = dict(user_options_store.DefaultOptions())
        options.update(DEFAULT_CLIENT_OPTIONS)
        user_options_store.SetAll(options)

        self.server_state = YouCompleteMe(user_options_store.GetAll())
        pass
Ejemplo n.º 13
0
def FilterToCompletedCompletions_OldVim_ExactMatchIsReturned_test( *args ):
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  completions = [ _BuildCompletion( "Test" ) ]

  result = ycm_state._FilterToMatchingCompletions( completions, False )

  eq_( list( result ), completions )
Ejemplo n.º 14
0
def GetRequiredNamespaceImport_ReturnNamespaceFromExtraData_test():
  namespace = "A_NAMESPACE"
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )

  eq_( namespace, ycm_state._GetRequiredNamespaceImport(
    _BuildCompletion( namespace )
  ))
Ejemplo n.º 15
0
def FilterToCompletedCompletions_NewVim_ShortTextDoesntRaise_test():
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
  vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( "A" )
  completions = [ _BuildCompletion( "AAA" ) ]

  ycm_state._FilterToMatchingCompletions( completions, False )
Ejemplo n.º 16
0
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_NonMatchIsntReturned_test( *args ):
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  completions = [ _BuildCompletion( "A" ) ]

  result = ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText( completions )

  eq_( result, False )
Ejemplo n.º 17
0
def OnCompleteDone_WithActionCallsIt_test( *args ):
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  action = MagicMock()
  ycm_state._complete_done_hooks[ "txt" ] = action
  ycm_state.OnCompleteDone()

  assert action.called
Ejemplo n.º 18
0
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ShortTextDoesntRaise_test():
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
  vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( "X" )
  completions = [ _BuildCompletion( "AAA" ) ]

  ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
def FilterToCompletedCompletions_NewVim_ShortTextDoesntRaise_test():
    ycm_state = YouCompleteMe(MagicMock(spec_set=dict))
    vimsupport.VimVersionAtLeast = MagicMock(return_value=True)
    vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs("A")
    completions = [_BuildCompletion("AAA")]

    ycm_state._FilterToMatchingCompletions(completions, False)
def OnCompleteDone_WithActionCallsIt_test():
    vimsupport.CurrentFiletypes = MagicMock(return_value=["txt"])
    ycm_state = YouCompleteMe(MagicMock(spec_set=dict))
    action = MagicMock()
    ycm_state._complete_done_hooks["txt"] = action
    ycm_state.OnCompleteDone()

    assert action.called
Ejemplo n.º 21
0
def OnCompleteDone_WithActionCallsIt_test():
  vimsupport.CurrentFiletypes = MagicMock( return_value = [ "txt" ] )
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  action = MagicMock()
  ycm_state._complete_done_hooks[ "txt" ] = action
  ycm_state.OnCompleteDone()

  assert action.called
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ShortTextDoesntRaise_test(
):
    ycm_state = YouCompleteMe(MagicMock(spec_set=dict))
    vimsupport.VimVersionAtLeast = MagicMock(return_value=True)
    vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs("X")
    completions = [_BuildCompletion("AAA")]

    ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText(completions)
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ShortTextDoesntRaise_test(
):
    ycm_state = YouCompleteMe(MagicMock(spec_set=dict))
    vimsupport.VimVersionAtLeast = MagicMock(return_value=False)
    vimsupport.TextBeforeCursor = MagicMock(return_value="X")
    completions = [_BuildCompletion("AAA")]

    ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText(completions)
Ejemplo n.º 24
0
 def Wrapper( *args, **kwargs ):
   ycm = YouCompleteMe( MakeUserOptions( custom_options ) )
   WaitUntilReady()
   ycm.CheckIfServerIsReady()
   try:
     test( ycm, *args, **kwargs )
   finally:
     StopServer( ycm )
Ejemplo n.º 25
0
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_MatchIsReturned_test(
    *args ):
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  completions = [ _BuildCompletion( "Test" ) ]

  result = ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText( completions )

  eq_( result, True )
Ejemplo n.º 26
0
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_MatchIsReturned_test(
    *args ):
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  completions = [ _BuildCompletion( "Test" ) ]

  result = ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText( completions )

  eq_( result, True )
Ejemplo n.º 27
0
 def Wrapper(*args, **kwargs):
     ycm = YouCompleteMe(_MakeUserOptions(custom_options))
     _WaitUntilReady()
     try:
         test(ycm, *args, **kwargs)
     finally:
         ycm.OnVimLeave()
         WaitUntilProcessIsTerminated(ycm._server_popen)
def FilterToCompletedCompletions_OldVim_NonMatchIsntReturned_test():
    ycm_state = YouCompleteMe(MagicMock(spec_set=dict))
    vimsupport.VimVersionAtLeast = MagicMock(return_value=False)
    vimsupport.TextBeforeCursor = MagicMock(return_value="   Quote")
    completions = [_BuildCompletion("A")]

    result = ycm_state._FilterToMatchingCompletions(completions, False)

    assert_that(list(result), empty())
Ejemplo n.º 29
0
def _SetupForCsharpCompletionDone( completions ):
  with patch( 'ycm.vimsupport.InsertNamespace' ):
    with patch( 'ycm.vimsupport.TextBeforeCursor', return_value = '   Test' ):
      ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
      request = MagicMock();
      request.Done = MagicMock( return_value = True )
      request.RawResponse = MagicMock( return_value = completions )
      ycm_state._latest_completion_request = request
      yield ycm_state
Ejemplo n.º 30
0
def _SetupForCsharpCompletionDone( completions ):
  with patch( 'ycm.vimsupport.InsertNamespace' ):
    with patch( 'ycm.vimsupport.TextBeforeCursor', return_value = '   Test' ):
      ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
      request = MagicMock();
      request.Done = MagicMock( return_value = True )
      request.RawResponse = MagicMock( return_value = completions )
      ycm_state._latest_completion_request = request
      yield ycm_state
Ejemplo n.º 31
0
def FilterToCompletedCompletions_OldVim_NonMatchIsntReturned_test():
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  vimsupport.VimVersionAtLeast = MagicMock( return_value = False )
  vimsupport.TextBeforeCursor = MagicMock( return_value = "   Quote" )
  completions = [ _BuildCompletion( "A" ) ]

  result = ycm_state._FilterToMatchingCompletions( completions, False )

  assert_that( list( result ), empty() )
def FilterToCompletedCompletions_OldVim_MatchIsReturned_test():
    ycm_state = YouCompleteMe(MagicMock(spec_set=dict))
    vimsupport.VimVersionAtLeast = MagicMock(return_value=False)
    vimsupport.TextBeforeCursor = MagicMock(return_value="   Test")
    completions = [_BuildCompletion("Test")]

    result = ycm_state._FilterToMatchingCompletions(completions, False)

    eq_(list(result), completions)
def _SetupForCsharpCompletionDone(completions):
    ycm_state = YouCompleteMe(MagicMock(spec_set=dict))
    request = MagicMock()
    request.Done = MagicMock(return_value=True)
    request.RawResponse = MagicMock(return_value=completions)
    ycm_state._latest_completion_request = request
    vimsupport.InsertNamespace = MagicMock()
    vimsupport.TextBeforeCursor = MagicMock(return_value="   Test")
    return ycm_state
def FilterToCompletedCompletions_NewVim_ExactMatchIsReturned_test():
    ycm_state = YouCompleteMe(MagicMock(spec_set=dict))
    vimsupport.VimVersionAtLeast = MagicMock(return_value=True)
    vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs("Test")
    completions = [_BuildCompletion("Test")]

    result = ycm_state._FilterToMatchingCompletions(completions, False)

    eq_(list(result), completions)
def FilterToCompletedCompletions_NewVim_NonMatchIsntReturned_test():
    ycm_state = YouCompleteMe(MagicMock(spec_set=dict))
    vimsupport.VimVersionAtLeast = MagicMock(return_value=True)
    vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs("   Quote")
    completions = [_BuildCompletion("A")]

    result = ycm_state._FilterToMatchingCompletions(completions, False)

    assert_that(list(result), empty())
Ejemplo n.º 36
0
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_NonMatchIsntReturned_test():
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  vimsupport.VimVersionAtLeast = MagicMock( return_value = False )
  vimsupport.TextBeforeCursor = MagicMock( return_value = "   Quote" )
  completions = [ _BuildCompletion( "A" ) ]

  result = ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText( completions )

  eq_( result, False )
Ejemplo n.º 37
0
def FilterToCompletedCompletions_OldVim_MatchIsReturned_test():
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  vimsupport.VimVersionAtLeast = MagicMock( return_value = False )
  vimsupport.TextBeforeCursor = MagicMock( return_value = "   Test" )
  completions = [ _BuildCompletion( "Test" ) ]

  result = ycm_state._FilterToMatchingCompletions( completions, False )

  eq_( list( result ), completions )
Ejemplo n.º 38
0
def _SetupForCsharpCompletionDone( completions ):
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  request = MagicMock();
  request.Done = MagicMock( return_value = True )
  request.RawResponse = MagicMock( return_value = completions )
  ycm_state._latest_completion_request = request
  vimsupport.InsertNamespace = MagicMock()
  vimsupport.TextBeforeCursor = MagicMock( return_value = "   Test" )
  return ycm_state
Ejemplo n.º 39
0
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_NonMatchIsntReturned_test():
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
  vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( "   Quote" )
  completions = [ _BuildCompletion( "A" ) ]

  result = ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText( completions )

  eq_( result, False )
Ejemplo n.º 40
0
def FilterToCompletedCompletions_NewVim_NonMatchIsntReturned_test():
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
  vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( "   Quote" )
  completions = [ _BuildCompletion( "A" ) ]

  result = ycm_state._FilterToMatchingCompletions( completions, False )

  assert_that( list( result ), empty() )
Ejemplo n.º 41
0
def FilterToCompletedCompletions_NewVim_ExactMatchIsReturned_test():
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
  vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( "Test" )
  completions = [ _BuildCompletion( "Test" ) ]

  result = ycm_state._FilterToMatchingCompletions( completions, False )

  eq_( list( result ), completions )
Ejemplo n.º 42
0
 def Wrapper(test_case_instance, *args, **kwargs):
     with UserOptions(custom_options):
         ycm = YouCompleteMe()
         WaitUntilReady()
         ycm.CheckIfServerIsReady()
         try:
             test_utils.VIM_PROPS_FOR_BUFFER.clear()
             return test(test_case_instance, ycm, *args, **kwargs)
         finally:
             StopServer(ycm)
Ejemplo n.º 43
0
 def Wrapper( *args, **kwargs ):
   with UserOptions( custom_options ):
     ycm = YouCompleteMe()
     WaitUntilReady()
     ycm.CheckIfServerIsReady()
     try:
       test_utils.VIM_MATCHES_FOR_WINDOW.clear()
       test( ycm, *args, **kwargs )
     finally:
       StopServer( ycm )
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_NonMatchIsntReturned_test(
):
    ycm_state = YouCompleteMe(MagicMock(spec_set=dict))
    vimsupport.VimVersionAtLeast = MagicMock(return_value=False)
    vimsupport.TextBeforeCursor = MagicMock(return_value="   Quote")
    completions = [_BuildCompletion("A")]

    result = ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText(
        completions)

    eq_(result, False)
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_NonMatchIsntReturned_test(
):
    ycm_state = YouCompleteMe(MagicMock(spec_set=dict))
    vimsupport.VimVersionAtLeast = MagicMock(return_value=True)
    vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs("   Quote")
    completions = [_BuildCompletion("A")]

    result = ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText(
        completions)

    eq_(result, False)
Ejemplo n.º 46
0
def ycm(request):
    custom_options = request.param
    with UserOptions(custom_options):
        ycm = YouCompleteMe()
        WaitUntilReady()
        ycm.CheckIfServerIsReady()
        try:
            test_utils.VIM_MATCHES_FOR_WINDOW.clear()
            yield ycm
        finally:
            StopServer(ycm)
Ejemplo n.º 47
0
class YouCompleteMe_test():

    # Minimal options to create the YouCompleteMe object.
    DEFAULT_OPTIONS = {
        'ycm_server_log_level': 'info',
        'ycm_server_keep_logfiles': 0,
        'ycm_min_num_of_chars_for_completion': 2,
        'ycm_auto_trigger': 1,
        'ycm_semantic_triggers': {}
    }

    def setUp(self):
        with patch('vim.eval', side_effect=self.VimEval):
            user_options_store.SetAll(base.BuildServerConf())
            self.ycm = YouCompleteMe(user_options_store.GetAll())

    def tearDown(self):
        self.ycm.OnVimLeave()

    def VimEval(self, value):
        if value == 'g:':
            return self.DEFAULT_OPTIONS

    def YcmCoreNotImported_test(self):
        assert_that('ycm_core', is_not(is_in(sys.modules)))
Ejemplo n.º 48
0
class YouCompleteMe_test():
    def setUp(self):
        self.ycm = YouCompleteMe(MagicMock(spec_set=dict))

    def tearDown(self):
        self.ycm.OnVimLeave()

    def YcmCoreNotImported_test(self):
        assert_that('ycm_core', is_not(is_in(sys.modules)))
Ejemplo n.º 49
0
def SetUpYCM():
    from ycm import base
    from ycmd import user_options_store
    from ycm.youcompleteme import YouCompleteMe

    base.LoadJsonDefaultsIntoVim()

    user_options_store.SetAll(base.BuildServerConf())

    return YouCompleteMe(user_options_store.GetAll())
Ejemplo n.º 50
0
 def setUp( self ):
   self.ycm = YouCompleteMe( MagicMock( spec_set = dict ) )
Ejemplo n.º 51
0
class PostComplete_test():

  def setUp( self ):
    self.ycm = YouCompleteMe( MagicMock( spec_set = dict ) )


  def tearDown( self ):
    self.ycm.OnVimLeave()


  @contextlib.contextmanager
  def _SetupForCsharpCompletionDone( self, completions ):
    with patch( 'ycm.vimsupport.InsertNamespace' ):
      with patch( 'ycm.vimsupport.TextBeforeCursor',
                  return_value = '   Test' ):
        request = MagicMock()
        request.Done = MagicMock( return_value = True )
        request.RawResponse = MagicMock( return_value = completions )
        self.ycm._latest_completion_request = request
        yield


  @patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ "cs" ] )
  def GetCompleteDoneHooks_ResultOnCsharp_test( self, *args ):
    result = self.ycm.GetCompleteDoneHooks()
    eq_( 1, len( list( result ) ) )


  @patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ "txt" ] )
  def GetCompleteDoneHooks_EmptyOnOtherFiletype_test( self, *args ):
    result = self.ycm.GetCompleteDoneHooks()
    eq_( 0, len( list( result ) ) )


  @patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ "txt" ] )
  def OnCompleteDone_WithActionCallsIt_test( self, *args ):
    action = MagicMock()
    self.ycm._complete_done_hooks[ "txt" ] = action
    self.ycm.OnCompleteDone()

    ok_( action.called )


  @patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ "txt" ] )
  def OnCompleteDone_NoActionNoError_test( self, *args ):
    self.ycm.OnCompleteDone()


  @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
  @patch( 'ycm.vimsupport.GetVariableValue',
          GetVariableValue_CompleteItemIs( 'Test' ) )
  def FilterToCompletedCompletions_NewVim_MatchIsReturned_test( self, *args ):
    completions = [ BuildCompletion( "Test" ) ]

    result = self.ycm._FilterToMatchingCompletions( completions, False )

    eq_( list( result ), completions )


  @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
  @patch( 'ycm.vimsupport.GetVariableValue',
          GetVariableValue_CompleteItemIs( 'A' ) )
  def FilterToCompletedCompletions_NewVim_ShortTextDoesntRaise_test( self,
                                                                     *args ):
    completions = [ BuildCompletion( "AAA" ) ]

    self.ycm._FilterToMatchingCompletions( completions, False )


  @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
  @patch( 'ycm.vimsupport.GetVariableValue',
          GetVariableValue_CompleteItemIs( 'Test' ) )
  def FilterToCompletedCompletions_NewVim_ExactMatchIsReturned_test( self,
                                                                     *args ):
    completions = [ BuildCompletion( "Test" ) ]

    result = self.ycm._FilterToMatchingCompletions( completions, False )

    eq_( list( result ), completions )


  @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
  @patch( 'ycm.vimsupport.GetVariableValue',
          GetVariableValue_CompleteItemIs( '   Quote' ) )
  def FilterToCompletedCompletions_NewVim_NonMatchIsntReturned_test( self,
                                                                     *args ):
    completions = [ BuildCompletion( "A" ) ]

    result = self.ycm._FilterToMatchingCompletions( completions, False )

    assert_that( list( result ), empty() )


  @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
  @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "   Test" )
  def FilterToCompletedCompletions_OldVim_MatchIsReturned_test( self, *args ):
    completions = [ BuildCompletion( "Test" ) ]

    result = self.ycm._FilterToMatchingCompletions( completions, False )

    eq_( list( result ), completions )


  @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
  @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "X" )
  def FilterToCompletedCompletions_OldVim_ShortTextDoesntRaise_test( self,
                                                                     *args ):
    completions = [ BuildCompletion( "AAA" ) ]

    self.ycm._FilterToMatchingCompletions( completions, False )


  @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
  @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "Test" )
  def FilterToCompletedCompletions_OldVim_ExactMatchIsReturned_test( self,
                                                                     *args ):
    completions = [ BuildCompletion( "Test" ) ]

    result = self.ycm._FilterToMatchingCompletions( completions, False )

    eq_( list( result ), completions )


  @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
  @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "   Quote" )
  def FilterToCompletedCompletions_OldVim_NonMatchIsntReturned_test( self,
                                                                     *args ):
    completions = [ BuildCompletion( "A" ) ]

    result = self.ycm._FilterToMatchingCompletions( completions, False )

    assert_that( list( result ), empty() )


  @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
  @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "   Te" )
  def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_MatchIsReturned_test( # noqa
    self, *args ):
    completions = [ BuildCompletion( "Test" ) ]

    result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText(
                                                                completions )

    eq_( result, True )


  @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
  @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "X" )
  def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ShortTextDoesntRaise_test( # noqa
    self, *args ):
    completions = [ BuildCompletion( "AAA" ) ]

    self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )


  @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
  @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "Test" )
  def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ExactMatchIsntReturned_test( # noqa
    self, *args ):
    completions = [ BuildCompletion( "Test" ) ]

    result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText(
                                                                completions )

    eq_( result, False )


  @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
  @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "   Quote" )
  def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_NonMatchIsntReturned_test( # noqa
    self, *args ):
    completions = [ BuildCompletion( "A" ) ]

    result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText(
                                                                completions )

    eq_( result, False )


  @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
  @patch( 'ycm.vimsupport.GetVariableValue',
          GetVariableValue_CompleteItemIs( "Te") )
  @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "   Quote" )
  def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_MatchIsReturned_test( # noqa
    self, *args ):
    completions = [ BuildCompletion( "Test" ) ]

    result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText(
                                                                completions )

    eq_( result, True )


  @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
  @patch( 'ycm.vimsupport.GetVariableValue',
          GetVariableValue_CompleteItemIs( "X") )
  @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "   Quote" )
  def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ShortTextDoesntRaise_test( # noqa
    self, *args ):
    completions = [ BuildCompletion( "AAA" ) ]

    self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )


  @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
  @patch( 'ycm.vimsupport.GetVariableValue',
          GetVariableValue_CompleteItemIs( "Test" ) )
  @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = '   Quote' )
  def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ExactMatchIsntReturned_test( # noqa
    self, *args ):
    completions = [ BuildCompletion( "Test" ) ]

    result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText(
                                                                completions )

    eq_( result, False )


  @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
  @patch( 'ycm.vimsupport.GetVariableValue',
          GetVariableValue_CompleteItemIs( "   Quote" ) )
  @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = '   Quote' )
  def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_NonMatchIsntReturned_test( # noqa
    self, *args ):
    completions = [ BuildCompletion( "A" ) ]

    result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText(
                                                                completions )

    eq_( result, False )


  def GetRequiredNamespaceImport_ReturnNoneForNoExtraData_test( self ):
    eq_( None, self.ycm._GetRequiredNamespaceImport( {} ) )


  def GetRequiredNamespaceImport_ReturnNamespaceFromExtraData_test( self ):
    namespace = "A_NAMESPACE"

    eq_( namespace, self.ycm._GetRequiredNamespaceImport(
      BuildCompletion( namespace )
    ) )


  def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfNotDone_test( self ):
    with self._SetupForCsharpCompletionDone( [] ):
      self.ycm._latest_completion_request.Done = MagicMock(
        return_value = False )

      eq_( [], self.ycm.GetCompletionsUserMayHaveCompleted() )


  def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_NewVim_test( # noqa
    self ):
    completions = [ BuildCompletion( None ) ]
    with self._SetupForCsharpCompletionDone( completions ):
      with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
        with patch( 'ycm.vimsupport.GetVariableValue',
                    GetVariableValue_CompleteItemIs( 'Te' ) ):
          eq_( [], self.ycm.GetCompletionsUserMayHaveCompleted() )


  def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_OldVim_test( # noqa
    self, *args ):
    completions = [ BuildCompletion( None ) ]
    with self._SetupForCsharpCompletionDone( completions ):
      with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
        with patch( 'ycm.vimsupport.GetVariableValue',
                    GetVariableValue_CompleteItemIs( 'Te' ) ):
          eq_( [], self.ycm.GetCompletionsUserMayHaveCompleted() )


  def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatches_NewVim_test(
    self, *args ):
    info = [ "NS", "Test", "Abbr", "Menu", "Info", "Kind" ]
    completions = [ BuildCompletion( *info ) ]
    with self._SetupForCsharpCompletionDone( completions ):
      with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
        with patch( 'ycm.vimsupport.GetVariableValue',
                    GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
          eq_( completions, self.ycm.GetCompletionsUserMayHaveCompleted() )


  def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatchesEvenIfPartial_NewVim_test( # noqa
    self, *args ):
    info = [ "NS", "Test", "Abbr", "Menu", "Info", "Kind" ]
    completions = [ BuildCompletion( *info ),
                    BuildCompletion( insertion_text = "TestTest" ) ]
    with self._SetupForCsharpCompletionDone( completions ):
      with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
        with patch( 'ycm.vimsupport.GetVariableValue',
                    GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
          eq_( [ completions[ 0 ] ],
               self.ycm.GetCompletionsUserMayHaveCompleted() )


  def GetCompletionsUserMayHaveCompleted_DontReturnMatchIfNontExactMatchesAndPartial_NewVim_test( # noqa
    self ):
    info = [ "NS", "Test", "Abbr", "Menu", "Info", "Kind" ]
    completions = [ BuildCompletion( insertion_text = info[ 0 ] ),
                    BuildCompletion( insertion_text = "TestTest" ) ]
    with self._SetupForCsharpCompletionDone( completions ):
      with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
        with patch( 'ycm.vimsupport.GetVariableValue',
                    GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
          eq_( [], self.ycm.GetCompletionsUserMayHaveCompleted() )


  def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_NewVim_test(
    self, *args ):
    completions = [ BuildCompletion( None ) ]
    with self._SetupForCsharpCompletionDone( completions ):
      with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
        with patch( 'ycm.vimsupport.GetVariableValue',
                    GetVariableValue_CompleteItemIs( "Test" ) ):
          eq_( completions, self.ycm.GetCompletionsUserMayHaveCompleted() )


  def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_OldVim_test(
    self, *args ):
    completions = [ BuildCompletion( None ) ]
    with self._SetupForCsharpCompletionDone( completions ):
      with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ):
        eq_( completions, self.ycm.GetCompletionsUserMayHaveCompleted() )


  def PostCompleteCsharp_EmptyDoesntInsertNamespace_test( self, *args ):
    with self._SetupForCsharpCompletionDone( [] ):
      with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ):
        self.ycm._OnCompleteDone_Csharp()

      ok_( not vimsupport.InsertNamespace.called )


  def PostCompleteCsharp_ExistingWithoutNamespaceDoesntInsertNamespace_test(
    self, *args ):
    completions = [ BuildCompletion( None ) ]
    with self._SetupForCsharpCompletionDone( completions ):
      with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ):
        self.ycm._OnCompleteDone_Csharp()

      ok_( not vimsupport.InsertNamespace.called )


  def PostCompleteCsharp_ValueDoesInsertNamespace_test( self, *args ):
    namespace = "A_NAMESPACE"
    completions = [ BuildCompletion( namespace ) ]
    with self._SetupForCsharpCompletionDone( completions ):
      with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ):
        self.ycm._OnCompleteDone_Csharp()

        vimsupport.InsertNamespace.assert_called_once_with( namespace )

  def PostCompleteCsharp_InsertSecondNamespaceIfSelected_test( self, *args ):
    namespace = "A_NAMESPACE"
    namespace2 = "ANOTHER_NAMESPACE"
    completions = [
      BuildCompletion( namespace ),
      BuildCompletion( namespace2 ),
    ]
    with self._SetupForCsharpCompletionDone( completions ):
      with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ):
        with patch( 'ycm.vimsupport.PresentDialog', return_value = 1 ):
          self.ycm._OnCompleteDone_Csharp()

          vimsupport.InsertNamespace.assert_called_once_with( namespace2 )
Ejemplo n.º 52
0
def FilterToCompletedCompletions_OldVim_ShortTextDoesntRaise_test( *args ):
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  completions = [ _BuildCompletion( "AAA" ) ]

  ycm_state._FilterToMatchingCompletions( completions, False )
Ejemplo n.º 53
0
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ShortTextDoesntRaise_test( *args ):
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
  completions = [ _BuildCompletion( "AAA" ) ]

  ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
Ejemplo n.º 54
0
def GetRequiredNamespaceImport_ReturnNoneForNoExtraData_test():
  ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )

  eq_( None, ycm_state._GetRequiredNamespaceImport( {} ) )