From 58eda950f82f6c8ef56cb8fabe9d785d707da762 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sat, 5 Jul 2025 17:52:19 +0200 Subject: [PATCH] Add test coverage for spell checker with 4 byte Unicode --- novelwriter/gui/doceditor.py | 5 ----- tests/test_gui/test_gui_doceditor.py | 17 +++++++++-------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index 7af87ac9..99a14ec2 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -2303,8 +2303,6 @@ class TextAutoReplace: cursor.movePosition(QtMoveLeft, QtKeepAnchor, min(4, pos)) last = cursor.selectedText() delete, insert = self._determine(last, pos) - if insert == "": - return False check = insert if self._doPadBefore and check in self._padBefore: @@ -2335,9 +2333,6 @@ class TextAutoReplace: t2 = text[-2:] t3 = text[-3:] t4 = text[-4:] - if t1 == "": - # Return early if there is nothing to check - return 0, "" leading = t2[:1].isspace() if self._replaceDQuote: diff --git a/tests/test_gui/test_gui_doceditor.py b/tests/test_gui/test_gui_doceditor.py index 699bbaaa..6480df93 100644 --- a/tests/test_gui/test_gui_doceditor.py +++ b/tests/test_gui/test_gui_doceditor.py @@ -514,6 +514,7 @@ def testGuiEditor_SpellChecking(qtbot, monkeypatch, nwGUI, projPath, ipsumText, # Run SpellCheck # ============== SHARED.project.data.setSpellCheck(True) + LORAX = "Lorax\U0001F03A" cursor = docEditor.textCursor() cursor.setPosition(16) @@ -527,21 +528,21 @@ def testGuiEditor_SpellChecking(qtbot, monkeypatch, nwGUI, projPath, ipsumText, # With Suggestion with monkeypatch.context() as mp: - mp.setattr(SHARED.spelling, "suggestWords", lambda *a: ["Lorax"]) + mp.setattr(SHARED.spelling, "suggestWords", lambda *a: [LORAX]) ctxMenu = getMenuForPos(docEditor, 16) assert ctxMenu is not None actions = [x.text() for x in ctxMenu.actions() if x.text()] assert "Spelling Suggestion(s)" in actions - assert f"{nwUnicode.U_ENDASH} Lorax" in actions + assert f"{nwUnicode.U_ENDASH} {LORAX}" in actions ctxMenu.actions()[7].trigger() QApplication.processEvents() - assert docEditor.getText() == text.replace("Lorem", "Lorax", 1) + assert docEditor.getText() == text.replace("Lorem", LORAX, 1) ctxMenu.setObjectName("") ctxMenu.deleteLater() # Update Entry - data._spellErrors = [(0, 5, "Lorax")] + data._spellErrors = [(0, 7, LORAX)] # Without Suggestion with monkeypatch.context() as mp: @@ -551,7 +552,7 @@ def testGuiEditor_SpellChecking(qtbot, monkeypatch, nwGUI, projPath, ipsumText, assert ctxMenu is not None actions = [x.text() for x in ctxMenu.actions() if x.text()] assert f"{nwUnicode.U_ENDASH} No Suggestions" in actions - assert docEditor.getText() == text.replace("Lorem", "Lorax", 1) + assert docEditor.getText() == text.replace("Lorem", LORAX, 1) ctxMenu.setObjectName("") ctxMenu.deleteLater() @@ -565,11 +566,11 @@ def testGuiEditor_SpellChecking(qtbot, monkeypatch, nwGUI, projPath, ipsumText, assert "Ignore Word" in actions assert "Add Word to Dictionary" in actions - assert "Lorax" not in SHARED.spelling._userDict + assert LORAX not in SHARED.spelling._userDict ctxMenu.actions()[7].trigger() # Ignore - assert "Lorax" not in SHARED.spelling._userDict + assert LORAX not in SHARED.spelling._userDict ctxMenu.actions()[8].trigger() # Add - assert "Lorax" in SHARED.spelling._userDict + assert LORAX in SHARED.spelling._userDict ctxMenu.setObjectName("") ctxMenu.deleteLater()