Skip to content

Commit a090d5f

Browse files
lieryanjonathanslenders
authored andcommitted
Add test for :s's 'g' flag and fix empty flags case
1 parent 8825d81 commit a090d5f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
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: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
And so are you.
88
""".lstrip()
99

10-
def given_sample_text(editor_buffer):
10+
def given_sample_text(editor_buffer, text=None):
1111
editor = editor_buffer.editor
1212
editor.window_arrangement._add_editor_buffer(editor_buffer)
13-
editor_buffer.buffer.text = sample_text
13+
editor_buffer.buffer.text = text or sample_text
1414
editor.sync_with_prompt_toolkit()
1515

1616

@@ -65,3 +65,14 @@ def test_substitute_from_search_history(editor, editor_buffer):
6565

6666
handle_command(editor, ':1,3s//pretty')
6767
assert 'Violets are pretty,' in editor_buffer.buffer.text
68+
69+
70+
def test_substitute_flags_empty_flags(editor, editor_buffer):
71+
given_sample_text(editor_buffer, 'Violet is Violet\n')
72+
handle_command(editor, ':s/Violet/Rose/')
73+
assert 'Rose is Violet' in editor_buffer.buffer.text
74+
75+
def test_substitute_flags_g(editor, editor_buffer):
76+
given_sample_text(editor_buffer, 'Rose is Violet\n')
77+
handle_command(editor, ':s/Violet/Rose/g')
78+
assert 'Rose is Rose' in editor_buffer.buffer.text

0 commit comments

Comments
 (0)