Fix quotes regex issue and update tests
This commit is contained in:
@@ -91,11 +91,11 @@ class RegExPatterns:
|
|||||||
if CONFIG.dialogStyle in (1, 3):
|
if CONFIG.dialogStyle in (1, 3):
|
||||||
qO = CONFIG.fmtSQuoteOpen.strip()[:1]
|
qO = CONFIG.fmtSQuoteOpen.strip()[:1]
|
||||||
qC = CONFIG.fmtSQuoteClose.strip()[:1]
|
qC = CONFIG.fmtSQuoteClose.strip()[:1]
|
||||||
rx.append(f"(\\B{qO}.*?(?:{qC}\\B{end}))")
|
rx.append(f"(?:\\B{qO}.*?(?:{qC}\\B{end}))")
|
||||||
if CONFIG.dialogStyle in (2, 3):
|
if CONFIG.dialogStyle in (2, 3):
|
||||||
qO = CONFIG.fmtDQuoteOpen.strip()[:1]
|
qO = CONFIG.fmtDQuoteOpen.strip()[:1]
|
||||||
qC = CONFIG.fmtDQuoteClose.strip()[:1]
|
qC = CONFIG.fmtDQuoteClose.strip()[:1]
|
||||||
rx.append(f"(\\B{qO}.*?(?:{qC}\\B{end}))")
|
rx.append(f"(?:\\B{qO}.*?(?:{qC}\\B{end}))")
|
||||||
return re.compile("|".join(rx), re.UNICODE)
|
return re.compile("|".join(rx), re.UNICODE)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[Meta]
|
[Meta]
|
||||||
timestamp = 2024-06-16 00:36:27
|
timestamp = 2024-11-03 21:45:08
|
||||||
|
|
||||||
[Main]
|
[Main]
|
||||||
font =
|
font =
|
||||||
@@ -59,10 +59,11 @@ incnoteswcount = True
|
|||||||
showfullpath = True
|
showfullpath = True
|
||||||
dialogstyle = 2
|
dialogstyle = 2
|
||||||
allowopendial = True
|
allowopendial = True
|
||||||
|
dialogline =
|
||||||
narratorbreak =
|
narratorbreak =
|
||||||
|
narratordialog =
|
||||||
altdialogopen =
|
altdialogopen =
|
||||||
altdialogclose =
|
altdialogclose =
|
||||||
dialogline =
|
|
||||||
highlightemph = True
|
highlightemph = True
|
||||||
stopwhenidle = True
|
stopwhenidle = True
|
||||||
useridletime = 300
|
useridletime = 300
|
||||||
|
|||||||
@@ -247,8 +247,9 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths):
|
|||||||
# Text Highlighting
|
# Text Highlighting
|
||||||
prefs.dialogStyle.setCurrentData(3, 0)
|
prefs.dialogStyle.setCurrentData(3, 0)
|
||||||
prefs.allowOpenDial.setChecked(False)
|
prefs.allowOpenDial.setChecked(False)
|
||||||
prefs.narratorBreak.setText("–")
|
|
||||||
prefs.dialogLine.setText("–")
|
prefs.dialogLine.setText("–")
|
||||||
|
prefs.narratorBreak.setText("–")
|
||||||
|
prefs.narratorDialog.setText("–")
|
||||||
prefs.altDialogOpen.setText("<")
|
prefs.altDialogOpen.setText("<")
|
||||||
prefs.altDialogClose.setText(">")
|
prefs.altDialogClose.setText(">")
|
||||||
prefs.highlightEmph.setChecked(False)
|
prefs.highlightEmph.setChecked(False)
|
||||||
@@ -256,8 +257,9 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths):
|
|||||||
|
|
||||||
assert CONFIG.dialogStyle == 2
|
assert CONFIG.dialogStyle == 2
|
||||||
assert CONFIG.allowOpenDial is True
|
assert CONFIG.allowOpenDial is True
|
||||||
assert CONFIG.narratorBreak == ""
|
|
||||||
assert CONFIG.dialogLine == ""
|
assert CONFIG.dialogLine == ""
|
||||||
|
assert CONFIG.narratorBreak == ""
|
||||||
|
assert CONFIG.narratorDialog == ""
|
||||||
assert CONFIG.altDialogOpen == ""
|
assert CONFIG.altDialogOpen == ""
|
||||||
assert CONFIG.altDialogClose == ""
|
assert CONFIG.altDialogClose == ""
|
||||||
assert CONFIG.highlightEmph is True
|
assert CONFIG.highlightEmph is True
|
||||||
@@ -366,8 +368,9 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths):
|
|||||||
# Text Highlighting
|
# Text Highlighting
|
||||||
assert CONFIG.dialogStyle == 3
|
assert CONFIG.dialogStyle == 3
|
||||||
assert CONFIG.allowOpenDial is False
|
assert CONFIG.allowOpenDial is False
|
||||||
assert CONFIG.narratorBreak == "–"
|
|
||||||
assert CONFIG.dialogLine == "–"
|
assert CONFIG.dialogLine == "–"
|
||||||
|
assert CONFIG.narratorBreak == "–"
|
||||||
|
assert CONFIG.narratorDialog == "–"
|
||||||
assert CONFIG.altDialogOpen == "<"
|
assert CONFIG.altDialogOpen == "<"
|
||||||
assert CONFIG.altDialogClose == ">"
|
assert CONFIG.altDialogClose == ">"
|
||||||
assert CONFIG.highlightEmph is False
|
assert CONFIG.highlightEmph is False
|
||||||
|
|||||||
@@ -296,6 +296,16 @@ def testTextPatterns_DialogueStyle():
|
|||||||
[("\u201ctwo\u201d", 4, 9)]
|
[("\u201ctwo\u201d", 4, 9)]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Both single and double quotes are recognised
|
||||||
|
assert allMatches(regEx, "one \u2018two\u2019 three \u201cfour\u201d five") == [
|
||||||
|
[("\u2018two\u2019", 4, 9)], [("\u201cfour\u201d", 16, 22)]
|
||||||
|
]
|
||||||
|
|
||||||
|
# But not mixed
|
||||||
|
assert allMatches(regEx, "one \u2018two\u201d three \u201cfour\u2019 five") == [
|
||||||
|
[("\u2018two\u201d three \u201cfour\u2019", 4, 22)]
|
||||||
|
]
|
||||||
|
|
||||||
# Straight single quotes are ignored
|
# Straight single quotes are ignored
|
||||||
assert allMatches(regEx, "one 'two' three") == []
|
assert allMatches(regEx, "one 'two' three") == []
|
||||||
|
|
||||||
@@ -363,6 +373,7 @@ def testTextPatterns_DialogParserEnglish():
|
|||||||
|
|
||||||
parser = DialogParser()
|
parser = DialogParser()
|
||||||
parser.initParser()
|
parser.initParser()
|
||||||
|
assert parser.enabled is True
|
||||||
|
|
||||||
# Positions: 0 18
|
# Positions: 0 18
|
||||||
assert parser("“Simple dialogue.”") == [
|
assert parser("“Simple dialogue.”") == [
|
||||||
@@ -384,9 +395,14 @@ def testTextPatterns_DialogParserEnglish():
|
|||||||
CONFIG.narratorBreak = nwUnicode.U_EMDASH
|
CONFIG.narratorBreak = nwUnicode.U_EMDASH
|
||||||
parser.initParser()
|
parser.initParser()
|
||||||
|
|
||||||
# Positions: 0 18 34 58
|
# Positions: 0 18 32 58
|
||||||
assert parser("“Simple dialogue, — argued John, — is not always so easy.”") == [
|
assert parser("“Simple dialogue, — argued John, — is not always so easy.”") == [
|
||||||
(0, 18), (34, 58),
|
(0, 18), (32, 58),
|
||||||
|
]
|
||||||
|
|
||||||
|
# Positions: 0 18 32 56
|
||||||
|
assert parser("“Simple dialogue, —argued John—, is not always so easy.”") == [
|
||||||
|
(0, 18), (32, 56),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -422,17 +438,15 @@ def testTextPatterns_DialogParserSpanish():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.core
|
@pytest.mark.core
|
||||||
def testTextPatterns_DialogParserAlternating():
|
def testTextPatterns_DialogParserPortuguese():
|
||||||
"""Test the dialog parser with alternating dialogue/narration like
|
"""Test the dialog parser with Portuguese settings."""
|
||||||
for Portuguese and Polish.
|
|
||||||
"""
|
|
||||||
# Set the config
|
# Set the config
|
||||||
CONFIG.dialogStyle = 0
|
CONFIG.dialogStyle = 0
|
||||||
CONFIG.fmtSQuoteOpen = nwUnicode.U_LSAQUO
|
CONFIG.fmtSQuoteOpen = nwUnicode.U_LSAQUO
|
||||||
CONFIG.fmtSQuoteClose = nwUnicode.U_RSAQUO
|
CONFIG.fmtSQuoteClose = nwUnicode.U_RSAQUO
|
||||||
CONFIG.fmtDQuoteOpen = nwUnicode.U_LAQUO
|
CONFIG.fmtDQuoteOpen = nwUnicode.U_LAQUO
|
||||||
CONFIG.fmtDQuoteClose = nwUnicode.U_RAQUO
|
CONFIG.fmtDQuoteClose = nwUnicode.U_RAQUO
|
||||||
CONFIG.dialogLine = ""
|
CONFIG.dialogLine = nwUnicode.U_EMDASH
|
||||||
CONFIG.narratorBreak = nwUnicode.U_EMDASH
|
CONFIG.narratorBreak = nwUnicode.U_EMDASH
|
||||||
|
|
||||||
parser = DialogParser()
|
parser = DialogParser()
|
||||||
@@ -448,7 +462,53 @@ def testTextPatterns_DialogParserAlternating():
|
|||||||
(0, 12),
|
(0, 12),
|
||||||
]
|
]
|
||||||
|
|
||||||
# Positions: 0 12 28 49
|
# Positions: 0 12 27 49
|
||||||
assert parser("— Tudo bem? — ele pergunta. — Você falou com ele?") == [
|
assert parser("— Tudo bem? — ele pergunta. — Você falou com ele?") == [
|
||||||
(0, 12), (28, 49),
|
(0, 12), (27, 49),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.core
|
||||||
|
def testTextPatterns_DialogParserPolish():
|
||||||
|
"""Test the dialog parser with alternating Polish settings."""
|
||||||
|
# Set the config
|
||||||
|
CONFIG.dialogStyle = 0
|
||||||
|
CONFIG.fmtSQuoteOpen = "'"
|
||||||
|
CONFIG.fmtSQuoteClose = "'"
|
||||||
|
CONFIG.fmtDQuoteOpen = '"'
|
||||||
|
CONFIG.fmtDQuoteClose = '"'
|
||||||
|
CONFIG.dialogLine = ""
|
||||||
|
CONFIG.narratorBreak = ""
|
||||||
|
CONFIG.narratorDialog = nwUnicode.U_ENDASH
|
||||||
|
|
||||||
|
parser = DialogParser()
|
||||||
|
parser.initParser()
|
||||||
|
|
||||||
|
# This is what an example dialogue might look like using Polish punctuation rules
|
||||||
|
# See discussion #1976
|
||||||
|
|
||||||
|
assert parser(
|
||||||
|
"– Example statement – someone said. And he added: – Another example statement."
|
||||||
|
) == [
|
||||||
|
(0, 20), (50, 78),
|
||||||
|
]
|
||||||
|
|
||||||
|
assert parser(
|
||||||
|
"– Oh my! – It would be nice if only the statements were highlighted, without "
|
||||||
|
"any narration. In a paragraph where there is only a short statement and then "
|
||||||
|
"a lot happens, this would be especially justified."
|
||||||
|
) == [
|
||||||
|
(0, 9),
|
||||||
|
]
|
||||||
|
|
||||||
|
assert parser(
|
||||||
|
"There are also sometimes paragraphs that start with a narrative, and only then "
|
||||||
|
"someone shouts out the words: – Oooh! Look!"
|
||||||
|
) == [
|
||||||
|
(109, 122),
|
||||||
|
]
|
||||||
|
|
||||||
|
assert parser(
|
||||||
|
"And so on and so forth. However, \"text in quotation marks\" should not be "
|
||||||
|
"highlighted at all, and if so, it should be highlighted differently."
|
||||||
|
) == []
|
||||||
|
|||||||
Reference in New Issue
Block a user