From 862be133495179ea226421bcab1b34a335503eaa Mon Sep 17 00:00:00 2001 From: Lie Ryan Date: Sun, 1 Mar 2020 21:57:01 +1100 Subject: [PATCH] Add test for range specification's boundary condition --- pyvim/commands/commands.py | 4 +--- tests/test_substitute.py | 8 ++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pyvim/commands/commands.py b/pyvim/commands/commands.py index c54174a..7cadb55 100644 --- a/pyvim/commands/commands.py +++ b/pyvim/commands/commands.py @@ -716,9 +716,7 @@ def get_line_index_iterator(cursor_position_row, range_start, range_end): range_start = range_end = cursor_position_row else: range_start = int(range_start) - 1 - if not range_end: - range_end = range_start - range_end = int(range_end) + range_end = int(range_end) - 1 if range_end else range_start return range(range_start, range_end + 1) def get_transform_callback(search, replace, flags): diff --git a/tests/test_substitute.py b/tests/test_substitute.py index 0356e01..e0b72c9 100644 --- a/tests/test_substitute.py +++ b/tests/test_substitute.py @@ -59,6 +59,14 @@ def test_substitute_range(editor, editor_buffer): # == editor_buffer.buffer.text.index('Violet') +def test_substitute_range_boundaries(editor, editor_buffer): + given_sample_text(editor_buffer, 'Violet\n' * 4) + + handle_command(editor, ':2,3s/Violet/Rose') + + assert 'Violet\nRose\nRose\nViolet\n' in editor_buffer.buffer.text + + def test_substitute_from_search_history(editor, editor_buffer): given_sample_text(editor_buffer) editor.application.current_search_state.text = 'blue'