|
@@ -1,6 +1,6 @@
|
|
|
#!/usr/bin/env python
|
|
|
#
|
|
|
-# Copyright (C) 2013 Google Inc.
|
|
|
+# Copyright (C) 2015 YouCompleteMe contributors
|
|
|
#
|
|
|
# This file is part of YouCompleteMe.
|
|
|
#
|
|
@@ -23,113 +23,193 @@ from hamcrest import assert_that, empty
|
|
|
from ycm import vimsupport
|
|
|
from ycm.youcompleteme import YouCompleteMe
|
|
|
|
|
|
-def HasPostCompletionAction_TrueOnCsharp_test():
|
|
|
+def GetCompleteDoneHooks_ResultOnCsharp_test():
|
|
|
vimsupport.CurrentFiletypes = MagicMock( return_value = [ "cs" ] )
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
- eq_( True, ycm_state.HasPostCompletionAction() )
|
|
|
+ result = ycm_state.GetCompleteDoneHooks()
|
|
|
+ eq_( 1, len( list( result ) ) )
|
|
|
|
|
|
|
|
|
-def HasPostCompletionAction_FalseOnOtherFiletype_test():
|
|
|
+def GetCompleteDoneHooks_EmptyOnOtherFiletype_test():
|
|
|
vimsupport.CurrentFiletypes = MagicMock( return_value = [ "txt" ] )
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
- eq_( False, ycm_state.HasPostCompletionAction() )
|
|
|
+ result = ycm_state.GetCompleteDoneHooks()
|
|
|
+ eq_( 0, len( list( result ) ) )
|
|
|
|
|
|
|
|
|
-def GetRequiredNamespaceImport_ReturnEmptyForNoExtraData_test():
|
|
|
+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()
|
|
|
|
|
|
- eq_( "", ycm_state.GetRequiredNamespaceImport( {} ) )
|
|
|
+ assert action.called
|
|
|
|
|
|
|
|
|
-def GetRequiredNamespaceImport_ReturnNamespaceFromExtraData_test():
|
|
|
- namespace = "A_NAMESPACE"
|
|
|
+def OnCompleteDone_NoActionNoError_test():
|
|
|
+ vimsupport.CurrentFiletypes = MagicMock( return_value = [ "txt" ] )
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
|
|
|
- eq_( namespace, ycm_state.GetRequiredNamespaceImport(
|
|
|
- _BuildCompletion( namespace )
|
|
|
- ))
|
|
|
+ ycm_state.OnCompleteDone()
|
|
|
|
|
|
|
|
|
-def FilterMatchingCompletions_MatchIsReturned_test():
|
|
|
+def FilterToCompletionsMatchingOnCursor_MatchIsReturned_test():
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
vimsupport.TextBeforeCursor = MagicMock( return_value = " Test" )
|
|
|
- completions = [ _BuildCompletion( "A" ) ]
|
|
|
+ completions = [ _BuildCompletion( "Test" ) ]
|
|
|
|
|
|
- result = ycm_state.FilterMatchingCompletions( completions )
|
|
|
+ result = ycm_state.FilterToCompletionsMatchingOnCursor( completions )
|
|
|
|
|
|
eq_( list( result ), completions )
|
|
|
|
|
|
|
|
|
-def FilterMatchingCompletions_ShortTextDoesntRaise_test():
|
|
|
+def FilterToCompletionsMatchingOnCursor_ShortTextDoesntRaise_test():
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
vimsupport.TextBeforeCursor = MagicMock( return_value = "X" )
|
|
|
- completions = [ _BuildCompletion( "A" ) ]
|
|
|
+ completions = [ _BuildCompletion( "AAA" ) ]
|
|
|
|
|
|
- ycm_state.FilterMatchingCompletions( completions )
|
|
|
+ ycm_state.FilterToCompletionsMatchingOnCursor( completions )
|
|
|
|
|
|
|
|
|
-def FilterMatchingCompletions_ExactMatchIsReturned_test():
|
|
|
+def FilterToCompletionsMatchingOnCursor_ExactMatchIsReturned_test():
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
vimsupport.TextBeforeCursor = MagicMock( return_value = "Test" )
|
|
|
- completions = [ _BuildCompletion( "A" ) ]
|
|
|
+ completions = [ _BuildCompletion( "Test" ) ]
|
|
|
|
|
|
- result = ycm_state.FilterMatchingCompletions( completions )
|
|
|
+ result = ycm_state.FilterToCompletionsMatchingOnCursor( completions )
|
|
|
|
|
|
eq_( list( result ), completions )
|
|
|
|
|
|
|
|
|
-def FilterMatchingCompletions_NonMatchIsntReturned_test():
|
|
|
+def FilterToCompletionsMatchingOnCursor_NonMatchIsntReturned_test():
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
vimsupport.TextBeforeCursor = MagicMock( return_value = " Quote" )
|
|
|
completions = [ _BuildCompletion( "A" ) ]
|
|
|
|
|
|
- result = ycm_state.FilterMatchingCompletions( completions )
|
|
|
+ result = ycm_state.FilterToCompletionsMatchingOnCursor( completions )
|
|
|
|
|
|
assert_that( list( result ), empty() )
|
|
|
|
|
|
|
|
|
-def PostComplete_EmptyDoesntInsertNamespace_test():
|
|
|
- ycm_state = _SetupForCompletionDone( [] )
|
|
|
+def HasCompletionsThatCouldMatchOnCursorWithMoreText_MatchIsReturned_test():
|
|
|
+ ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
+ vimsupport.TextBeforeCursor = MagicMock( return_value = " Te" )
|
|
|
+ completions = [ _BuildCompletion( "Test" ) ]
|
|
|
+
|
|
|
+ result = ycm_state.HasCompletionsThatCouldMatchOnCursorWithMoreText( completions )
|
|
|
|
|
|
- ycm_state.OnCompleteDone()
|
|
|
+ eq_( result, True )
|
|
|
+
|
|
|
+
|
|
|
+def HasCompletionsThatCouldMatchOnCursorWithMoreText_ShortTextDoesntRaise_test():
|
|
|
+ ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
+ vimsupport.TextBeforeCursor = MagicMock( return_value = "X" )
|
|
|
+ completions = [ _BuildCompletion( "AAA" ) ]
|
|
|
+
|
|
|
+ ycm_state.HasCompletionsThatCouldMatchOnCursorWithMoreText( completions )
|
|
|
+
|
|
|
+
|
|
|
+def HasCompletionsThatCouldMatchOnCursorWithMoreText_ExactMatchIsntReturned_test():
|
|
|
+ ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
+ vimsupport.TextBeforeCursor = MagicMock( return_value = "Test" )
|
|
|
+ completions = [ _BuildCompletion( "Test" ) ]
|
|
|
+
|
|
|
+ result = ycm_state.HasCompletionsThatCouldMatchOnCursorWithMoreText( completions )
|
|
|
+
|
|
|
+ eq_( result, False )
|
|
|
+
|
|
|
+
|
|
|
+def HasCompletionsThatCouldMatchOnCursorWithMoreText_NonMatchIsntReturned_test():
|
|
|
+ ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
+ vimsupport.TextBeforeCursor = MagicMock( return_value = " Quote" )
|
|
|
+ completions = [ _BuildCompletion( "A" ) ]
|
|
|
+
|
|
|
+ result = ycm_state.HasCompletionsThatCouldMatchOnCursorWithMoreText( completions )
|
|
|
+
|
|
|
+ eq_( result, False )
|
|
|
+
|
|
|
+
|
|
|
+def GetRequiredNamespaceImport_ReturnNoneForNoExtraData_test():
|
|
|
+ ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
+
|
|
|
+ eq_( None, ycm_state.GetRequiredNamespaceImport( {} ) )
|
|
|
+
|
|
|
+
|
|
|
+def GetRequiredNamespaceImport_ReturnNamespaceFromExtraData_test():
|
|
|
+ namespace = "A_NAMESPACE"
|
|
|
+ ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
+
|
|
|
+ eq_( namespace, ycm_state.GetRequiredNamespaceImport(
|
|
|
+ _BuildCompletion( namespace )
|
|
|
+ ))
|
|
|
+
|
|
|
+
|
|
|
+def GetMatchingCompletionsOnCursor_ReturnEmptyIfNotDone_test():
|
|
|
+ ycm_state = _SetupForCsharpCompletionDone( [] )
|
|
|
+ ycm_state._latest_completion_request.Done = MagicMock( return_value = False )
|
|
|
+
|
|
|
+ eq_( [], ycm_state.GetMatchingCompletionsOnCursor() )
|
|
|
+
|
|
|
+
|
|
|
+def GetMatchingCompletionsOnCursor_ReturnEmptyIfPendingMatches_test():
|
|
|
+ completions = [ _BuildCompletion( None ) ]
|
|
|
+ ycm_state = _SetupForCsharpCompletionDone( completions )
|
|
|
+ vimsupport.TextBeforeCursor = MagicMock( return_value = " Te" )
|
|
|
+
|
|
|
+ eq_( [], ycm_state.GetMatchingCompletionsOnCursor() )
|
|
|
+
|
|
|
+
|
|
|
+def GetMatchingCompletionsOnCursor_ReturnMatchIfMatches_test():
|
|
|
+ completions = [ _BuildCompletion( None ) ]
|
|
|
+ ycm_state = _SetupForCsharpCompletionDone( completions )
|
|
|
+ vimsupport.TextBeforeCursor = MagicMock( return_value = " Test" )
|
|
|
+
|
|
|
+ eq_( completions, ycm_state.GetMatchingCompletionsOnCursor() )
|
|
|
+
|
|
|
+
|
|
|
+def PostCompleteCsharp_EmptyDoesntInsertNamespace_test():
|
|
|
+ ycm_state = _SetupForCsharpCompletionDone( [] )
|
|
|
+
|
|
|
+ ycm_state.OnCompleteDone_Csharp()
|
|
|
|
|
|
assert not vimsupport.InsertNamespace.called
|
|
|
|
|
|
-def PostComplete_ExistingWithoutNamespaceDoesntInsertNamespace_test():
|
|
|
+
|
|
|
+def PostCompleteCsharp_ExistingWithoutNamespaceDoesntInsertNamespace_test():
|
|
|
completions = [ _BuildCompletion( None ) ]
|
|
|
- ycm_state = _SetupForCompletionDone( completions )
|
|
|
+ ycm_state = _SetupForCsharpCompletionDone( completions )
|
|
|
|
|
|
- ycm_state.OnCompleteDone()
|
|
|
+ ycm_state.OnCompleteDone_Csharp()
|
|
|
|
|
|
assert not vimsupport.InsertNamespace.called
|
|
|
|
|
|
|
|
|
-def PostComplete_ValueDoesInsertNamespace_test():
|
|
|
+def PostCompleteCsharp_ValueDoesInsertNamespace_test():
|
|
|
namespace = "A_NAMESPACE"
|
|
|
completions = [ _BuildCompletion( namespace ) ]
|
|
|
- ycm_state = _SetupForCompletionDone( completions )
|
|
|
+ ycm_state = _SetupForCsharpCompletionDone( completions )
|
|
|
|
|
|
- ycm_state.OnCompleteDone()
|
|
|
+ ycm_state.OnCompleteDone_Csharp()
|
|
|
|
|
|
vimsupport.InsertNamespace.assert_called_once_with( namespace )
|
|
|
|
|
|
-def PostComplete_InsertSecondNamespaceIfSelected_test():
|
|
|
+def PostCompleteCsharp_InsertSecondNamespaceIfSelected_test():
|
|
|
namespace = "A_NAMESPACE"
|
|
|
namespace2 = "ANOTHER_NAMESPACE"
|
|
|
completions = [
|
|
|
_BuildCompletion( namespace ),
|
|
|
_BuildCompletion( namespace2 ),
|
|
|
]
|
|
|
- ycm_state = _SetupForCompletionDone( completions )
|
|
|
+ ycm_state = _SetupForCsharpCompletionDone( completions )
|
|
|
vimsupport.PresentDialog = MagicMock( return_value = 1 )
|
|
|
|
|
|
- ycm_state.OnCompleteDone()
|
|
|
+ ycm_state.OnCompleteDone_Csharp()
|
|
|
|
|
|
vimsupport.InsertNamespace.assert_called_once_with( namespace2 )
|
|
|
|
|
|
|
|
|
-def _SetupForCompletionDone( completions ):
|
|
|
- vimsupport.CurrentFiletypes = MagicMock( return_value = [ "cs" ] )
|
|
|
+def _SetupForCsharpCompletionDone( completions ):
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
request = MagicMock();
|
|
|
request.Done = MagicMock( return_value = True )
|