aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.cpp')
-rw-r--r--sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.cpp644
1 files changed, 348 insertions, 296 deletions
diff --git a/sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.cpp b/sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.cpp
index ea60d36b5..45cecd1a1 100644
--- a/sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.cpp
+++ b/sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.cpp
@@ -1,38 +1,16 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of Qt for Python.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "qtxmltosphinxtest.h"
#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
@@ -74,285 +52,322 @@ void QtXmlToSphinxTest::testTable_data()
QTest::newRow("emptyString") << QString() << QString();
// testSimpleTable
- const char *xml = "\
-<table>\
- <header>\
- <item>\
- <para>Header 1</para>\
- </item>\
- <item>\
- <para>Header 2</para>\
- </item>\
- </header>\
- <row>\
- <item>\
- <para>1 1</para>\
- </item>\
- <item>\
- <para>1 2</para>\
- </item>\
- </row>\
- <row>\
- <item>\
- <para>2 1</para>\
- </item>\
- <item>\
- <para>2 2</para>\
- </item>\
- </row>\
-</table>";
-
- const char *expected = "\n\
- +--------+--------+\n\
- |Header 1|Header 2|\n\
- +--------+--------+\n\
- |1 1 |1 2 |\n\
- +--------+--------+\n\
- |2 1 |2 2 |\n\
- +--------+--------+\n\
-\n";
+ const char *xml = R"(<table>
+ <header>
+ <item>
+ <para>Header 1</para>
+ </item>
+ <item>
+ <para>Header 2</para>
+ </item>
+ </header>
+ <row>
+ <item>
+ <para>1 1</para>
+ </item>
+ <item>
+ <para>1 2</para>
+ </item>
+ </row>
+ <row>
+ <item>
+ <para>2 1</para>
+ </item>
+ <item>
+ <para>2 2</para>
+ </item>
+ </row>
+</table>)";
+
+ const char *expected = R"(
+ +--------+--------+
+ |Header 1|Header 2|
+ +========+========+
+ |1 1 |1 2 |
+ +--------+--------+
+ |2 1 |2 2 |
+ +--------+--------+
+
+)";
QTest::newRow("testSimpleTable")
<< QString::fromLatin1(xml) << QString::fromLatin1(expected);
// testRowSpan
- xml = "\
-<table>\
- <header>\
- <item>\
- <para>Header 1</para>\
- </item>\
- <item>\
- <para>Header 2</para>\
- </item>\
- </header>\
- <row>\
- <item colspan=\"2\">\
- <para>I'm a big text!</para>\
- </item>\
- </row>\
- <row>\
- <item>\
- <para>2 1</para>\
- </item>\
- <item>\
- <para>2 2</para>\
- </item>\
- </row>\
-</table>";
-
- expected = "\n\
- +---------------+--------+\n\
- |Header 1 |Header 2|\n\
- +---------------+--------+\n\
- |I'm a big text! |\n\
- +---------------+--------+\n\
- |2 1 |2 2 |\n\
- +---------------+--------+\n\
-\n";
+ xml = R"(<table>
+ <header>
+ <item>
+ <para>Header 1</para>
+ </item>
+ <item>
+ <para>Header 2</para>
+ </item>
+ </header>
+ <row>
+ <item colspan="2">
+ <para>I'm a big text!</para>
+ </item>
+ </row>
+ <row>
+ <item>
+ <para>2 1</para>
+ </item>
+ <item>
+ <para>2 2</para>
+ </item>
+ </row>
+</table>)";
+
+ expected = R"(
+ +---------------+--------+
+ |Header 1 |Header 2|
+ +===============+========+
+ |I'm a big text! |
+ +---------------+--------+
+ |2 1 |2 2 |
+ +---------------+--------+
+
+)";
QTest::newRow("testColSpan")
<< QString::fromLatin1(xml) << QString::fromLatin1(expected);
// testRowSpan
- xml = "\
-<table>\
- <header>\
- <item>\
- <para>Header 1</para>\
- </item>\
- <item>\
- <para>Header 2</para>\
- </item>\
- </header>\
- <row>\
- <item rowspan=\"2\">\
- <para>1.1</para>\
- </item>\
- <item>\
- <para>1.2</para>\
- </item>\
- </row>\
- <row>\
- <item>\
- <para>2 2</para>\
- </item>\
- </row>\
-</table>";
-
- expected = "\n\
- +--------+--------+\n\
- |Header 1|Header 2|\n\
- +--------+--------+\n\
- |1.1 |1.2 |\n\
- + +--------+\n\
- | |2 2 |\n\
- +--------+--------+\n\
-\n";
+ xml = R"(<table>
+ <header>
+ <item>
+ <para>Header 1</para>
+ </item>
+ <item>
+ <para>Header 2</para>
+ </item>
+ </header>
+ <row>
+ <item rowspan="2">
+ <para>1.1</para>
+ </item>
+ <item>
+ <para>1.2</para>
+ </item>
+ </row>
+ <row>
+ <item>
+ <para>2 2</para>
+ </item>
+ </row>
+</table>)";
+
+ expected = R"(
+ +--------+--------+
+ |Header 1|Header 2|
+ +========+========+
+ |1.1 |1.2 |
+ + +--------+
+ | |2 2 |
+ +--------+--------+
+
+)";
QTest::newRow("testRowSpan")
<< QString::fromLatin1(xml) << QString::fromLatin1(expected);
// testComplexTable
- xml = "\
-<table>\
- <header>\
- <item>\
- <para>Header 1</para>\
- </item>\
- <item>\
- <para>Header 2</para>\
- </item>\
- <item>\
- <para>Header 3</para>\
- </item>\
- </header>\
- <row>\
- <item rowspan=\"2\">\
- <para>1.1</para>\
- </item>\
- <item colspan=\"2\">\
- <para>1.2</para>\
- </item>\
- </row>\
- <row>\
- <item>\
- <para>2 2</para>\
- </item>\
- <item>\
- <para>2 3</para>\
- </item>\
- </row>\
-</table>";
-
- expected = "\n\
- +--------+--------+--------+\n\
- |Header 1|Header 2|Header 3|\n\
- +--------+--------+--------+\n\
- |1.1 |1.2 |\n\
- + +--------+--------+\n\
- | |2 2 |2 3 |\n\
- +--------+--------+--------+\n\
-\n";
+ xml = R"(<table>
+ <header>
+ <item>
+ <para>Header 1</para>
+ </item>
+ <item>
+ <para>Header 2</para>
+ </item>
+ <item>
+ <para>Header 3</para>
+ </item>
+ </header>
+ <row>
+ <item rowspan="2">
+ <para>1.1</para>
+ </item>
+ <item colspan="2">
+ <para>1.2</para>
+ </item>
+ </row>
+ <row>
+ <item>
+ <para>2 2</para>
+ </item>
+ <item>
+ <para>2 3</para>
+ </item>
+ </row>
+</table>)";
+
+ expected = R"(
+ +--------+--------+--------+
+ |Header 1|Header 2|Header 3|
+ +========+========+========+
+ |1.1 |1.2 |
+ + +--------+--------+
+ | |2 2 |2 3 |
+ +--------+--------+--------+
+
+)";
QTest::newRow("testComplexTable")
<< QString::fromLatin1(xml) << QString::fromLatin1(expected);
// testRowSpan2
- xml = "\
-<table>\
- <header>\
- <item><para>h1</para></item>\
- <item><para>h2</para></item>\
- <item><para>h3</para></item>\
- <item><para>h4</para></item>\
- </header>\
- <row>\
- <item rowspan=\"6\"><para>A</para></item>\
- <item rowspan=\"6\"><para>B</para></item>\
- <item><para>C</para></item>\
- <item><para>D</para></item>\
- </row>\
- <row>\
- <item><para>E</para></item>\
- <item><para>F</para></item>\
- </row>\
- <row>\
- <item><para>E</para></item>\
- <item><para>F</para></item>\
- </row>\
- <row>\
- <item><para>E</para></item>\
- <item><para>F</para></item>\
- </row>\
- <row>\
- <item><para>E</para></item>\
- <item><para>F</para></item>\
- </row>\
- <row>\
- <item><para>E</para></item>\
- <item><para>F</para></item>\
- </row>\
-</table>";
-
- expected = "\n\
- +--+--+--+--+\n\
- |h1|h2|h3|h4|\n\
- +--+--+--+--+\n\
- |A |B |C |D |\n\
- + + +--+--+\n\
- | | |E |F |\n\
- + + +--+--+\n\
- | | |E |F |\n\
- + + +--+--+\n\
- | | |E |F |\n\
- + + +--+--+\n\
- | | |E |F |\n\
- + + +--+--+\n\
- | | |E |F |\n\
- +--+--+--+--+\n\
-\n";
+ xml = R"(<table>
+ <header>
+ <item><para>h1</para></item>
+ <item><para>h2</para></item>
+ <item><para>h3</para></item>
+ <item><para>h4</para></item>
+ </header>
+ <row>
+ <item rowspan="6"><para>A</para></item>
+ <item rowspan="6"><para>B</para></item>
+ <item><para>C</para></item>
+ <item><para>D</para></item>
+ </row>
+ <row>
+ <item><para>E</para></item>
+ <item><para>F</para></item>
+ </row>
+ <row>
+ <item><para>E</para></item>
+ <item><para>F</para></item>
+ </row>
+ <row>
+ <item><para>E</para></item>
+ <item><para>F</para></item>
+ </row>
+ <row>
+ <item><para>E</para></item>
+ <item><para>F</para></item>
+ </row>
+ <row>
+ <item><para>E</para></item>
+ <item><para>F</para></item>
+ </row>
+</table>)";
+
+ expected = R"(
+ +--+--+--+--+
+ |h1|h2|h3|h4|
+ +==+==+==+==+
+ |A |B |C |D |
+ + + +--+--+
+ | | |E |F |
+ + + +--+--+
+ | | |E |F |
+ + + +--+--+
+ | | |E |F |
+ + + +--+--+
+ | | |E |F |
+ + + +--+--+
+ | | |E |F |
+ +--+--+--+--+
+
+)";
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 = "\
-<table>\
- <header>\
- <item>\
- <para>Header 1</para>\
- </item>\
- <item>\
- <para>Header 2</para>\
- </item>\
- </header>\
- <row>\
- <item>\
- <para>1.1</para>\
- </item>\
- <item>\
- <para>1.2</para>\
- </item>\
- </row>\
- <row>\
- <item colspan=\"2\">\
- <para>2 2</para>\
- </item>\
- <item>\
- <para>2 3</para>\
- </item>\
- <item>\
- <para>2 4</para>\
- </item>\
- <item>\
- <para>2 5</para>\
- </item>\
- </row>\
- <row>\
- <item>\
- <para>3 1</para>\
- </item>\
- <item>\
- <para>3 2</para>\
- </item>\
- <item>\
- <para>3 3</para>\
- </item>\
- </row>\
-</table>";
-
- expected = "\n\
- +--------+------------+\n\
- |Header 1|Header 2 |\n\
- +--------+------------+\n\
- |1.1 |1.2 |\n\
- +--------+------------+\n\
- |2 2 2 3 2 4 2 5|\n\
- +--------+------------+\n\
- |3 1 |3 2 3 3 |\n\
- +--------+------------+\n\
-\n";
+ xml = R"(<table>
+ <header>
+ <item>
+ <para>Header 1</para>
+ </item>
+ <item>
+ <para>Header 2</para>
+ </item>
+ </header>
+ <row>
+ <item>
+ <para>1.1</para>
+ </item>
+ <item>
+ <para>1.2</para>
+ </item>
+ </row>
+ <row>
+ <item colspan="2">
+ <para>2 2</para>
+ </item>
+ <item>
+ <para>2 3</para>
+ </item>
+ <item>
+ <para>2 4</para>
+ </item>
+ <item>
+ <para>2 5</para>
+ </item>
+ </row>
+ <row>
+ <item>
+ <para>3 1</para>
+ </item>
+ <item>
+ <para>3 2</para>
+ </item>
+ <item>
+ <para>3 3</para>
+ </item>
+ </row>
+</table>)";
+
+ expected = R"(
+ +--------+------------+
+ |Header 1|Header 2 |
+ +========+============+
+ |1.1 |1.2 |
+ +--------+------------+
+ |2 2 2 3 2 4 2 5|
+ +--------+------------+
+ |3 1 |3 2 3 3 |
+ +--------+------------+
+
+)";
QTest::newRow("testBrokenTable")
<< QString::fromLatin1(xml) << QString::fromLatin1(expected);
@@ -369,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"(+------+------+
@@ -402,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"(+------+------+
@@ -456,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)