Add test coverage for spell checker with 4 byte Unicode
This commit is contained in:
@@ -2303,8 +2303,6 @@ class TextAutoReplace:
|
|||||||
cursor.movePosition(QtMoveLeft, QtKeepAnchor, min(4, pos))
|
cursor.movePosition(QtMoveLeft, QtKeepAnchor, min(4, pos))
|
||||||
last = cursor.selectedText()
|
last = cursor.selectedText()
|
||||||
delete, insert = self._determine(last, pos)
|
delete, insert = self._determine(last, pos)
|
||||||
if insert == "":
|
|
||||||
return False
|
|
||||||
|
|
||||||
check = insert
|
check = insert
|
||||||
if self._doPadBefore and check in self._padBefore:
|
if self._doPadBefore and check in self._padBefore:
|
||||||
@@ -2335,9 +2333,6 @@ class TextAutoReplace:
|
|||||||
t2 = text[-2:]
|
t2 = text[-2:]
|
||||||
t3 = text[-3:]
|
t3 = text[-3:]
|
||||||
t4 = text[-4:]
|
t4 = text[-4:]
|
||||||
if t1 == "":
|
|
||||||
# Return early if there is nothing to check
|
|
||||||
return 0, ""
|
|
||||||
|
|
||||||
leading = t2[:1].isspace()
|
leading = t2[:1].isspace()
|
||||||
if self._replaceDQuote:
|
if self._replaceDQuote:
|
||||||
|
|||||||
@@ -514,6 +514,7 @@ def testGuiEditor_SpellChecking(qtbot, monkeypatch, nwGUI, projPath, ipsumText,
|
|||||||
# Run SpellCheck
|
# Run SpellCheck
|
||||||
# ==============
|
# ==============
|
||||||
SHARED.project.data.setSpellCheck(True)
|
SHARED.project.data.setSpellCheck(True)
|
||||||
|
LORAX = "Lorax\U0001F03A"
|
||||||
|
|
||||||
cursor = docEditor.textCursor()
|
cursor = docEditor.textCursor()
|
||||||
cursor.setPosition(16)
|
cursor.setPosition(16)
|
||||||
@@ -527,21 +528,21 @@ def testGuiEditor_SpellChecking(qtbot, monkeypatch, nwGUI, projPath, ipsumText,
|
|||||||
|
|
||||||
# With Suggestion
|
# With Suggestion
|
||||||
with monkeypatch.context() as mp:
|
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)
|
ctxMenu = getMenuForPos(docEditor, 16)
|
||||||
assert ctxMenu is not None
|
assert ctxMenu is not None
|
||||||
actions = [x.text() for x in ctxMenu.actions() if x.text()]
|
actions = [x.text() for x in ctxMenu.actions() if x.text()]
|
||||||
assert "Spelling Suggestion(s)" in actions
|
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()
|
ctxMenu.actions()[7].trigger()
|
||||||
QApplication.processEvents()
|
QApplication.processEvents()
|
||||||
assert docEditor.getText() == text.replace("Lorem", "Lorax", 1)
|
assert docEditor.getText() == text.replace("Lorem", LORAX, 1)
|
||||||
ctxMenu.setObjectName("")
|
ctxMenu.setObjectName("")
|
||||||
ctxMenu.deleteLater()
|
ctxMenu.deleteLater()
|
||||||
|
|
||||||
# Update Entry
|
# Update Entry
|
||||||
data._spellErrors = [(0, 5, "Lorax")]
|
data._spellErrors = [(0, 7, LORAX)]
|
||||||
|
|
||||||
# Without Suggestion
|
# Without Suggestion
|
||||||
with monkeypatch.context() as mp:
|
with monkeypatch.context() as mp:
|
||||||
@@ -551,7 +552,7 @@ def testGuiEditor_SpellChecking(qtbot, monkeypatch, nwGUI, projPath, ipsumText,
|
|||||||
assert ctxMenu is not None
|
assert ctxMenu is not None
|
||||||
actions = [x.text() for x in ctxMenu.actions() if x.text()]
|
actions = [x.text() for x in ctxMenu.actions() if x.text()]
|
||||||
assert f"{nwUnicode.U_ENDASH} No Suggestions" in actions
|
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.setObjectName("")
|
||||||
ctxMenu.deleteLater()
|
ctxMenu.deleteLater()
|
||||||
|
|
||||||
@@ -565,11 +566,11 @@ def testGuiEditor_SpellChecking(qtbot, monkeypatch, nwGUI, projPath, ipsumText,
|
|||||||
assert "Ignore Word" in actions
|
assert "Ignore Word" in actions
|
||||||
assert "Add Word to Dictionary" 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
|
ctxMenu.actions()[7].trigger() # Ignore
|
||||||
assert "Lorax" not in SHARED.spelling._userDict
|
assert LORAX not in SHARED.spelling._userDict
|
||||||
ctxMenu.actions()[8].trigger() # Add
|
ctxMenu.actions()[8].trigger() # Add
|
||||||
assert "Lorax" in SHARED.spelling._userDict
|
assert LORAX in SHARED.spelling._userDict
|
||||||
ctxMenu.setObjectName("")
|
ctxMenu.setObjectName("")
|
||||||
ctxMenu.deleteLater()
|
ctxMenu.deleteLater()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user