Add test coverage and update the highlighter

This commit is contained in:
Veronica Berglyd Olsen
2023-11-25 17:50:59 +01:00
parent 887b4379b2
commit 8ed85363e2
2 changed files with 38 additions and 13 deletions
+31 -4
View File
@@ -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