Skip to content

Commit

Permalink
Add test for regex (review suggestion)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrclary committed Feb 9, 2023
1 parent 2dd196e commit cea807c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions spyder/widgets/tests/test_findreplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ def test_replace_all(findreplace_editor, qtbot):
editor = findreplace_editor.editor
findreplace = findreplace_editor.findreplace
findreplace.show_replace()

findreplace.search_text.setCurrentText('a')
findreplace.replace_text.setCurrentText('x')

# Replace all
editor.set_text('a\naa')
expected = 'x\u2029xx' # Note: \n is replaced with \u2029
qtbot.wait(500)
Expand All @@ -118,12 +120,28 @@ def test_replace_all(findreplace_editor, qtbot):
assert editor.get_text('sof', 'eof') == expected
assert len(editor.get_text('sof', 'eof')) == len(expected)

# Replace all with whole word matching
editor.set_text('a\naa')
expected = 'x\u2029aa' # Note: \n is replaced with \u2029
qtbot.wait(500)
qtbot.mouseClick(findreplace.words_button, Qt.LeftButton)
findreplace.replace_find_all()
qtbot.wait(500)
qtbot.mouseClick(findreplace.words_button, Qt.LeftButton)
assert editor.get_text('sof', 'eof') == expected
assert len(editor.get_text('sof', 'eof')) == len(expected)

findreplace.search_text.setCurrentText(r'a(\d+)a')
findreplace.replace_text.setCurrentText(r'b\1b')

# Replace all with regex
editor.set_text('a123a\nabca')
expected = 'b123b\u2029abca' # Note: \n is replaced with \u2029
qtbot.wait(500)
qtbot.mouseClick(findreplace.re_button, Qt.LeftButton)
findreplace.replace_find_all()
qtbot.wait(500)
qtbot.mouseClick(findreplace.re_button, Qt.LeftButton)
assert editor.get_text('sof', 'eof') == expected
assert len(editor.get_text('sof', 'eof')) == len(expected)

Expand Down

0 comments on commit cea807c

Please sign in to comment.