Fix word counter bug (#1816)
This commit is contained in:
@@ -57,6 +57,7 @@ def preProcessText(text: str, keepHeaders: bool = True) -> list[str]:
|
||||
continue
|
||||
if line[0] == ">":
|
||||
line = line.lstrip(">").lstrip(" ")
|
||||
if line: # Above check can return empty line (Issue #1816)
|
||||
if line[-1] == "<":
|
||||
line = line.rstrip("<").rstrip(" ")
|
||||
if "[" in line:
|
||||
|
||||
@@ -29,7 +29,7 @@ from novelwriter.text.counting import bodyTextCounter, preProcessText, standardC
|
||||
def testTextCounting_preProcessText():
|
||||
"""Test the text preprocessor for counters."""
|
||||
# Not Text
|
||||
assert preProcessText(None) == []
|
||||
assert preProcessText(None) == [] # type: ignore
|
||||
|
||||
# No Text
|
||||
assert preProcessText("") == []
|
||||
@@ -81,6 +81,10 @@ def testTextCounting_standardCounter():
|
||||
assert standardCounter(None) == (0, 0, 0) # type: ignore
|
||||
assert standardCounter(1234) == (0, 0, 0) # type: ignore
|
||||
|
||||
# Test Corner Cases, Bug #1816
|
||||
assert standardCounter("> ") == (0, 0, 0)
|
||||
assert standardCounter(" <") == (0, 0, 0)
|
||||
|
||||
# General Text
|
||||
cC, wC, pC = standardCounter((
|
||||
"#! Title\n\n"
|
||||
@@ -182,7 +186,7 @@ def testTextCounting_standardCounter():
|
||||
def testTextCounting_bodyTextCounter():
|
||||
"""Test the body text counter."""
|
||||
# Not Text
|
||||
assert bodyTextCounter(None) == (0, 0, 0)
|
||||
assert bodyTextCounter(None) == (0, 0, 0) # type: ignore
|
||||
|
||||
# General Text
|
||||
wC, cC, sC = bodyTextCounter((
|
||||
|
||||
Reference in New Issue
Block a user