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