30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
from PySide6.QtGui import QTextCursor
|
|
from PySide6.QtWidgets import QPlainTextEdit, QLineEdit, QCheckBox, QLabel
|
|
|
|
from mdhelper.editor_find import EditorFindController
|
|
|
|
|
|
def test_find_replace_keeps_unicode_word_boundaries_and_undo(qt_application):
|
|
editor = QPlainTextEdit()
|
|
original = "🙂 alpha ALPHA alphabet\nalpha"
|
|
editor.setPlainText(original)
|
|
editor.moveCursor(QTextCursor.MoveOperation.End)
|
|
editor.insertPlainText(" extra")
|
|
query, replacement = QLineEdit("alpha"), QLineEdit("猫😀")
|
|
match_case, whole_word, status = QCheckBox(), QCheckBox(), QLabel()
|
|
whole_word.setChecked(True)
|
|
finder = EditorFindController(editor, query, replacement, match_case, whole_word, status)
|
|
editor.textChanged.connect(finder._rebuild_find_matches)
|
|
finder._rebuild_find_matches()
|
|
finder.find_next_in_editor()
|
|
assert editor.textCursor().selectedText() == "alpha"
|
|
assert status.text() == "1/3"
|
|
finder.replace_all_in_editor()
|
|
assert editor.toPlainText() == "🙂 猫😀 猫😀 alphabet\n猫😀 extra"
|
|
assert status.text() == "0/0"
|
|
editor.undo()
|
|
assert editor.toPlainText() == original + " extra"
|
|
editor.undo()
|
|
assert editor.toPlainText() == original
|
|
|