Add test coverage for spell checker with 4 byte Unicode

This commit is contained in:
Veronica Berglyd Olsen
2025-07-05 17:52:19 +02:00
parent ad3760762f
commit 58eda950f8
2 changed files with 9 additions and 13 deletions
-5
View File
@@ -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:
+9 -8
View File
@@ -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()