Skip to content

Commit

Permalink
Loosen grammar to allow for missing parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
lieryan authored and jonathanslenders committed Mar 6, 2020
1 parent 5e45d33 commit 44937c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyvim/commands/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
\s*
(
# Substitute command
((?P<range_start>\d+)(,(?P<range_end>\d+))?)? (?P<command>s|substitute) \s* / (?P<search>[^/]*) / (?P<replace>[^/]*) (?P<flags> /(g)? )? |
((?P<range_start>\d+)(,(?P<range_end>\d+))?)? (?P<command>s|substitute) \s* / (?P<search>[^/]*) ( / (?P<replace>[^/]*) (?P<flags> /(g)? )? )? |
# Commands accepting a location.
(?P<command>%(commands_taking_locations)s)(?P<force>!?) \s+ (?P<location>[^\s]+) |
Expand Down
17 changes: 16 additions & 1 deletion tests/test_substitute.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_substitute_from_search_history(editor, editor_buffer):


def test_substitute_from_substitute_search_history(editor, editor_buffer):
given_sample_text(editor_buffer, 'Violet is Violet')
given_sample_text(editor_buffer, 'Violet is Violet\n')

handle_command(editor, ':s/Violet/Rose')
assert 'Rose is Violet' in editor_buffer.buffer.text
Expand All @@ -100,6 +100,20 @@ def test_substitute_with_repeat_last_substitution(editor, editor_buffer):
assert 'Rose is Rose' in editor_buffer.buffer.text


def test_substitute_without_replacement_text(editor, editor_buffer):
given_sample_text(editor_buffer, 'Violet Violet Violet \n')
editor.application.current_search_state.text = 'Lily'

handle_command(editor, ':s/Violet/')
assert ' Violet Violet \n' in editor_buffer.buffer.text

handle_command(editor, ':s/Violet')
assert ' Violet \n' in editor_buffer.buffer.text

handle_command(editor, ':s/')
assert ' \n' in editor_buffer.buffer.text


def test_substitute_with_repeat_last_substitution_without_previous_substitution(editor, editor_buffer):
original_text = 'Violet is blue\n'
given_sample_text(editor_buffer, original_text)
Expand All @@ -118,6 +132,7 @@ def test_substitute_flags_empty_flags(editor, editor_buffer):
handle_command(editor, ':s/Violet/Rose/')
assert 'Rose is Violet' in editor_buffer.buffer.text


def test_substitute_flags_g(editor, editor_buffer):
given_sample_text(editor_buffer, 'Violet is Violet\n')
handle_command(editor, ':s/Violet/Rose/g')
Expand Down

0 comments on commit 44937c5

Please sign in to comment.