diff --git a/tests/test_core/test_core_tohtml.py b/tests/test_core/test_core_tohtml.py index 8b3b589c..a274f2a6 100644 --- a/tests/test_core/test_core_tohtml.py +++ b/tests/test_core/test_core_tohtml.py @@ -29,8 +29,8 @@ from novelwriter.core.project import NWProject @pytest.mark.core -def testCoreToHtml_ConvertFormat(mockGUI): - """Test the tokenizer and converter chain using the ToHtml class.""" +def testCoreToHtml_ConvertHeaders(mockGUI): + """Test header formats in the ToHtml class.""" project = NWProject() html = ToHtml(project) @@ -129,6 +129,19 @@ def testCoreToHtml_ConvertFormat(mockGUI): html.doConvert() assert html.result == "

Heading Two

\n" +# END Test testCoreToHtml_ConvertHeaders + + +@pytest.mark.core +def testCoreToHtml_ConvertParagraphs(mockGUI): + """Test paragraph formats in the ToHtml class.""" + project = NWProject() + html = ToHtml(project) + + html._isNovel = True + html._isNote = False + html._isFirst = True + # Paragraphs # ========== @@ -141,6 +154,19 @@ def testCoreToHtml_ConvertFormat(mockGUI): "strikethrough text here

\n" ) + # Shortcodes + html._text = ( + "Some [b]bold[/b], [i]italic[/i], [s]strike[/s], [u]underline[/u], [m]mark[/m], " + "super[sup]script[/sup], sub[sub]script[/sub] here\n" + ) + html.tokenizeText() + html.doConvert() + assert html.result == ( + "

Some bold, italic, strike, " + "underline, mark, " + "superscript, subscript here

\n" + ) + # Text w/Hard Break html._text = "Line one \nLine two \nLine three\n" html.tokenizeText() @@ -206,17 +232,13 @@ def testCoreToHtml_ConvertFormat(mockGUI): html.tokenizeText() html.doConvert() assert html.result == ( - "

" - "Chapter

\n" - "

" - "Point of View: Bod" - "

\n" - "

" - "Plot: Main" - "

\n" - "

" - "Locations: Europe" - "

\n" + "

Chapter

\n" + "

Point of View: " + "Bod

\n" + "

Plot: " + "Main

\n" + "

Locations: " + "Europe

\n" ) # Preview Mode @@ -234,7 +256,7 @@ def testCoreToHtml_ConvertFormat(mockGUI): "text here

\n" ) -# END Test testCoreToHtml_ConvertFormat +# END Test testCoreToHtml_ConvertParagraphs @pytest.mark.core diff --git a/tests/test_core/test_core_tokenizer.py b/tests/test_core/test_core_tokenizer.py index a74e567c..5c492a7f 100644 --- a/tests/test_core/test_core_tokenizer.py +++ b/tests/test_core/test_core_tokenizer.py @@ -638,6 +638,11 @@ def testCoreToken_ExtractFormats(mockGUI): assert text == "Text with underline in it." assert fmt == [(10, tokens.FMT_U_B), (19, tokens.FMT_U_E)] + # Plain mark + text, fmt = tokens._extractFormats("Text with [m]highlight[/m] in it.") + assert text == "Text with highlight in it." + assert fmt == [(10, tokens.FMT_M_B), (19, tokens.FMT_M_E)] + # Plain superscript text, fmt = tokens._extractFormats("Text with super[sup]script[/sup] in it.") assert text == "Text with superscript in it." diff --git a/tests/test_core/test_core_tomd.py b/tests/test_core/test_core_tomd.py index fc2503ac..b368ad68 100644 --- a/tests/test_core/test_core_tomd.py +++ b/tests/test_core/test_core_tomd.py @@ -29,16 +29,11 @@ from novelwriter.core.project import NWProject @pytest.mark.core -def testCoreToMarkdown_ConvertFormat(mockGUI): - """Test the tokenizer and converter chain using the ToMarkdown - class. - """ +def testCoreToMarkdown_ConvertHeaders(mockGUI): + """Test header formats in the ToMarkdown class.""" project = NWProject() toMD = ToMarkdown(project) - # Headers - # ======= - toMD._isNovel = True toMD._isNote = False toMD._isFirst = True @@ -79,8 +74,18 @@ def testCoreToMarkdown_ConvertFormat(mockGUI): toMD.doConvert() assert toMD.result == "## Prologue\n\n" - # Paragraphs - # ========== +# END Test testCoreToMarkdown_ConvertHeaders + + +@pytest.mark.core +def testCoreToMarkdown_ConvertParagraphs(mockGUI): + """Test paragraph formats in the ToMarkdown class.""" + project = NWProject() + toMD = ToMarkdown(project) + + toMD._isNovel = True + toMD._isNote = False + toMD._isFirst = True # Text for Extended Markdown toMD.setExtendedMarkdown() @@ -100,6 +105,31 @@ def testCoreToMarkdown_ConvertFormat(mockGUI): "Some **nested bold and _italic_ and strikethrough text** here\n\n" ) + # Shortcodes for Extended Markdown + toMD.setExtendedMarkdown() + toMD._text = ( + "Some [b]bold[/b], [i]italic[/i], [s]strike[/s], [u]underline[/u], [m]mark[/m], " + "super[sup]script[/sup], sub[sub]script[/sub] here\n" + ) + toMD.tokenizeText() + toMD.doConvert() + assert toMD.result == ( + "Some **bold**, _italic_, ~~strike~~, underline, ==mark==, " + "super^script^, sub~script~ here\n\n" + ) + + # Shortcodes for Standard Markdown + toMD.setStandardMarkdown() + toMD._text = ( + "Some [b]bold[/b], [i]italic[/i], [s]strike[/s], [u]underline[/u], [m]mark[/m], " + "super[sup]script[/sup], sub[sub]script[/sub] here\n" + ) + toMD.tokenizeText() + toMD.doConvert() + assert toMD.result == ( + "Some **bold**, _italic_, strike, underline, mark, superscript, subscript here\n\n" + ) + # Text w/Hard Break toMD._text = "Line one \nLine two \nLine three\n" toMD.tokenizeText() @@ -160,7 +190,7 @@ def testCoreToMarkdown_ConvertFormat(mockGUI): "**Locations:** Europe\n\n" ) -# END Test testCoreToMarkdown_ConvertFormat +# END Test testCoreToMarkdown_ConvertParagraphs @pytest.mark.core diff --git a/tests/test_core/test_core_toodt.py b/tests/test_core/test_core_toodt.py index c9039236..23afa0ac 100644 --- a/tests/test_core/test_core_toodt.py +++ b/tests/test_core/test_core_toodt.py @@ -237,22 +237,12 @@ def testCoreToOdt_TextFormatting(mockGUI): @pytest.mark.core -def testCoreToOdt_Convert(mockGUI): +def testCoreToOdt_ConvertHeaders(mockGUI): """Test the converter of the ToOdt class.""" project = NWProject() odt = ToOdt(project, isFlat=True) - odt._isNovel = True - def getStyle(styleName): - for aSet in odt._autoPara.values(): - if aSet[0] == styleName: - return aSet[1] - return None - - # Headers - # ======= - # Header 1 odt._text = "# Title\n" odt.tokenizeText() @@ -331,8 +321,21 @@ def testCoreToOdt_Convert(mockGUI): '' ) - # Paragraphs - # ========== +# END Test testCoreToOdt_ConvertHeaders + + +@pytest.mark.core +def testCoreToOdt_ConvertParagraphs(mockGUI): + """Test the converter of the ToOdt class.""" + project = NWProject() + odt = ToOdt(project, isFlat=True) + odt._isNovel = True + + def getStyle(styleName): + for aSet in odt._autoPara.values(): + if aSet[0] == styleName: + return aSet[1] + return None # Nested Markdown Text odt._text = "Some ~~nested **bold** and _italics_ text~~ text." @@ -372,7 +375,7 @@ def testCoreToOdt_Convert(mockGUI): '' ) - # Nested Shortcode Text, Super/Subscript + # Shortcode Text, Super/Subscript odt._text = "Some super[sup]script[/sup] and sub[sub]script[/sub] text." odt.tokenizeText() odt.initDocument() @@ -387,6 +390,21 @@ def testCoreToOdt_Convert(mockGUI): '' ) + # Shortcode Text, Underline/Highlight + odt._text = "Some [u]underlined and [m]highlighted[/m][/u] text." + odt.tokenizeText() + odt.initDocument() + odt.doConvert() + odt.closeDocument() + assert odt.errData == [] + assert xmlToText(odt._xText) == ( + '' + 'Some ' + 'underlined and ' + 'highlighted text.' + '' + ) + # Hard Break odt._text = "Some text.\nNext line\n" odt.tokenizeText() @@ -422,7 +440,7 @@ def testCoreToOdt_Convert(mockGUI): assert odt.errData == [] assert xmlToText(odt._xText) == ( '' - 'Some ' + 'Some ' 'boldtext' '' ) @@ -467,13 +485,13 @@ def testCoreToOdt_Convert(mockGUI): assert xmlToText(odt._xText) == ( '' 'Scene' - '' + '' 'Point of View: Jane' - '' + '' 'Synopsis: So it begins' - '' + '' 'Short Description: Then what' - '' + '' 'Comment: A plain comment' '' ) @@ -535,26 +553,26 @@ def testCoreToOdt_Convert(mockGUI): assert xmlToText(odt._xText) == ( '' 'Scene' - '' + '' 'Point of View: Jane' - '' + '' 'Characters: John' - '' + '' 'Plot: Main' - 'Right align' + 'Right align' 'Left Align' - 'Centered' - 'Left indent' - 'Right indent' + 'Centered' + 'Left indent' + 'Right indent' '' ) - assert getStyle("P3")._pAttr["margin-bottom"] == ["fo", "0.000cm"] # type: ignore - assert getStyle("P4")._pAttr["margin-bottom"] == ["fo", "0.000cm"] # type: ignore - assert getStyle("P4")._pAttr["margin-top"] == ["fo", "0.000cm"] # type: ignore - assert getStyle("P5")._pAttr["text-align"] == ["fo", "right"] # type: ignore - assert getStyle("P6")._pAttr["text-align"] == ["fo", "center"] # type: ignore - assert getStyle("P7")._pAttr["margin-left"] == ["fo", "1.693cm"] # type: ignore - assert getStyle("P8")._pAttr["margin-right"] == ["fo", "1.693cm"] # type: ignore + assert getStyle("P1")._pAttr["margin-bottom"] == ["fo", "0.000cm"] # type: ignore + assert getStyle("P2")._pAttr["margin-bottom"] == ["fo", "0.000cm"] # type: ignore + assert getStyle("P2")._pAttr["margin-top"] == ["fo", "0.000cm"] # type: ignore + assert getStyle("P3")._pAttr["text-align"] == ["fo", "right"] # type: ignore + assert getStyle("P4")._pAttr["text-align"] == ["fo", "center"] # type: ignore + assert getStyle("P5")._pAttr["margin-left"] == ["fo", "1.693cm"] # type: ignore + assert getStyle("P6")._pAttr["margin-right"] == ["fo", "1.693cm"] # type: ignore # Justified odt._text = ( @@ -573,11 +591,11 @@ def testCoreToOdt_Convert(mockGUI): '' 'Scene' 'Regular paragraph' - 'withbreak' - 'Left Align' + 'withbreak' + 'Left Align' '' ) - assert getStyle("P9")._pAttr["text-align"] == ["fo", "left"] # type: ignore + assert getStyle("P7")._pAttr["text-align"] == ["fo", "left"] # type: ignore # Page Breaks odt._text = ( @@ -593,9 +611,9 @@ def testCoreToOdt_Convert(mockGUI): assert odt.errData == [] assert xmlToText(odt._xText) == ( '' - 'Chapter One' + 'Chapter One' 'Text' - 'Chapter Two' + 'Chapter Two' 'Text' '' ) @@ -612,12 +630,12 @@ def testCoreToOdt_Convert(mockGUI): assert odt.errData == [] assert xmlToText(odt._xText) == ( '' - 'Test text **' + 'Test text **' 'bold** and more.' '' ) -# END Test testCoreToOdt_Convert +# END Test testCoreToOdt_ConvertParagraphs @pytest.mark.core @@ -1081,6 +1099,17 @@ def testCoreToOdt_ODTTextStyle(): txtStyle.setFontStyle("stuff") assert txtStyle._tAttr["font-style"] == ["fo", None] + # Background Color + assert txtStyle._tAttr["background-color"] == ["fo", None] + txtStyle.setBackgroundColor("stuff") + assert txtStyle._tAttr["background-color"] == ["fo", None] + txtStyle.setBackgroundColor("012345") + assert txtStyle._tAttr["background-color"] == ["fo", None] + txtStyle.setBackgroundColor("#012345") + assert txtStyle._tAttr["background-color"] == ["fo", "#012345"] + txtStyle.setBackgroundColor("stuff") + assert txtStyle._tAttr["background-color"] == ["fo", None] + # Text Position assert txtStyle._tAttr["text-position"] == ["style", None] txtStyle.setTextPosition("stuff") diff --git a/tests/test_gui/test_gui_doceditor.py b/tests/test_gui/test_gui_doceditor.py index 93b8bcc8..8ce95710 100644 --- a/tests/test_gui/test_gui_doceditor.py +++ b/tests/test_gui/test_gui_doceditor.py @@ -491,6 +491,13 @@ def testGuiEditor_Actions(qtbot, nwGUI, projPath, ipsumText, mockRnd): assert nwGUI.docEditor.docAction(nwDocAction.UNDO) is True assert nwGUI.docEditor.getText() == text + # Mark + nwGUI.docEditor.setCursorPosition(46) + assert nwGUI.docEditor.docAction(nwDocAction.SC_MARK) is True + assert nwGUI.docEditor.getText() == text.replace("consectetur", "[m]consectetur[/m]") + assert nwGUI.docEditor.docAction(nwDocAction.UNDO) is True + assert nwGUI.docEditor.getText() == text + # Superscript nwGUI.docEditor.setCursorPosition(46) assert nwGUI.docEditor.docAction(nwDocAction.SC_SUP) is True