diff options
Diffstat (limited to 'sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.cpp')
-rw-r--r-- | sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.cpp | 107 |
1 files changed, 92 insertions, 15 deletions
diff --git a/sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.cpp b/sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.cpp index 963a74da7..45cecd1a1 100644 --- a/sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.cpp +++ b/sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.cpp @@ -5,9 +5,12 @@ #include "qtxmltosphinx.h" #include <QtTest/QTest> +#include <QtCore/QBuffer> #include <QtCore/QDebug> #include <QtCore/QLoggingCategory> +using namespace Qt::StringLiterals; + Q_LOGGING_CATEGORY(lcQtXmlToSphinxTest, "qt.sphinxtabletest"); // QtXmlToSphinxDocGeneratorInterface @@ -271,6 +274,43 @@ void QtXmlToSphinxTest::testTable_data() QTest::newRow("testRowSpan2") << QString::fromLatin1(xml) << QString::fromLatin1(expected); + // testNestedList + xml = R"(<table> + <row> + <item> + <list type="bullet"> + <item> + <para>I11</para> + </item> + <item> + <para>I21</para> + </item> + </list> + </item> + <item> + <list type="bullet"> + <item> + <para>I12</para> + </item> + <item> + <para>I22</para> + </item> + </list> + </item> + </row> +</table>)"; + + expected = R"( + +---------+---------+ + | * I11| * I12| + | * I21| * I22| + +---------+---------+ + +)"; + + QTest::newRow("testNestedList") + << QString::fromLatin1(xml) << QString::fromLatin1(expected); + // testBrokenTable xml = R"(<table> <header> @@ -344,26 +384,20 @@ void QtXmlToSphinxTest::testTable() QCOMPARE(actual, expected); } -using TablePtr = QSharedPointer<QtXmlToSphinx::Table>; +using TablePtr = std::shared_ptr<QtXmlToSphinx::Table>; Q_DECLARE_METATYPE(TablePtr); void QtXmlToSphinxTest::testTableFormatting_data() { - using TableRow = QtXmlToSphinx::TableRow; using TableCell = QtXmlToSphinx::TableCell; QTest::addColumn<TablePtr>("table"); QTest::addColumn<QString>("expected"); TablePtr table(new QtXmlToSphinx::Table); - TableRow row; - row << TableCell("item11") << TableCell("item12"); - table->appendRow(row); - row.clear(); - row << TableCell("") << TableCell("item22"); - table->appendRow(row); - row.clear(); + table->appendRow({TableCell("item11"), TableCell("item12")}); + table->appendRow({TableCell(""), TableCell("item22")}); table->normalize(); const char *expected = R"(+------+------+ @@ -377,12 +411,8 @@ void QtXmlToSphinxTest::testTableFormatting_data() QTest::newRow("normal") << table << QString::fromLatin1(expected); table.reset(new QtXmlToSphinx::Table); - row << TableCell("item11") << TableCell("item12\nline2"); - table->appendRow(row); - row.clear(); - row << TableCell("") << TableCell("item22\nline2\nline3"); - table->appendRow(row); - row.clear(); + table->appendRow({TableCell("item11"), TableCell("item12\nline2")}); + table->appendRow({TableCell(""), TableCell("item22\nline2\nline3")}); table->normalize(); expected = R"(+------+------+ @@ -431,4 +461,51 @@ void QtXmlToSphinxTest::testTableFormattingIoDevice() QCOMPARE(actual, expected); } +void QtXmlToSphinxTest::testSnippetExtraction_data() +{ + QTest::addColumn<QByteArray>("file"); + QTest::addColumn<QLatin1StringView>("id"); + QTest::addColumn<QString>("expected"); + + const char *fileCpp = R"(bla +// ![snip1] +snip1_line1 +// ![snip1] // ![snip2] +snip2_line1 +snip2_line2 +// ![snip2] // ![snip3] +)"; + + constexpr auto id = "snip2"_L1; + const QString expected = uR"(snip2_line1 +snip2_line2 +)"_s; + + const char *filePython = R"(bla +# ![snip1] +snip1_line1 +# ![snip1] # ![snip2] +snip2_line1 +snip2_line2 +# ![snip2] # ![snip3] +)"; + + QTest::newRow("c++") << QByteArray(fileCpp) << id << expected; + QTest::newRow("Python") << QByteArray(filePython) << id << expected; +} + +void QtXmlToSphinxTest::testSnippetExtraction() +{ + QFETCH(QByteArray, file); + QFETCH(QLatin1StringView, id); + QFETCH(QString, expected); + + QBuffer buffer(&file); + QVERIFY(buffer.open(QIODevice::ReadOnly)); + QString errorMessage; + QString actual = QtXmlToSphinx::readSnippet(buffer, id, &errorMessage); + QVERIFY2(errorMessage.isEmpty(), qPrintable(errorMessage)); + QCOMPARE(actual, expected); +} + QTEST_APPLESS_MAIN( QtXmlToSphinxTest) |