Clean code in vimsupport tests

This commit is contained in:
micbou 2015-09-12 16:34:47 +02:00
parent 33316d8bf8
commit 2c72a3c598

View File

@ -20,6 +20,7 @@
from ycm import vimsupport from ycm import vimsupport
from nose.tools import eq_ from nose.tools import eq_
def ReplaceChunk_SingleLine_Repl_1_test(): def ReplaceChunk_SingleLine_Repl_1_test():
# Replace with longer range # Replace with longer range
# 12345678901234567 # 12345678901234567
@ -38,7 +39,7 @@ def ReplaceChunk_SingleLine_Repl_1_test():
# and replace again, using delta # and replace again, using delta
start, end = _BuildLocations( 1, 10, 1, 11 ) start, end = _BuildLocations( 1, 10, 1, 11 )
( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk( ( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk(
start, start,
end, end,
' piece of ', ' piece of ',
@ -58,7 +59,7 @@ def ReplaceChunk_SingleLine_Repl_1_test():
# and once more, for luck # and once more, for luck
start, end = _BuildLocations( 1, 11, 1, 17 ) start, end = _BuildLocations( 1, 11, 1, 17 )
( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk( ( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk(
start, start,
end, end,
'pie', 'pie',
@ -75,6 +76,7 @@ def ReplaceChunk_SingleLine_Repl_1_test():
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, 10 ) eq_( char_offset, 10 )
def ReplaceChunk_SingleLine_Repl_2_test(): def ReplaceChunk_SingleLine_Repl_2_test():
# Replace with shorter range # Replace with shorter range
# 12345678901234567 # 12345678901234567
@ -91,6 +93,7 @@ def ReplaceChunk_SingleLine_Repl_2_test():
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, -2 ) eq_( char_offset, -2 )
def ReplaceChunk_SingleLine_Repl_3_test(): def ReplaceChunk_SingleLine_Repl_3_test():
# Replace with equal range # Replace with equal range
# 12345678901234567 # 12345678901234567
@ -107,6 +110,7 @@ def ReplaceChunk_SingleLine_Repl_3_test():
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, 0 ) eq_( char_offset, 0 )
def ReplaceChunk_SingleLine_Add_1_test(): def ReplaceChunk_SingleLine_Add_1_test():
# Insert at start # Insert at start
result_buffer = [ "is a string" ] result_buffer = [ "is a string" ]
@ -122,6 +126,7 @@ def ReplaceChunk_SingleLine_Add_1_test():
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, 5 ) eq_( char_offset, 5 )
def ReplaceChunk_SingleLine_Add_2_test(): def ReplaceChunk_SingleLine_Add_2_test():
# Insert at end # Insert at end
result_buffer = [ "This is a " ] result_buffer = [ "This is a " ]
@ -137,6 +142,7 @@ def ReplaceChunk_SingleLine_Add_2_test():
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, 6 ) eq_( char_offset, 6 )
def ReplaceChunk_SingleLine_Add_3_test(): def ReplaceChunk_SingleLine_Add_3_test():
# Insert in the middle # Insert in the middle
result_buffer = [ "This is a string" ] result_buffer = [ "This is a string" ]
@ -152,6 +158,7 @@ def ReplaceChunk_SingleLine_Add_3_test():
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, 4 ) eq_( char_offset, 4 )
def ReplaceChunk_SingleLine_Del_1_test(): def ReplaceChunk_SingleLine_Del_1_test():
# Delete from start # Delete from start
result_buffer = [ "This is a string" ] result_buffer = [ "This is a string" ]
@ -167,6 +174,7 @@ def ReplaceChunk_SingleLine_Del_1_test():
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, -5 ) eq_( char_offset, -5 )
def ReplaceChunk_SingleLine_Del_2_test(): def ReplaceChunk_SingleLine_Del_2_test():
# Delete from end # Delete from end
result_buffer = [ "This is a string" ] result_buffer = [ "This is a string" ]
@ -182,6 +190,7 @@ def ReplaceChunk_SingleLine_Del_2_test():
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, -8 ) eq_( char_offset, -8 )
def ReplaceChunk_SingleLine_Del_3_test(): def ReplaceChunk_SingleLine_Del_3_test():
# Delete from middle # Delete from middle
result_buffer = [ "This is not a string" ] result_buffer = [ "This is not a string" ]
@ -197,6 +206,7 @@ def ReplaceChunk_SingleLine_Del_3_test():
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, -4 ) eq_( char_offset, -4 )
def ReplaceChunk_RemoveSingleLine_test(): def ReplaceChunk_RemoveSingleLine_test():
result_buffer = [ "aAa", "aBa", "aCa" ] result_buffer = [ "aAa", "aBa", "aCa" ]
start, end = _BuildLocations( 2, 1, 3, 1 ) start, end = _BuildLocations( 2, 1, 3, 1 )
@ -209,13 +219,13 @@ def ReplaceChunk_RemoveSingleLine_test():
def ReplaceChunk_SingleToMultipleLines_test(): def ReplaceChunk_SingleToMultipleLines_test():
result_buffer = [ "aAa", result_buffer = [ "aAa",
"aBa", "aBa",
"aCa" ] "aCa" ]
start, end = _BuildLocations( 2, 2, 2, 2 ) start, end = _BuildLocations( 2, 2, 2, 2 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'Eb\nbF', ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'Eb\nbF',
0, 0, result_buffer ) 0, 0, result_buffer )
expected_buffer = [ "aAa", expected_buffer = [ "aAa",
"aEb", "aEb",
"bFBa", "bFBa",
"aCa" ] "aCa" ]
@ -245,12 +255,12 @@ def ReplaceChunk_SingleToMultipleLines2_test():
result_buffer = [ "aAa", "aBa", "aCa" ] result_buffer = [ "aAa", "aBa", "aCa" ]
start, end = _BuildLocations( 2, 2, 2, 2 ) start, end = _BuildLocations( 2, 2, 2, 2 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
'Eb\nbFb\nG', 'Eb\nbFb\nG',
0, 0,
0, 0,
result_buffer ) result_buffer )
expected_buffer = [ "aAa", "aEb" ,"bFb", "GBa", "aCa" ] expected_buffer = [ "aAa", "aEb", "bFb", "GBa", "aCa" ]
eq_( expected_buffer, result_buffer ) eq_( expected_buffer, result_buffer )
eq_( line_offset, 2 ) eq_( line_offset, 2 )
eq_( char_offset, 0 ) eq_( char_offset, 0 )
@ -259,45 +269,47 @@ def ReplaceChunk_SingleToMultipleLines2_test():
def ReplaceChunk_SingleToMultipleLines3_test(): def ReplaceChunk_SingleToMultipleLines3_test():
result_buffer = [ "aAa", "aBa", "aCa" ] result_buffer = [ "aAa", "aBa", "aCa" ]
start, end = _BuildLocations( 2, 2, 2, 2 ) start, end = _BuildLocations( 2, 2, 2, 2 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
'Eb\nbFb\nbGb', 'Eb\nbFb\nbGb',
0, 0,
0, 0,
result_buffer ) result_buffer )
expected_buffer = [ "aAa", "aEb" ,"bFb", "bGbBa", "aCa" ] expected_buffer = [ "aAa", "aEb", "bFb", "bGbBa", "aCa" ]
eq_( expected_buffer, result_buffer ) eq_( expected_buffer, result_buffer )
eq_( line_offset, 2 ) eq_( line_offset, 2 )
eq_( char_offset, 2 ) eq_( char_offset, 2 )
def ReplaceChunk_SingleToMultipleLinesReplace_test(): def ReplaceChunk_SingleToMultipleLinesReplace_test():
result_buffer = [ "aAa", "aBa", "aCa" ] result_buffer = [ "aAa", "aBa", "aCa" ]
start, end = _BuildLocations( 1, 2, 1, 4 ) start, end = _BuildLocations( 1, 2, 1, 4 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
'Eb\nbFb\nbGb', 'Eb\nbFb\nbGb',
0, 0,
0, 0,
result_buffer ) result_buffer )
expected_buffer = [ "aEb", "bFb", "bGb", "aBa", "aCa" ] expected_buffer = [ "aEb", "bFb", "bGb", "aBa", "aCa" ]
eq_( expected_buffer, result_buffer ) eq_( expected_buffer, result_buffer )
eq_( line_offset, 2 ) eq_( line_offset, 2 )
eq_( char_offset, 0 ) eq_( char_offset, 0 )
def ReplaceChunk_SingleToMultipleLinesReplace_2_test(): def ReplaceChunk_SingleToMultipleLinesReplace_2_test():
result_buffer = [ "aAa", result_buffer = [ "aAa",
"aBa", "aBa",
"aCa" ] "aCa" ]
start, end = _BuildLocations( 1, 2, 1, 4 ) start, end = _BuildLocations( 1, 2, 1, 4 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
'Eb\nbFb\nbGb', 'Eb\nbFb\nbGb',
0, 0,
0, 0,
result_buffer ) result_buffer )
expected_buffer = [ "aEb", expected_buffer = [ "aEb",
"bFb", "bFb",
"bGb", "bGb",
"aBa", "aBa",
"aCa" ] "aCa" ]
eq_( expected_buffer, result_buffer ) eq_( expected_buffer, result_buffer )
@ -306,7 +318,7 @@ def ReplaceChunk_SingleToMultipleLinesReplace_2_test():
# now do a subsequent change (insert at end of line "1") # now do a subsequent change (insert at end of line "1")
start, end = _BuildLocations( 1, 4, 1, 4 ) start, end = _BuildLocations( 1, 4, 1, 4 )
( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk( ( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk(
start, start,
end, end,
'cccc', 'cccc',
@ -340,7 +352,7 @@ def ReplaceChunk_MultipleLinesToSingleLine_test():
# make another modification applying offsets # make another modification applying offsets
start, end = _BuildLocations( 3, 3, 3, 4 ) start, end = _BuildLocations( 3, 3, 3, 4 )
( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk( ( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk(
start, start,
end, end,
'cccc', 'cccc',
@ -357,7 +369,7 @@ def ReplaceChunk_MultipleLinesToSingleLine_test():
# and another, for luck # and another, for luck
start, end = _BuildLocations( 3, 4, 3, 5 ) start, end = _BuildLocations( 3, 4, 3, 5 )
( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk( ( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk(
start, start,
end, end,
'dd\ndd', 'dd\ndd',
@ -367,7 +379,7 @@ def ReplaceChunk_MultipleLinesToSingleLine_test():
line_offset += new_line_offset line_offset += new_line_offset
char_offset += new_char_offset char_offset += new_char_offset
eq_( [ "aAa", "aECccccdd", "ddaa" ], result_buffer ) eq_( [ "aAa", "aECccccdd", "ddaa" ], result_buffer )
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, -2 ) eq_( char_offset, -2 )
@ -387,11 +399,11 @@ def ReplaceChunk_MultipleLinesToSameMultipleLines_test():
def ReplaceChunk_MultipleLinesToMoreMultipleLines_test(): def ReplaceChunk_MultipleLinesToMoreMultipleLines_test():
result_buffer = [ "aAa", "aBa", "aCa", "aDe" ] result_buffer = [ "aAa", "aBa", "aCa", "aDe" ]
start, end = _BuildLocations( 2, 2, 3, 2 ) start, end = _BuildLocations( 2, 2, 3, 2 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
'Eb\nbFb\nbG', 'Eb\nbFb\nbG',
0, 0,
0, 0,
result_buffer ) result_buffer )
expected_buffer = [ "aAa", "aEb", "bFb", "bGCa", "aDe" ] expected_buffer = [ "aAa", "aEb", "bFb", "bGCa", "aDe" ]
eq_( expected_buffer, result_buffer ) eq_( expected_buffer, result_buffer )
@ -501,11 +513,11 @@ def ReplaceChunk_MultipleLinesToSingleLineOffsetWorks_test():
def ReplaceChunk_MultipleLineOffsetWorks_test(): def ReplaceChunk_MultipleLineOffsetWorks_test():
result_buffer = [ "aAa", "aBa", "aCa" ] result_buffer = [ "aAa", "aBa", "aCa" ]
start, end = _BuildLocations( 3, 1, 4, 3 ) start, end = _BuildLocations( 3, 1, 4, 3 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
'bDb\nbEb\nbFb', 'bDb\nbEb\nbFb',
-1, -1,
1, 1,
result_buffer ) result_buffer )
expected_buffer = [ "aAa", "abDb", "bEb", "bFba" ] expected_buffer = [ "aAa", "abDb", "bEb", "bFba" ]
eq_( expected_buffer, result_buffer ) eq_( expected_buffer, result_buffer )
@ -514,10 +526,10 @@ def ReplaceChunk_MultipleLineOffsetWorks_test():
def _BuildLocations( start_line, start_column, end_line, end_column ): def _BuildLocations( start_line, start_column, end_line, end_column ):
return { return {
'line_num' : start_line, 'line_num' : start_line,
'column_num': start_column, 'column_num': start_column,
}, { }, {
'line_num' : end_line, 'line_num' : end_line,
'column_num': end_column, 'column_num': end_column,
} }