summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui')
-rw-r--r--tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp75
-rw-r--r--tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp4
2 files changed, 77 insertions, 2 deletions
diff --git a/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp b/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
index 87a8f4aa89..b8d53ca194 100644
--- a/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
+++ b/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
@@ -41,6 +41,8 @@ private slots:
void fragmentsAndProperties();
void pathological_data();
void pathological();
+ void fencedCodeBlocks_data();
+ void fencedCodeBlocks();
private:
bool isMainFontFixed();
@@ -490,5 +492,78 @@ void tst_QTextMarkdownImporter::pathological() // avoid crashing on crazy input
QTextDocument().setMarkdown(f.readAll());
}
+void tst_QTextMarkdownImporter::fencedCodeBlocks_data()
+{
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<int>("expectedCodeBlockCount");
+ QTest::addColumn<int>("expectedPlainBlockCount");
+ QTest::addColumn<QString>("expectedLanguage");
+ QTest::addColumn<QString>("expectedFenceChar");
+ QTest::addColumn<QString>("rewrite");
+
+ // TODO shouldn't add empty blocks: QTBUG-101031
+ QTest::newRow("backtick fence with language")
+ << "```pseudocode\nprint('hello world\\n')\n```\n"
+ << 2 << 0 << "pseudocode" << "`"
+ << "```pseudocode\nprint('hello world\\n')\n```\n\n";
+ QTest::newRow("tilde fence with language")
+ << "~~~pseudocode\nprint('hello world\\n')\n~~~\n"
+ << 2 << 0 << "pseudocode" << "~"
+ << "~~~pseudocode\nprint('hello world\\n')\n~~~\n\n";
+ QTest::newRow("embedded backticks")
+ << "```\nnone `one` ``two``\n```\nplain\n```\n```three``` ````four````\n```\nplain\n"
+ << 4 << 2 << QString() << "`"
+ << "```\nnone `one` ``two``\n```\nplain\n\n```\n```three``` ````four````\n```\nplain\n\n";
+}
+
+void tst_QTextMarkdownImporter::fencedCodeBlocks()
+{
+ QFETCH(QString, input);
+ QFETCH(int, expectedCodeBlockCount);
+ QFETCH(int, expectedPlainBlockCount);
+ QFETCH(QString, expectedLanguage);
+ QFETCH(QString, expectedFenceChar);
+ QFETCH(QString, rewrite);
+
+ QTextDocument doc;
+ doc.setMarkdown(input);
+
+#ifdef DEBUG_WRITE_HTML
+ {
+ QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + ".html");
+ out.open(QFile::WriteOnly);
+ out.write(doc.toHtml().toLatin1());
+ out.close();
+ }
+#endif
+
+ QTextFrame::iterator iterator = doc.rootFrame()->begin();
+ QTextFrame *currentFrame = iterator.currentFrame();
+ int codeBlockCount = 0;
+ int plainBlockCount = 0;
+ while (!iterator.atEnd()) {
+ // There are no child frames
+ QCOMPARE(iterator.currentFrame(), currentFrame);
+ // Check whether the block is code or plain
+ QTextBlock block = iterator.currentBlock();
+ const bool codeBlock = block.blockFormat().hasProperty(QTextFormat::BlockCodeFence);
+ QCOMPARE(block.blockFormat().nonBreakableLines(), codeBlock);
+ QCOMPARE(block.blockFormat().stringProperty(QTextFormat::BlockCodeLanguage), codeBlock ? expectedLanguage : QString());
+ if (codeBlock) {
+ QCOMPARE(block.blockFormat().stringProperty(QTextFormat::BlockCodeFence), expectedFenceChar);
+ ++codeBlockCount;
+ } else {
+ ++plainBlockCount;
+ }
+ qCDebug(lcTests) << (codeBlock ? "code" : "text") << block.text() << block.charFormat().fontFamilies();
+ ++iterator;
+ }
+ QCOMPARE(codeBlockCount, expectedCodeBlockCount);
+ QCOMPARE(plainBlockCount, expectedPlainBlockCount);
+ if (doc.toMarkdown() != rewrite && isMainFontFixed())
+ QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue);
+ QCOMPARE(doc.toMarkdown(), rewrite);
+}
+
QTEST_MAIN(tst_QTextMarkdownImporter)
#include "tst_qtextmarkdownimporter.moc"
diff --git a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp
index b9230be465..c5e4829533 100644
--- a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp
+++ b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp
@@ -500,8 +500,8 @@ void tst_QTextMarkdownWriter::fromHtml_data()
// "<p>(The first sentence of this paragraph is a line, the next paragraph has a number</p>13) but that's not part of an ordered list" <<
// "(The first sentence of this paragraph is a line, the next paragraph has a number\n\n13\\) but that's not part of an ordered list\n\n";
QTest::newRow("preformats with embedded backticks") <<
- "<pre>none `one` ``two``</pre><pre>```three``` ````four````</pre>plain" <<
- "``` none `one` ``two`` ```\n\n````` ```three``` ````four```` `````\n\nplain\n\n";
+ "<pre>none `one` ``two``</pre>plain<pre>```three``` ````four````</pre>plain" <<
+ "```\nnone `one` ``two``\n\n```\nplain\n\n```\n```three``` ````four````\n\n```\nplain\n\n";
}
void tst_QTextMarkdownWriter::fromHtml()