Add test coverage and update the highlighter
This commit is contained in:
@@ -36,6 +36,8 @@ from PyQt5.QtGui import (
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.common import checkInt
|
||||
from novelwriter.constants import nwRegEx, nwUnicode
|
||||
from novelwriter.core.index import processComment
|
||||
from novelwriter.enum import nwComment
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -352,16 +354,12 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
||||
|
||||
elif text.startswith("%"): # Comments
|
||||
self.setCurrentBlockState(self.BLOCK_TEXT)
|
||||
toCheck = text[1:].lstrip()
|
||||
synTag = toCheck[:9].lower()
|
||||
tLen = len(text)
|
||||
cLen = len(toCheck)
|
||||
cOff = tLen - cLen
|
||||
if synTag == "synopsis:":
|
||||
self.setFormat(0, cOff+9, self._hStyles["modifier"])
|
||||
self.setFormat(cOff+9, tLen, self._hStyles["hidden"])
|
||||
cStyle, _, cPos = processComment(text)
|
||||
if cStyle == nwComment.PLAIN:
|
||||
self.setFormat(0, len(text), self._hStyles["hidden"])
|
||||
else:
|
||||
self.setFormat(0, tLen, self._hStyles["hidden"])
|
||||
self.setFormat(0, cPos, self._hStyles["modifier"])
|
||||
self.setFormat(cPos, len(text), self._hStyles["hidden"])
|
||||
|
||||
else: # Text Paragraph
|
||||
|
||||
|
||||
@@ -29,9 +29,9 @@ from mocked import causeException
|
||||
from novelwriter.core.item import NWItem
|
||||
from tools import C, buildTestProject, cmpFiles, writeFile
|
||||
|
||||
from novelwriter.enum import nwItemClass, nwItemLayout
|
||||
from novelwriter.enum import nwComment, nwItemClass, nwItemLayout
|
||||
from novelwriter.constants import nwFiles
|
||||
from novelwriter.core.index import IndexItem, NWIndex, countWords, TagsIndex
|
||||
from novelwriter.core.index import IndexItem, NWIndex, countWords, TagsIndex, processComment
|
||||
from novelwriter.core.project import NWProject
|
||||
|
||||
|
||||
@@ -1264,7 +1264,34 @@ def testCoreIndex_ItemIndex(mockGUI, fncPath, mockRnd):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreIndex_CountWords():
|
||||
def testCoreIndex_processComment():
|
||||
"""Test the comment processing function."""
|
||||
# Regular comment
|
||||
assert processComment("%Hi") == (nwComment.PLAIN, "Hi", 0)
|
||||
assert processComment("% Hi") == (nwComment.PLAIN, "Hi", 0)
|
||||
assert processComment("% Hi:you") == (nwComment.PLAIN, "Hi:you", 0)
|
||||
|
||||
# Synopsis
|
||||
assert processComment("%synopsis:") == (nwComment.PLAIN, "synopsis:", 0)
|
||||
assert processComment("%synopsis: Hi") == (nwComment.SYNOPSIS, "Hi", 10)
|
||||
assert processComment("% synopsis: Hi") == (nwComment.SYNOPSIS, "Hi", 11)
|
||||
assert processComment("% synopsis : Hi") == (nwComment.SYNOPSIS, "Hi", 13)
|
||||
assert processComment("% Synopsis : Hi") == (nwComment.SYNOPSIS, "Hi", 15)
|
||||
assert processComment("% \t SYNOPSIS : Hi") == (nwComment.SYNOPSIS, "Hi", 16)
|
||||
|
||||
# Brief
|
||||
assert processComment("%brief:") == (nwComment.PLAIN, "brief:", 0)
|
||||
assert processComment("%brief: Hi") == (nwComment.BRIEF, "Hi", 7)
|
||||
assert processComment("% brief: Hi") == (nwComment.BRIEF, "Hi", 8)
|
||||
assert processComment("% brief : Hi") == (nwComment.BRIEF, "Hi", 10)
|
||||
assert processComment("% Brief : Hi") == (nwComment.BRIEF, "Hi", 12)
|
||||
assert processComment("% \t BRIEF : Hi") == (nwComment.BRIEF, "Hi", 13)
|
||||
|
||||
# END Test testCoreIndex_processComment
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreIndex_countWords():
|
||||
"""Test the word counter and the exclusion filers."""
|
||||
# Non-Text
|
||||
assert countWords(None) == (0, 0, 0) # type: ignore
|
||||
@@ -1362,4 +1389,4 @@ def testCoreIndex_CountWords():
|
||||
assert wC == 14
|
||||
assert pC == 2
|
||||
|
||||
# END Test testCoreIndex_CountWords
|
||||
# END Test testCoreIndex_countWords
|
||||
|
||||
Reference in New Issue
Block a user