Browse Source

virtual text - fix up awful mock tests

Ben Jackson 2 năm trước cách đây
mục cha
commit
9523936c48

+ 13 - 19
python/ycm/tests/test_utils.py

@@ -42,18 +42,12 @@ BWIPEOUT_REGEX = re.compile(
 GETBUFVAR_REGEX = re.compile(
   '^getbufvar\\((?P<buffer_number>[0-9]+), "(?P<option>.+)"\\)$' )
 PROP_ADD_REGEX = re.compile(
-        '^prop_add\\( ' # A literal at the start
-        '(?P<start_line>\\d+), ' # First argument - number
+        '^prop_add\\( '            # A literal at the start
+        '(?P<start_line>\\d+), '   # First argument - number
         '(?P<start_column>\\d+), ' # Second argument - number
-        '{'                        # Third argument is a complex dict.
-          '('                        # And some keys are optional.
-            '\'end_lnum\': (?P<end_line>\\d+), '
-            '\'end_col\': (?P<end_column>\\d+), '
-          ')?'                       # End of optional keys
-            '\'type\': \'(?P<type>\\w+)\', '
-            '\'bufnr\': (?P<bufnr>\\d+), '
-            '\'id\': (?P<id>\\d+)'
-        '} \\)$' )
+        '{(?P<opts>.+)} '          # Third argument is a complex dict, which
+                                   # we parse separately
+        '\\)$' )
 PROP_REMOVE_REGEX = re.compile( '^prop_remove\\( (?P<prop>.+) \\)$' )
 OMNIFUNC_REGEX_FORMAT = (
   '^{omnifunc_name}\\((?P<findstart>[01]),[\'"](?P<base>.*)[\'"]\\)$' )
@@ -263,23 +257,23 @@ def _MockVimPropEval( value ):
 
   match = PROP_ADD_REGEX.search( value )
   if match:
-    prop_type = match.group( 'type' )
     prop_start_line = int( match.group( 'start_line' ) )
     prop_start_column = int( match.group( 'start_column' ) )
-    prop_end_line = match.group( 'end_line' )
-    prop_end_column = match.group( 'end_column' )
+    import ast
+    opts = ast.literal_eval( '{' + match.group( 'opts' ) + '}' )
     vim_prop = VimProp(
-        prop_type,
+        opts[ 'type' ],
         prop_start_line,
         prop_start_column,
-        int( prop_end_line ) if prop_end_line else prop_end_line,
-        int( prop_end_column ) if prop_end_column else prop_end_column )
-    VIM_PROPS_FOR_BUFFER[ int( match.group( 'bufnr' ) ) ].append( vim_prop )
+        int( opts[ 'end_lnum' ] ) if opts[ 'end_lnum' ] else prop_start_line,
+        int( opts[ 'end_col' ] ) if opts[ 'end_col' ] else prop_start_column
+    )
+    VIM_PROPS_FOR_BUFFER[ int( opts[ 'bufnr' ] ) ].append( vim_prop )
     return vim_prop.id
 
   match = PROP_REMOVE_REGEX.search( value )
   if match:
-    prop = eval( match.group( 'prop' ) )
+    prop, lin_num = eval( match.group( 'prop' ) )
     vim_props = VIM_PROPS_FOR_BUFFER[ prop[ 'bufnr' ] ]
     for index, vim_prop in enumerate( vim_props ):
       if vim_prop.id == prop[ 'id' ]:

+ 4 - 2
python/ycm/tests/youcompleteme_test.py

@@ -339,7 +339,8 @@ class YouCompleteMeTest( TestCase ):
 
 
   @YouCompleteMeInstance( { 'g:ycm_extra_conf_vim_data': [ 'tempname()' ] } )
-  def test_YouCompleteMe_DebugInfo_ServerRunning( self, ycm ):
+  @patch( 'ycm.vimsupport.VimSupportsPopupWindows', return_value=True )
+  def test_YouCompleteMe_DebugInfo_ServerRunning( self, ycm, *args ):
     dir_of_script = os.path.dirname( os.path.abspath( __file__ ) )
     buf_name = os.path.join( dir_of_script, 'testdata', 'test.cpp' )
     extra_conf = os.path.join( dir_of_script, 'testdata', '.ycm_extra_conf.py' )
@@ -367,7 +368,8 @@ class YouCompleteMeTest( TestCase ):
 
 
   @YouCompleteMeInstance()
-  def test_YouCompleteMe_DebugInfo_ServerNotRunning( self, ycm ):
+  @patch( 'ycm.vimsupport.VimSupportsPopupWindows', return_value=True )
+  def test_YouCompleteMe_DebugInfo_ServerNotRunning( self, ycm, *args ):
     StopServer( ycm )
 
     current_buffer = VimBuffer( 'current_buffer' )

+ 6 - 9
python/ycm/vimsupport.py

@@ -361,9 +361,7 @@ def AddTextProperty( buffer_number,
       'type': prop_type,
       'bufnr': buffer_number
     } )
-    return GetIntValue(
-      vim.eval( f'prop_add( { line }, { column }, { extra_args } )' )
-    )
+    return GetIntValue( f'prop_add( { line }, { column }, { extra_args } )' )
   else:
     extra_args[ 'hl_group' ] = prop_type
     # Neovim uses 0-based offsets
@@ -373,12 +371,11 @@ def AddTextProperty( buffer_number,
       extra_args[ 'end_col' ] = extra_args.pop( 'end_col' ) - 1
     line -= 1
     column -= 1
-    return GetIntValue(
-      vim.eval( f'nvim_buf_set_extmark( { buffer_number }, '
-                                         f'{ YCM_NEOVIM_NS_ID }, '
-                                         f'{ line }, '
-                                         f'{ column }, '
-                                         f'{ extra_args } )' ) )
+    return GetIntValue( f'nvim_buf_set_extmark( { buffer_number }, '
+                                              f'{ YCM_NEOVIM_NS_ID }, '
+                                              f'{ line }, '
+                                              f'{ column }, '
+                                              f'{ extra_args } )' )
 
 
 def RemoveDiagnosticProperty( buffer_number: int, prop: DiagnosticProperty ):