Update ReplaceChunk tests

Do not convert strings to bytes but instead use plain strings to mimic
Vim buffers returning a list of byte objects on Python 2 and unicode
objects on Python 3.
This commit is contained in:
micbou 2016-07-13 23:19:41 +02:00
parent d5610e577c
commit a986b3ed0e

View File

@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>. # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals # Intentionally not importing unicode_literals!
from __future__ import print_function from __future__ import print_function
from __future__ import division from __future__ import division
from __future__ import absolute_import from __future__ import absolute_import
@ -37,9 +37,15 @@ import os
import json import json
def AssertBuffersAreEqualAsBytes( result_buffer, expected_buffer ):
eq_( len( result_buffer ), len( expected_buffer ) )
for result_line, expected_line in zip( result_buffer, expected_buffer ):
eq_( ToBytes( result_line ), ToBytes( expected_line ) )
def ReplaceChunk_SingleLine_Repl_1_test(): def ReplaceChunk_SingleLine_Repl_1_test():
# Replace with longer range # Replace with longer range
result_buffer = [ ToBytes( "This is a string" ) ] result_buffer = [ 'This is a string' ]
start, end = _BuildLocations( 1, 1, 1, 5 ) start, end = _BuildLocations( 1, 1, 1, 5 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
@ -48,7 +54,7 @@ def ReplaceChunk_SingleLine_Repl_1_test():
0, 0,
result_buffer ) result_buffer )
eq_( [ ToBytes( "How long is a string" ) ], result_buffer ) AssertBuffersAreEqualAsBytes( [ 'How long is a string' ], result_buffer )
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, 4 ) eq_( char_offset, 4 )
@ -65,7 +71,8 @@ def ReplaceChunk_SingleLine_Repl_1_test():
line_offset += new_line_offset line_offset += new_line_offset
char_offset += new_char_offset char_offset += new_char_offset
eq_( [ ToBytes( 'How long is a piece of string' ) ], result_buffer ) AssertBuffersAreEqualAsBytes( [ 'How long is a piece of string' ],
result_buffer )
eq_( new_line_offset, 0 ) eq_( new_line_offset, 0 )
eq_( new_char_offset, 9 ) eq_( new_char_offset, 9 )
eq_( line_offset, 0 ) eq_( line_offset, 0 )
@ -85,7 +92,8 @@ def ReplaceChunk_SingleLine_Repl_1_test():
line_offset += new_line_offset line_offset += new_line_offset
char_offset += new_char_offset char_offset += new_char_offset
eq_( [ ToBytes( 'How long is a piece of pie' ) ], result_buffer ) AssertBuffersAreEqualAsBytes( [ 'How long is a piece of pie' ],
result_buffer )
eq_( new_line_offset, 0 ) eq_( new_line_offset, 0 )
eq_( new_char_offset, -3 ) eq_( new_char_offset, -3 )
eq_( line_offset, 0 ) eq_( line_offset, 0 )
@ -94,7 +102,7 @@ def ReplaceChunk_SingleLine_Repl_1_test():
def ReplaceChunk_SingleLine_Repl_2_test(): def ReplaceChunk_SingleLine_Repl_2_test():
# Replace with shorter range # Replace with shorter range
result_buffer = [ ToBytes( "This is a string" ) ] result_buffer = [ 'This is a string' ]
start, end = _BuildLocations( 1, 11, 1, 17 ) start, end = _BuildLocations( 1, 11, 1, 17 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
@ -103,14 +111,14 @@ def ReplaceChunk_SingleLine_Repl_2_test():
0, 0,
result_buffer ) result_buffer )
eq_( [ ToBytes( "This is a test" ) ], result_buffer ) AssertBuffersAreEqualAsBytes( [ 'This is a test' ], result_buffer )
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
result_buffer = [ ToBytes( "This is a string" ) ] result_buffer = [ 'This is a string' ]
start, end = _BuildLocations( 1, 6, 1, 8 ) start, end = _BuildLocations( 1, 6, 1, 8 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
@ -119,14 +127,14 @@ def ReplaceChunk_SingleLine_Repl_3_test():
0, 0,
result_buffer ) result_buffer )
eq_( [ ToBytes( "This be a string" ) ], result_buffer ) AssertBuffersAreEqualAsBytes( [ 'This be a string' ], result_buffer )
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 = [ ToBytes( "is a string" ) ] result_buffer = [ 'is a string' ]
start, end = _BuildLocations( 1, 1, 1, 1 ) start, end = _BuildLocations( 1, 1, 1, 1 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
@ -135,14 +143,14 @@ def ReplaceChunk_SingleLine_Add_1_test():
0, 0,
result_buffer ) result_buffer )
eq_( [ ToBytes( "This is a string" ) ], result_buffer ) AssertBuffersAreEqualAsBytes( [ 'This is a string' ], result_buffer )
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 = [ ToBytes( "This is a " ) ] result_buffer = [ 'This is a ' ]
start, end = _BuildLocations( 1, 11, 1, 11 ) start, end = _BuildLocations( 1, 11, 1, 11 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
@ -151,14 +159,14 @@ def ReplaceChunk_SingleLine_Add_2_test():
0, 0,
result_buffer ) result_buffer )
eq_( [ ToBytes( "This is a string" ) ], result_buffer ) AssertBuffersAreEqualAsBytes( [ 'This is a string' ], result_buffer )
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 = [ ToBytes( "This is a string" ) ] result_buffer = [ 'This is a string' ]
start, end = _BuildLocations( 1, 8, 1, 8 ) start, end = _BuildLocations( 1, 8, 1, 8 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
@ -167,14 +175,14 @@ def ReplaceChunk_SingleLine_Add_3_test():
0, 0,
result_buffer ) result_buffer )
eq_( [ ToBytes( "This is not a string" ) ], result_buffer ) AssertBuffersAreEqualAsBytes( [ 'This is not a string' ], result_buffer )
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 = [ ToBytes( "This is a string" ) ] result_buffer = [ 'This is a string' ]
start, end = _BuildLocations( 1, 1, 1, 6 ) start, end = _BuildLocations( 1, 1, 1, 6 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
@ -183,14 +191,14 @@ def ReplaceChunk_SingleLine_Del_1_test():
0, 0,
result_buffer ) result_buffer )
eq_( [ ToBytes( "is a string" ) ], result_buffer ) AssertBuffersAreEqualAsBytes( [ 'is a string' ], result_buffer )
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 = [ ToBytes( "This is a string" ) ] result_buffer = [ 'This is a string' ]
start, end = _BuildLocations( 1, 10, 1, 18 ) start, end = _BuildLocations( 1, 10, 1, 18 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
@ -199,14 +207,14 @@ def ReplaceChunk_SingleLine_Del_2_test():
0, 0,
result_buffer ) result_buffer )
eq_( [ ToBytes( "This is a" ) ], result_buffer ) AssertBuffersAreEqualAsBytes( [ 'This is a' ], result_buffer )
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 = [ ToBytes( "This is not a string" ) ] result_buffer = [ 'This is not a string' ]
start, end = _BuildLocations( 1, 9, 1, 13 ) start, end = _BuildLocations( 1, 9, 1, 13 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
@ -215,14 +223,14 @@ def ReplaceChunk_SingleLine_Del_3_test():
0, 0,
result_buffer ) result_buffer )
eq_( [ ToBytes( "This is a string" ) ], result_buffer ) AssertBuffersAreEqualAsBytes( [ 'This is a string' ], result_buffer )
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, -4 ) eq_( char_offset, -4 )
def ReplaceChunk_SingleLine_Unicode_ReplaceUnicodeChars_test(): def ReplaceChunk_SingleLine_Unicode_ReplaceUnicodeChars_test():
# Replace Unicode characters. # Replace Unicode characters.
result_buffer = [ ToBytes( "This Uniçø∂‰ string is in the middle" ) ] result_buffer = [ 'This Uniçø∂‰ string is in the middle' ]
start, end = _BuildLocations( 1, 6, 1, 20 ) start, end = _BuildLocations( 1, 6, 1, 20 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
@ -231,14 +239,15 @@ def ReplaceChunk_SingleLine_Unicode_ReplaceUnicodeChars_test():
0, 0,
result_buffer ) result_buffer )
eq_( [ ToBytes( "This Unicode string is in the middle" ) ], result_buffer ) AssertBuffersAreEqualAsBytes( [ 'This Unicode string is in the middle' ],
result_buffer )
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, -6 ) eq_( char_offset, -6 )
def ReplaceChunk_SingleLine_Unicode_ReplaceAfterUnicode_test(): def ReplaceChunk_SingleLine_Unicode_ReplaceAfterUnicode_test():
# Replace ASCII characters after Unicode characters in the line. # Replace ASCII characters after Unicode characters in the line.
result_buffer = [ ToBytes( "This Uniçø∂‰ string is in the middle" ) ] result_buffer = [ 'This Uniçø∂‰ string is in the middle' ]
start, end = _BuildLocations( 1, 30, 1, 43 ) start, end = _BuildLocations( 1, 30, 1, 43 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
@ -247,14 +256,15 @@ def ReplaceChunk_SingleLine_Unicode_ReplaceAfterUnicode_test():
0, 0,
result_buffer ) result_buffer )
eq_( [ ToBytes( "This Uniçø∂‰ string is fåke" ) ], result_buffer ) AssertBuffersAreEqualAsBytes( [ 'This Uniçø∂‰ string is fåke' ],
result_buffer )
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, -8 ) eq_( char_offset, -8 )
def ReplaceChunk_SingleLine_Unicode_Grown_test(): def ReplaceChunk_SingleLine_Unicode_Grown_test():
# Replace ASCII characters after Unicode characters in the line. # Replace ASCII characters after Unicode characters in the line.
result_buffer = [ ToBytes( "a" ) ] result_buffer = [ 'a' ]
start, end = _BuildLocations( 1, 1, 1, 2 ) start, end = _BuildLocations( 1, 1, 1, 2 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
end, end,
@ -263,37 +273,38 @@ def ReplaceChunk_SingleLine_Unicode_Grown_test():
0, 0,
result_buffer ) result_buffer )
eq_( [ ToBytes( "å" ) ], result_buffer ) AssertBuffersAreEqualAsBytes( [ 'å' ], result_buffer )
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, 1 ) # Note: byte difference (a = 1 byte, å = 2 bytes) eq_( char_offset, 1 ) # Note: byte difference (a = 1 byte, å = 2 bytes)
def ReplaceChunk_RemoveSingleLine_test(): def ReplaceChunk_RemoveSingleLine_test():
result_buffer = [ ToBytes( "aAa" ), result_buffer = [ 'aAa',
ToBytes( "aBa" ), 'aBa',
ToBytes( "aCa" ) ] 'aCa' ]
start, end = _BuildLocations( 2, 1, 3, 1 ) start, end = _BuildLocations( 2, 1, 3, 1 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, '', ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, '',
0, 0, result_buffer ) 0, 0, result_buffer )
expected_buffer = [ ToBytes( "aAa" ), # First line is not affected.
ToBytes( "aCa" ) ] expected_buffer = [ 'aAa',
eq_( expected_buffer, result_buffer ) 'aCa' ]
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
eq_( line_offset, -1 ) eq_( line_offset, -1 )
eq_( char_offset, 0 ) eq_( char_offset, 0 )
def ReplaceChunk_SingleToMultipleLines_test(): def ReplaceChunk_SingleToMultipleLines_test():
result_buffer = [ ToBytes( "aAa" ), result_buffer = [ 'aAa',
ToBytes( "aBa" ), 'aBa',
ToBytes( "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 = [ ToBytes( "aAa" ), expected_buffer = [ 'aAa',
ToBytes( "aEb" ), 'aEb',
ToBytes( "bFBa" ), 'bFBa',
ToBytes( "aCa" ) ] 'aCa' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
eq_( line_offset, 1 ) eq_( line_offset, 1 )
eq_( char_offset, 1 ) eq_( char_offset, 1 )
@ -310,16 +321,16 @@ def ReplaceChunk_SingleToMultipleLines_test():
line_offset += new_line_offset line_offset += new_line_offset
char_offset += new_char_offset char_offset += new_char_offset
eq_( [ ToBytes( "aAa" ), AssertBuffersAreEqualAsBytes( [ 'aAa',
ToBytes( "aEb" ), 'aEb',
ToBytes( "bFBcccc" ), 'bFBcccc',
ToBytes( "aCa" ) ], result_buffer ) 'aCa' ], result_buffer )
eq_( line_offset, 1 ) eq_( line_offset, 1 )
eq_( char_offset, 4 ) eq_( char_offset, 4 )
def ReplaceChunk_SingleToMultipleLines2_test(): def ReplaceChunk_SingleToMultipleLines2_test():
result_buffer = [ ToBytes( "aAa" ), ToBytes( "aBa" ), ToBytes( "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,
@ -327,18 +338,18 @@ def ReplaceChunk_SingleToMultipleLines2_test():
0, 0,
0, 0,
result_buffer ) result_buffer )
expected_buffer = [ ToBytes( "aAa" ), expected_buffer = [ 'aAa',
ToBytes( "aEb" ), 'aEb',
ToBytes( "bFb" ), 'bFb',
ToBytes( "GBa" ), 'GBa',
ToBytes( "aCa" ) ] 'aCa' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
eq_( line_offset, 2 ) eq_( line_offset, 2 )
eq_( char_offset, 0 ) eq_( char_offset, 0 )
def ReplaceChunk_SingleToMultipleLines3_test(): def ReplaceChunk_SingleToMultipleLines3_test():
result_buffer = [ ToBytes( "aAa" ), ToBytes( "aBa" ), ToBytes( "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,
@ -346,18 +357,18 @@ def ReplaceChunk_SingleToMultipleLines3_test():
0, 0,
0, 0,
result_buffer ) result_buffer )
expected_buffer = [ ToBytes( "aAa" ), expected_buffer = [ 'aAa',
ToBytes( "aEb" ), 'aEb',
ToBytes( "bFb" ), 'bFb',
ToBytes( "bGbBa" ), 'bGbBa',
ToBytes( "aCa" ) ] 'aCa' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( 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 = [ ToBytes( "aAa" ), ToBytes( "aBa" ), ToBytes( "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,
@ -365,20 +376,20 @@ def ReplaceChunk_SingleToMultipleLinesReplace_test():
0, 0,
0, 0,
result_buffer ) result_buffer )
expected_buffer = [ ToBytes( "aEb" ), expected_buffer = [ 'aEb',
ToBytes( "bFb" ), 'bFb',
ToBytes( "bGb" ), 'bGb',
ToBytes( "aBa" ), 'aBa',
ToBytes( "aCa" ) ] 'aCa' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( 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 = [ ToBytes( "aAa" ), result_buffer = [ 'aAa',
ToBytes( "aBa" ), 'aBa',
ToBytes( "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,
@ -386,12 +397,12 @@ def ReplaceChunk_SingleToMultipleLinesReplace_2_test():
0, 0,
0, 0,
result_buffer ) result_buffer )
expected_buffer = [ ToBytes( "aEb" ), expected_buffer = [ 'aEb',
ToBytes( "bFb" ), 'bFb',
ToBytes( "bGb" ), 'bGb',
ToBytes( "aBa" ), 'aBa',
ToBytes( "aCa" ) ] 'aCa' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
eq_( line_offset, 2 ) eq_( line_offset, 2 )
eq_( char_offset, 0 ) eq_( char_offset, 0 )
@ -408,23 +419,23 @@ def ReplaceChunk_SingleToMultipleLinesReplace_2_test():
line_offset += new_line_offset line_offset += new_line_offset
char_offset += new_char_offset char_offset += new_char_offset
eq_( [ ToBytes( "aEb" ), AssertBuffersAreEqualAsBytes( [ 'aEb',
ToBytes( "bFb" ), 'bFb',
ToBytes( "bGbcccc" ), 'bGbcccc',
ToBytes( "aBa" ), 'aBa',
ToBytes( "aCa" ) ], result_buffer ) 'aCa' ], result_buffer )
eq_( line_offset, 2 ) eq_( line_offset, 2 )
eq_( char_offset, 4 ) eq_( char_offset, 4 )
def ReplaceChunk_MultipleLinesToSingleLine_test(): def ReplaceChunk_MultipleLinesToSingleLine_test():
result_buffer = [ ToBytes( "aAa" ), ToBytes( "aBa" ), ToBytes( "aCaaaa" ) ] result_buffer = [ 'aAa', 'aBa', 'aCaaaa' ]
start, end = _BuildLocations( 2, 2, 3, 2 ) start, end = _BuildLocations( 2, 2, 3, 2 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'E', ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'E',
0, 0, result_buffer ) 0, 0, result_buffer )
expected_buffer = [ ToBytes( "aAa" ), ToBytes( "aECaaaa" ) ] expected_buffer = [ 'aAa', 'aECaaaa' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
eq_( line_offset, -1 ) eq_( line_offset, -1 )
eq_( char_offset, 1 ) eq_( char_offset, 1 )
@ -441,8 +452,8 @@ 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_( [ ToBytes( "aAa" ), AssertBuffersAreEqualAsBytes( [ 'aAa',
ToBytes( "aECccccaaa" ) ], result_buffer ) 'aECccccaaa' ], result_buffer )
eq_( line_offset, -1 ) eq_( line_offset, -1 )
eq_( char_offset, 4 ) eq_( char_offset, 4 )
@ -459,36 +470,35 @@ 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_( [ ToBytes( "aAa" ), AssertBuffersAreEqualAsBytes( [ 'aAa',
ToBytes( "aECccccdd" ), 'aECccccdd',
ToBytes( "ddaa" ) ], 'ddaa' ], result_buffer )
result_buffer )
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, -2 ) eq_( char_offset, -2 )
def ReplaceChunk_MultipleLinesToSameMultipleLines_test(): def ReplaceChunk_MultipleLinesToSameMultipleLines_test():
result_buffer = [ ToBytes( "aAa" ), result_buffer = [ 'aAa',
ToBytes( "aBa" ), 'aBa',
ToBytes( "aCa" ), 'aCa',
ToBytes( "aDe" ) ] 'aDe' ]
start, end = _BuildLocations( 2, 2, 3, 2 ) start, end = _BuildLocations( 2, 2, 3, 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 = [ ToBytes( "aAa" ), expected_buffer = [ 'aAa',
ToBytes( "aEb" ), 'aEb',
ToBytes( "bFCa" ), 'bFCa',
ToBytes( "aDe" ) ] 'aDe' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, 1 ) eq_( char_offset, 1 )
def ReplaceChunk_MultipleLinesToMoreMultipleLines_test(): def ReplaceChunk_MultipleLinesToMoreMultipleLines_test():
result_buffer = [ ToBytes( "aAa" ), result_buffer = [ 'aAa',
ToBytes( "aBa" ), 'aBa',
ToBytes( "aCa" ), 'aCa',
ToBytes( "aDe" ) ] '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,
@ -496,153 +506,153 @@ def ReplaceChunk_MultipleLinesToMoreMultipleLines_test():
0, 0,
0, 0,
result_buffer ) result_buffer )
expected_buffer = [ ToBytes( "aAa" ), expected_buffer = [ 'aAa',
ToBytes( "aEb" ), 'aEb',
ToBytes( "bFb" ), 'bFb',
ToBytes( "bGCa" ), 'bGCa',
ToBytes( "aDe" ) ] 'aDe' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
eq_( line_offset, 1 ) eq_( line_offset, 1 )
eq_( char_offset, 1 ) eq_( char_offset, 1 )
def ReplaceChunk_MultipleLinesToLessMultipleLines_test(): def ReplaceChunk_MultipleLinesToLessMultipleLines_test():
result_buffer = [ ToBytes( "aAa" ), result_buffer = [ 'aAa',
ToBytes( "aBa" ), 'aBa',
ToBytes( "aCa" ), 'aCa',
ToBytes( "aDe" ) ] 'aDe' ]
start, end = _BuildLocations( 1, 2, 3, 2 ) start, end = _BuildLocations( 1, 2, 3, 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 = [ ToBytes( "aEb" ), ToBytes( "bFCa" ), ToBytes( "aDe" ) ] expected_buffer = [ 'aEb', 'bFCa', 'aDe' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
eq_( line_offset, -1 ) eq_( line_offset, -1 )
eq_( char_offset, 1 ) eq_( char_offset, 1 )
def ReplaceChunk_MultipleLinesToEvenLessMultipleLines_test(): def ReplaceChunk_MultipleLinesToEvenLessMultipleLines_test():
result_buffer = [ ToBytes( "aAa" ), result_buffer = [ 'aAa',
ToBytes( "aBa" ), 'aBa',
ToBytes( "aCa" ), 'aCa',
ToBytes( "aDe" ) ] 'aDe' ]
start, end = _BuildLocations( 1, 2, 4, 2 ) start, end = _BuildLocations( 1, 2, 4, 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 = [ ToBytes( "aEb" ), ToBytes( "bFDe" ) ] expected_buffer = [ 'aEb', 'bFDe' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
eq_( line_offset, -2 ) eq_( line_offset, -2 )
eq_( char_offset, 1 ) eq_( char_offset, 1 )
def ReplaceChunk_SpanBufferEdge_test(): def ReplaceChunk_SpanBufferEdge_test():
result_buffer = [ ToBytes( "aAa" ), result_buffer = [ 'aAa',
ToBytes( "aBa" ), 'aBa',
ToBytes( "aCa" ) ] 'aCa' ]
start, end = _BuildLocations( 1, 1, 1, 3 ) start, end = _BuildLocations( 1, 1, 1, 3 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'bDb', ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'bDb',
0, 0, result_buffer ) 0, 0, result_buffer )
expected_buffer = [ ToBytes( "bDba" ), expected_buffer = [ 'bDba',
ToBytes( "aBa" ), 'aBa',
ToBytes( "aCa" ) ] 'aCa' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, 1 ) eq_( char_offset, 1 )
def ReplaceChunk_DeleteTextInLine_test(): def ReplaceChunk_DeleteTextInLine_test():
result_buffer = [ ToBytes( "aAa" ), result_buffer = [ 'aAa',
ToBytes( "aBa" ), 'aBa',
ToBytes( "aCa" ) ] 'aCa' ]
start, end = _BuildLocations( 2, 2, 2, 3 ) start, end = _BuildLocations( 2, 2, 2, 3 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, '', ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, '',
0, 0, result_buffer ) 0, 0, result_buffer )
expected_buffer = [ ToBytes( "aAa" ), expected_buffer = [ 'aAa',
ToBytes( "aa" ), 'aa',
ToBytes( "aCa" ) ] 'aCa' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, -1 ) eq_( char_offset, -1 )
def ReplaceChunk_AddTextInLine_test(): def ReplaceChunk_AddTextInLine_test():
result_buffer = [ ToBytes( "aAa" ), result_buffer = [ 'aAa',
ToBytes( "aBa" ), 'aBa',
ToBytes( "aCa" ) ] 'aCa' ]
start, end = _BuildLocations( 2, 2, 2, 2 ) start, end = _BuildLocations( 2, 2, 2, 2 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'bDb', ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'bDb',
0, 0, result_buffer ) 0, 0, result_buffer )
expected_buffer = [ ToBytes( "aAa" ), expected_buffer = [ 'aAa',
ToBytes( "abDbBa" ), 'abDbBa',
ToBytes( "aCa" ) ] 'aCa' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, 3 ) eq_( char_offset, 3 )
def ReplaceChunk_ReplaceTextInLine_test(): def ReplaceChunk_ReplaceTextInLine_test():
result_buffer = [ ToBytes( "aAa" ), result_buffer = [ 'aAa',
ToBytes( "aBa" ), 'aBa',
ToBytes( "aCa" ) ] 'aCa' ]
start, end = _BuildLocations( 2, 2, 2, 3 ) start, end = _BuildLocations( 2, 2, 2, 3 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'bDb', ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'bDb',
0, 0, result_buffer ) 0, 0, result_buffer )
expected_buffer = [ ToBytes( "aAa" ), expected_buffer = [ 'aAa',
ToBytes( "abDba" ), 'abDba',
ToBytes( "aCa" ) ] 'aCa' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, 2 ) eq_( char_offset, 2 )
def ReplaceChunk_SingleLineOffsetWorks_test(): def ReplaceChunk_SingleLineOffsetWorks_test():
result_buffer = [ ToBytes( "aAa" ), result_buffer = [ 'aAa',
ToBytes( "aBa" ), 'aBa',
ToBytes( "aCa" ) ] 'aCa' ]
start, end = _BuildLocations( 1, 1, 1, 2 ) start, end = _BuildLocations( 1, 1, 1, 2 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'bDb', ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'bDb',
1, 1, result_buffer ) 1, 1, result_buffer )
expected_buffer = [ ToBytes( "aAa" ), expected_buffer = [ 'aAa',
ToBytes( "abDba" ), 'abDba',
ToBytes( "aCa" ) ] 'aCa' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
eq_( line_offset, 0 ) eq_( line_offset, 0 )
eq_( char_offset, 2 ) eq_( char_offset, 2 )
def ReplaceChunk_SingleLineToMultipleLinesOffsetWorks_test(): def ReplaceChunk_SingleLineToMultipleLinesOffsetWorks_test():
result_buffer = [ ToBytes( "aAa" ), result_buffer = [ 'aAa',
ToBytes( "aBa" ), 'aBa',
ToBytes( "aCa" ) ] 'aCa' ]
start, end = _BuildLocations( 1, 1, 1, 2 ) start, end = _BuildLocations( 1, 1, 1, 2 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'Db\nE', ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'Db\nE',
1, 1, result_buffer ) 1, 1, result_buffer )
expected_buffer = [ ToBytes( "aAa" ), expected_buffer = [ 'aAa',
ToBytes( "aDb" ), 'aDb',
ToBytes( "Ea" ), 'Ea',
ToBytes( "aCa" ) ] 'aCa' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
eq_( line_offset, 1 ) eq_( line_offset, 1 )
eq_( char_offset, -1 ) eq_( char_offset, -1 )
def ReplaceChunk_MultipleLinesToSingleLineOffsetWorks_test(): def ReplaceChunk_MultipleLinesToSingleLineOffsetWorks_test():
result_buffer = [ ToBytes( "aAa" ), result_buffer = [ 'aAa',
ToBytes( "aBa" ), 'aBa',
ToBytes( "aCa" ) ] 'aCa' ]
start, end = _BuildLocations( 1, 1, 2, 2 ) start, end = _BuildLocations( 1, 1, 2, 2 )
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'bDb', ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'bDb',
1, 1, result_buffer ) 1, 1, result_buffer )
expected_buffer = [ ToBytes( "aAa" ), expected_buffer = [ 'aAa',
ToBytes( "abDbCa" ) ] 'abDbCa' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
eq_( line_offset, -1 ) eq_( line_offset, -1 )
eq_( char_offset, 3 ) eq_( char_offset, 3 )
def ReplaceChunk_MultipleLineOffsetWorks_test(): def ReplaceChunk_MultipleLineOffsetWorks_test():
result_buffer = [ ToBytes( "aAa" ), result_buffer = [ 'aAa',
ToBytes( "aBa" ), 'aBa',
ToBytes( "aCa" ) ] '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,
@ -650,11 +660,11 @@ def ReplaceChunk_MultipleLineOffsetWorks_test():
-1, -1,
1, 1,
result_buffer ) result_buffer )
expected_buffer = [ ToBytes( "aAa" ), expected_buffer = [ 'aAa',
ToBytes( "abDb" ), 'abDb',
ToBytes( "bEb" ), 'bEb',
ToBytes( "bFba" ) ] 'bFba' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
eq_( line_offset, 1 ) eq_( line_offset, 1 )
eq_( char_offset, 1 ) eq_( char_offset, 1 )
@ -675,11 +685,11 @@ def ReplaceChunksInBuffer_SortedChunks_test():
_BuildChunk( 1, 11, 1, 11, ')' ) _BuildChunk( 1, 11, 1, 11, ')' )
] ]
result_buffer = [ ToBytes( "CT<10 >> 2> ct" ) ] result_buffer = [ 'CT<10 >> 2> ct' ]
vimsupport.ReplaceChunksInBuffer( chunks, result_buffer, None ) vimsupport.ReplaceChunksInBuffer( chunks, result_buffer, None )
expected_buffer = [ ToBytes( "CT<(10 >> 2)> ct" ) ] expected_buffer = [ 'CT<(10 >> 2)> ct' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
def ReplaceChunksInBuffer_UnsortedChunks_test(): def ReplaceChunksInBuffer_UnsortedChunks_test():
@ -688,11 +698,11 @@ def ReplaceChunksInBuffer_UnsortedChunks_test():
_BuildChunk( 1, 4, 1, 4, '(' ) _BuildChunk( 1, 4, 1, 4, '(' )
] ]
result_buffer = [ ToBytes( "CT<10 >> 2> ct" ) ] result_buffer = [ 'CT<10 >> 2> ct' ]
vimsupport.ReplaceChunksInBuffer( chunks, result_buffer, None ) vimsupport.ReplaceChunksInBuffer( chunks, result_buffer, None )
expected_buffer = [ ToBytes( "CT<(10 >> 2)> ct" ) ] expected_buffer = [ 'CT<(10 >> 2)> ct' ]
eq_( expected_buffer, result_buffer ) AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
class MockBuffer( object ): class MockBuffer( object ):
@ -700,7 +710,7 @@ class MockBuffer( object ):
generate a location list""" generate a location list"""
def __init__( self, lines, name, number ): def __init__( self, lines, name, number ):
self.lines = [ ToBytes( x ) for x in lines ] self.lines = lines
self.name = name self.name = name
self.number = number self.number = number