Skip to content

Commit 44937c5

Browse files
lieryanjonathanslenders
authored andcommitted
Loosen grammar to allow for missing parentheses
1 parent 5e45d33 commit 44937c5

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

pyvim/commands/grammar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
\s*
1313
(
1414
# Substitute command
15-
((?P<range_start>\d+)(,(?P<range_end>\d+))?)? (?P<command>s|substitute) \s* / (?P<search>[^/]*) / (?P<replace>[^/]*) (?P<flags> /(g)? )? |
15+
((?P<range_start>\d+)(,(?P<range_end>\d+))?)? (?P<command>s|substitute) \s* / (?P<search>[^/]*) ( / (?P<replace>[^/]*) (?P<flags> /(g)? )? )? |
1616
1717
# Commands accepting a location.
1818
(?P<command>%(commands_taking_locations)s)(?P<force>!?) \s+ (?P<location>[^\s]+) |

tests/test_substitute.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_substitute_from_search_history(editor, editor_buffer):
8080

8181

8282
def test_substitute_from_substitute_search_history(editor, editor_buffer):
83-
given_sample_text(editor_buffer, 'Violet is Violet')
83+
given_sample_text(editor_buffer, 'Violet is Violet\n')
8484

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

102102

103+
def test_substitute_without_replacement_text(editor, editor_buffer):
104+
given_sample_text(editor_buffer, 'Violet Violet Violet \n')
105+
editor.application.current_search_state.text = 'Lily'
106+
107+
handle_command(editor, ':s/Violet/')
108+
assert ' Violet Violet \n' in editor_buffer.buffer.text
109+
110+
handle_command(editor, ':s/Violet')
111+
assert ' Violet \n' in editor_buffer.buffer.text
112+
113+
handle_command(editor, ':s/')
114+
assert ' \n' in editor_buffer.buffer.text
115+
116+
103117
def test_substitute_with_repeat_last_substitution_without_previous_substitution(editor, editor_buffer):
104118
original_text = 'Violet is blue\n'
105119
given_sample_text(editor_buffer, original_text)
@@ -118,6 +132,7 @@ def test_substitute_flags_empty_flags(editor, editor_buffer):
118132
handle_command(editor, ':s/Violet/Rose/')
119133
assert 'Rose is Violet' in editor_buffer.buffer.text
120134

135+
121136
def test_substitute_flags_g(editor, editor_buffer):
122137
given_sample_text(editor_buffer, 'Violet is Violet\n')
123138
handle_command(editor, ':s/Violet/Rose/g')

0 commit comments

Comments
 (0)