|
@@ -32,7 +32,7 @@ MockVimModule()
|
|
|
|
|
|
from ycm import vimsupport
|
|
|
from nose.tools import eq_
|
|
|
-from hamcrest import assert_that, calling, equal_to, has_entry, none, raises
|
|
|
+from hamcrest import assert_that, calling, equal_to, has_entry, raises
|
|
|
from mock import MagicMock, call, patch
|
|
|
from ycmd.utils import ToBytes
|
|
|
import os
|
|
@@ -727,13 +727,14 @@ def ReplaceChunks_SingleFile_Open_test( vim_command,
|
|
|
get_buffer_number_for_filename,
|
|
|
set_fitting_height,
|
|
|
variable_exists ):
|
|
|
+ single_buffer_name = os.path.realpath( 'single_file' )
|
|
|
|
|
|
chunks = [
|
|
|
- _BuildChunk( 1, 1, 2, 1, 'replacement', 'single_file' )
|
|
|
+ _BuildChunk( 1, 1, 2, 1, 'replacement', single_buffer_name )
|
|
|
]
|
|
|
|
|
|
result_buffer = VimBuffer(
|
|
|
- 'single_file',
|
|
|
+ single_buffer_name,
|
|
|
contents = [
|
|
|
'line1',
|
|
|
'line2',
|
|
@@ -755,14 +756,14 @@ def ReplaceChunks_SingleFile_Open_test( vim_command,
|
|
|
# raise a warning)
|
|
|
# - once whilst applying the changes
|
|
|
get_buffer_number_for_filename.assert_has_exact_calls( [
|
|
|
- call( 'single_file', False ),
|
|
|
- call( 'single_file', False ),
|
|
|
+ call( single_buffer_name, False ),
|
|
|
+ call( single_buffer_name, False ),
|
|
|
] )
|
|
|
|
|
|
# BufferIsVisible is called twice for the same reasons as above
|
|
|
buffer_is_visible.assert_has_exact_calls( [
|
|
|
- call( 1 ),
|
|
|
- call( 1 ),
|
|
|
+ call( 1 ),
|
|
|
+ call( 1 ),
|
|
|
] )
|
|
|
|
|
|
# we don't attempt to open any files
|
|
@@ -770,25 +771,25 @@ def ReplaceChunks_SingleFile_Open_test( vim_command,
|
|
|
|
|
|
# But we do set the quickfix list
|
|
|
vim_eval.assert_has_exact_calls( [
|
|
|
- call( 'setqflist( {0} )'.format( json.dumps( [ {
|
|
|
- 'bufnr': 1,
|
|
|
- 'filename': 'single_file',
|
|
|
- 'lnum': 1,
|
|
|
- 'col': 1,
|
|
|
- 'text': 'replacement',
|
|
|
- 'type': 'F'
|
|
|
- } ] ) ) ),
|
|
|
+ call( 'setqflist( {0} )'.format( json.dumps( [ {
|
|
|
+ 'bufnr': 1,
|
|
|
+ 'filename': single_buffer_name,
|
|
|
+ 'lnum': 1,
|
|
|
+ 'col': 1,
|
|
|
+ 'text': 'replacement',
|
|
|
+ 'type': 'F'
|
|
|
+ } ] ) ) ),
|
|
|
] )
|
|
|
vim_command.assert_has_exact_calls( [
|
|
|
- call( 'botright copen' ),
|
|
|
- call( 'silent! wincmd p' )
|
|
|
+ call( 'botright copen' ),
|
|
|
+ call( 'silent! wincmd p' )
|
|
|
] )
|
|
|
set_fitting_height.assert_called_once_with()
|
|
|
|
|
|
# And it is ReplaceChunks that prints the message showing the number of
|
|
|
# changes
|
|
|
post_vim_message.assert_has_exact_calls( [
|
|
|
- call( 'Applied 1 changes', warning = False ),
|
|
|
+ call( 'Applied 1 changes', warning = False ),
|
|
|
] )
|
|
|
|
|
|
|
|
@@ -817,13 +818,14 @@ def ReplaceChunks_SingleFile_NotOpen_test( vim_command,
|
|
|
get_buffer_number_for_filename,
|
|
|
set_fitting_height,
|
|
|
variable_exists ):
|
|
|
+ single_buffer_name = os.path.realpath( 'single_file' )
|
|
|
|
|
|
chunks = [
|
|
|
- _BuildChunk( 1, 1, 2, 1, 'replacement', 'single_file' )
|
|
|
+ _BuildChunk( 1, 1, 2, 1, 'replacement', single_buffer_name )
|
|
|
]
|
|
|
|
|
|
result_buffer = VimBuffer(
|
|
|
- 'single_file',
|
|
|
+ single_buffer_name,
|
|
|
contents = [
|
|
|
'line1',
|
|
|
'line2',
|
|
@@ -852,9 +854,9 @@ def ReplaceChunks_SingleFile_NotOpen_test( vim_command,
|
|
|
# - once whilst applying the changes (-1 return)
|
|
|
# - finally after calling OpenFilename (1 return)
|
|
|
get_buffer_number_for_filename.assert_has_exact_calls( [
|
|
|
- call( 'single_file', False ),
|
|
|
- call( 'single_file', False ),
|
|
|
- call( 'single_file', False ),
|
|
|
+ call( single_buffer_name, False ),
|
|
|
+ call( single_buffer_name, False ),
|
|
|
+ call( single_buffer_name, False ),
|
|
|
] )
|
|
|
|
|
|
# BufferIsVisible is called 3 times for the same reasons as above, with the
|
|
@@ -866,7 +868,7 @@ def ReplaceChunks_SingleFile_NotOpen_test( vim_command,
|
|
|
] )
|
|
|
|
|
|
# We open 'single_file' as expected.
|
|
|
- open_filename.assert_called_with( 'single_file', {
|
|
|
+ open_filename.assert_called_with( single_buffer_name, {
|
|
|
'focus': True,
|
|
|
'fix': True,
|
|
|
'size': 10
|
|
@@ -886,7 +888,7 @@ def ReplaceChunks_SingleFile_NotOpen_test( vim_command,
|
|
|
call( '&previewheight' ),
|
|
|
call( 'setqflist( {0} )'.format( json.dumps( [ {
|
|
|
'bufnr': 1,
|
|
|
- 'filename': 'single_file',
|
|
|
+ 'filename': single_buffer_name,
|
|
|
'lnum': 1,
|
|
|
'col': 1,
|
|
|
'text': 'replacement',
|
|
@@ -929,13 +931,14 @@ def ReplaceChunks_User_Declines_To_Open_File_test(
|
|
|
|
|
|
# Same as above, except the user selects Cancel when asked if they should
|
|
|
# allow us to open lots of (ahem, 1) file.
|
|
|
+ single_buffer_name = os.path.realpath( 'single_file' )
|
|
|
|
|
|
chunks = [
|
|
|
- _BuildChunk( 1, 1, 2, 1, 'replacement', 'single_file' )
|
|
|
+ _BuildChunk( 1, 1, 2, 1, 'replacement', single_buffer_name )
|
|
|
]
|
|
|
|
|
|
result_buffer = VimBuffer(
|
|
|
- 'single_file',
|
|
|
+ single_buffer_name,
|
|
|
contents = [
|
|
|
'line1',
|
|
|
'line2',
|
|
@@ -963,7 +966,7 @@ def ReplaceChunks_User_Declines_To_Open_File_test(
|
|
|
# - once to the check if we would require opening the file (so that we can
|
|
|
# raise a warning) (-1 return)
|
|
|
get_buffer_number_for_filename.assert_has_exact_calls( [
|
|
|
- call( 'single_file', False ),
|
|
|
+ call( single_buffer_name, False ),
|
|
|
] )
|
|
|
|
|
|
# BufferIsVisible is called once for the above file, which wasn't visible.
|
|
@@ -1009,13 +1012,14 @@ def ReplaceChunks_User_Aborts_Opening_File_test(
|
|
|
|
|
|
# Same as above, except the user selects Abort or Quick during the
|
|
|
# "swap-file-found" dialog
|
|
|
+ single_buffer_name = os.path.realpath( 'single_file' )
|
|
|
|
|
|
chunks = [
|
|
|
- _BuildChunk( 1, 1, 2, 1, 'replacement', 'single_file' )
|
|
|
+ _BuildChunk( 1, 1, 2, 1, 'replacement', single_buffer_name )
|
|
|
]
|
|
|
|
|
|
result_buffer = VimBuffer(
|
|
|
- 'single_file',
|
|
|
+ single_buffer_name,
|
|
|
contents = [
|
|
|
'line1',
|
|
|
'line2',
|
|
@@ -1026,10 +1030,10 @@ def ReplaceChunks_User_Aborts_Opening_File_test(
|
|
|
with patch( 'vim.buffers', [ None, result_buffer, None ] ):
|
|
|
assert_that( calling( vimsupport.ReplaceChunks ).with_args( chunks ),
|
|
|
raises( RuntimeError,
|
|
|
- 'Unable to open file: single_file\nFixIt/Refactor operation '
|
|
|
- 'aborted prior to completion. Your files have not been '
|
|
|
- 'fully updated. Please use undo commands to revert the '
|
|
|
- 'applied changes.' ) )
|
|
|
+ 'Unable to open file: .+single_file\n'
|
|
|
+ 'FixIt/Refactor operation aborted prior to completion. '
|
|
|
+ 'Your files have not been fully updated. '
|
|
|
+ 'Please use undo commands to revert the applied changes.' ) )
|
|
|
|
|
|
# We checked if it was OK to open the file
|
|
|
confirm.assert_has_exact_calls( [
|
|
@@ -1044,7 +1048,7 @@ def ReplaceChunks_User_Aborts_Opening_File_test(
|
|
|
] )
|
|
|
|
|
|
# We tried to open this file
|
|
|
- open_filename.assert_called_with( "single_file", {
|
|
|
+ open_filename.assert_called_with( single_buffer_name, {
|
|
|
'focus': True,
|
|
|
'fix': True,
|
|
|
'size': 10
|
|
@@ -1059,10 +1063,10 @@ def ReplaceChunks_User_Aborts_Opening_File_test(
|
|
|
@patch( 'ycm.vimsupport.SetFittingHeightForCurrentWindow' )
|
|
|
@patch( 'ycm.vimsupport.GetBufferNumberForFilename', side_effect = [
|
|
|
22, # first_file (check)
|
|
|
- -1, # another_file (check)
|
|
|
+ -1, # second_file (check)
|
|
|
22, # first_file (apply)
|
|
|
- -1, # another_file (apply)
|
|
|
- 19, # another_file (check after open)
|
|
|
+ -1, # second_file (apply)
|
|
|
+ 19, # second_file (check after open)
|
|
|
],
|
|
|
new_callable = ExtendedMock )
|
|
|
@patch( 'ycm.vimsupport.BufferIsVisible', side_effect = [
|
|
@@ -1094,14 +1098,16 @@ def ReplaceChunks_MultiFile_Open_test( vim_command,
|
|
|
variable_exists ):
|
|
|
|
|
|
# Chunks are split across 2 files, one is already open, one isn't
|
|
|
+ first_buffer_name = os.path.realpath( '1_first_file' )
|
|
|
+ second_buffer_name = os.path.realpath( '2_second_file' )
|
|
|
|
|
|
chunks = [
|
|
|
- _BuildChunk( 1, 1, 2, 1, 'first_file_replacement ', '1_first_file' ),
|
|
|
- _BuildChunk( 2, 1, 2, 1, 'second_file_replacement ', '2_another_file' ),
|
|
|
+ _BuildChunk( 1, 1, 2, 1, 'first_file_replacement ', first_buffer_name ),
|
|
|
+ _BuildChunk( 2, 1, 2, 1, 'second_file_replacement ', second_buffer_name ),
|
|
|
]
|
|
|
|
|
|
first_file = VimBuffer(
|
|
|
- '1_first_file',
|
|
|
+ first_buffer_name,
|
|
|
number = 22,
|
|
|
contents = [
|
|
|
'line1',
|
|
@@ -1109,8 +1115,8 @@ def ReplaceChunks_MultiFile_Open_test( vim_command,
|
|
|
'line3',
|
|
|
]
|
|
|
)
|
|
|
- another_file = VimBuffer(
|
|
|
- '2_another_file',
|
|
|
+ second_file = VimBuffer(
|
|
|
+ second_buffer_name,
|
|
|
number = 19,
|
|
|
contents = [
|
|
|
'another line1',
|
|
@@ -1120,18 +1126,18 @@ def ReplaceChunks_MultiFile_Open_test( vim_command,
|
|
|
|
|
|
vim_buffers = [ None ] * 23
|
|
|
vim_buffers[ 22 ] = first_file
|
|
|
- vim_buffers[ 19 ] = another_file
|
|
|
+ vim_buffers[ 19 ] = second_file
|
|
|
|
|
|
with patch( 'vim.buffers', vim_buffers ):
|
|
|
vimsupport.ReplaceChunks( chunks )
|
|
|
|
|
|
# We checked for the right file names
|
|
|
get_buffer_number_for_filename.assert_has_exact_calls( [
|
|
|
- call( '1_first_file', False ),
|
|
|
- call( '2_another_file', False ),
|
|
|
- call( '1_first_file', False ),
|
|
|
- call( '2_another_file', False ),
|
|
|
- call( '2_another_file', False ),
|
|
|
+ call( first_buffer_name, False ),
|
|
|
+ call( second_buffer_name, False ),
|
|
|
+ call( first_buffer_name, False ),
|
|
|
+ call( second_buffer_name, False ),
|
|
|
+ call( second_buffer_name, False ),
|
|
|
] )
|
|
|
|
|
|
# We checked if it was OK to open the file
|
|
@@ -1140,7 +1146,7 @@ def ReplaceChunks_MultiFile_Open_test( vim_command,
|
|
|
] )
|
|
|
|
|
|
# Ensure that buffers are updated
|
|
|
- eq_( another_file.GetLines(), [
|
|
|
+ eq_( second_file.GetLines(), [
|
|
|
'another line1',
|
|
|
'second_file_replacement ACME line2',
|
|
|
] )
|
|
@@ -1149,8 +1155,8 @@ def ReplaceChunks_MultiFile_Open_test( vim_command,
|
|
|
'line3',
|
|
|
] )
|
|
|
|
|
|
- # We open '2_another_file' as expected.
|
|
|
- open_filename.assert_called_with( '2_another_file', {
|
|
|
+ # We open '2_second_file' as expected.
|
|
|
+ open_filename.assert_called_with( second_buffer_name, {
|
|
|
'focus': True,
|
|
|
'fix': True,
|
|
|
'size': 10
|
|
@@ -1170,14 +1176,14 @@ def ReplaceChunks_MultiFile_Open_test( vim_command,
|
|
|
call( '&previewheight' ),
|
|
|
call( 'setqflist( {0} )'.format( json.dumps( [ {
|
|
|
'bufnr': 22,
|
|
|
- 'filename': '1_first_file',
|
|
|
+ 'filename': first_buffer_name,
|
|
|
'lnum': 1,
|
|
|
'col': 1,
|
|
|
'text': 'first_file_replacement ',
|
|
|
'type': 'F'
|
|
|
}, {
|
|
|
'bufnr': 19,
|
|
|
- 'filename': '2_another_file',
|
|
|
+ 'filename': second_buffer_name,
|
|
|
'lnum': 2,
|
|
|
'col': 1,
|
|
|
'text': 'second_file_replacement ',
|
|
@@ -1320,34 +1326,10 @@ def WriteToPreviewWindow_JumpFail_MultiLine_test( vim_current, vim_command ):
|
|
|
vim_current.buffer.options.__setitem__.assert_not_called()
|
|
|
|
|
|
|
|
|
-def CheckFilename_test():
|
|
|
- assert_that(
|
|
|
- calling( vimsupport.CheckFilename ).with_args( None ),
|
|
|
- raises( RuntimeError, "'None' is not a valid filename" )
|
|
|
- )
|
|
|
-
|
|
|
- assert_that(
|
|
|
- calling( vimsupport.CheckFilename ).with_args( 'nonexistent_file' ),
|
|
|
- raises( RuntimeError,
|
|
|
- "filename 'nonexistent_file' cannot be opened. "
|
|
|
- "No such file or directory." )
|
|
|
- )
|
|
|
-
|
|
|
- assert_that( vimsupport.CheckFilename( __file__ ), none() )
|
|
|
-
|
|
|
-
|
|
|
def BufferIsVisibleForFilename_test():
|
|
|
vim_buffers = [
|
|
|
- VimBuffer(
|
|
|
- os.path.realpath( 'visible_filename' ),
|
|
|
- number = 1,
|
|
|
- window = 1
|
|
|
- ),
|
|
|
- VimBuffer(
|
|
|
- os.path.realpath( 'hidden_filename' ),
|
|
|
- number = 2,
|
|
|
- window = None
|
|
|
- )
|
|
|
+ VimBuffer( 'visible_filename', number = 1, window = 1 ),
|
|
|
+ VimBuffer( 'hidden_filename', number = 2, window = None )
|
|
|
]
|
|
|
|
|
|
with patch( 'vim.buffers', vim_buffers ):
|
|
@@ -1361,14 +1343,8 @@ def BufferIsVisibleForFilename_test():
|
|
|
new_callable = ExtendedMock )
|
|
|
def CloseBuffersForFilename_test( vim_command, *args ):
|
|
|
vim_buffers = [
|
|
|
- VimBuffer(
|
|
|
- os.path.realpath( 'some_filename' ),
|
|
|
- number = 2
|
|
|
- ),
|
|
|
- VimBuffer(
|
|
|
- os.path.realpath( 'some_filename' ),
|
|
|
- number = 5
|
|
|
- )
|
|
|
+ VimBuffer( 'some_filename', number = 2 ),
|
|
|
+ VimBuffer( 'some_filename', number = 5 )
|
|
|
]
|
|
|
|
|
|
with patch( 'vim.buffers', vim_buffers ):
|
|
@@ -1383,10 +1359,11 @@ def CloseBuffersForFilename_test( vim_command, *args ):
|
|
|
@patch( 'vim.command', new_callable = ExtendedMock )
|
|
|
@patch( 'vim.current', new_callable = ExtendedMock )
|
|
|
def OpenFilename_test( vim_current, vim_command ):
|
|
|
- # Options used to open a logfile
|
|
|
+ # Options used to open a logfile.
|
|
|
options = {
|
|
|
'size': vimsupport.GetIntValue( '&previewheight' ),
|
|
|
'fix': True,
|
|
|
+ 'focus': False,
|
|
|
'watch': True,
|
|
|
'position': 'end'
|
|
|
}
|