QTextMarkdownImporter: spell CRLF literal correctly
Amends eced22d7250fc7ba4dbafa1694bf149c2259d9ea tst_QTextMarkdownImporter::frontMatter(yaml + markdown with CRLFs) now does explicit replacement of LF with CRLF: git may convert the file, so we can't rely on the CI test system checking out a true copy of yaml-crlf.md; but QFile::open(ReadOnly | Text) ensures that we will have LF line endings, not CRLF. Pick-to: 6.8 Task-number: QTBUG-135284 Change-Id: I7eee5f41e7aea902a59ac06238e591ece016d2d3 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io> (cherry picked from commit 66595c3efe125cc92333d7a71317cce529c52e92) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
c3eaa283c3
commit
4ebb0413f1
@ -29,7 +29,7 @@ static const QChar qtmi_Newline = u'\n';
|
||||
static const QChar qtmi_Space = u' ';
|
||||
|
||||
static constexpr auto lfMarkerString() noexcept { return "---\n"_L1; }
|
||||
static constexpr auto crlfMarkerString() noexcept { return "---r\n"_L1; }
|
||||
static constexpr auto crlfMarkerString() noexcept { return "---\r\n"_L1; }
|
||||
|
||||
// TODO maybe eliminate the margins after all views recognize BlockQuoteLevel, CSS can format it, etc.
|
||||
static const int qtmi_BlockQuoteIndent =
|
||||
|
@ -1,10 +0,0 @@
|
||||
---
|
||||
name: "Venus"
|
||||
discoverer: "Galileo Galilei"
|
||||
title: "A description of the planet Venus"
|
||||
keywords:
|
||||
- planets
|
||||
- solar system
|
||||
- astronomy
|
||||
---
|
||||
*Venus* is the second planet from the Sun, orbiting it every 224.7 Earth days.
|
@ -645,20 +645,22 @@ void tst_QTextMarkdownImporter::fencedCodeBlocks()
|
||||
void tst_QTextMarkdownImporter::frontMatter_data()
|
||||
{
|
||||
QTest::addColumn<QString>("inputFile");
|
||||
QTest::addColumn<bool>("convertToCrLf");
|
||||
QTest::addColumn<int>("expectedFrontMatterSize");
|
||||
QTest::addColumn<int>("expectedBlockCount");
|
||||
|
||||
QTest::newRow("yaml + markdown") << QFINDTESTDATA("data/yaml.md") << 140 << 1;
|
||||
QTest::newRow("yaml + markdown with CRLFs") << QFINDTESTDATA("data/yaml-crlf.md") << 140 << 1;
|
||||
QTest::newRow("yaml only") << QFINDTESTDATA("data/yaml-only.md") << 59 << 0;
|
||||
QTest::newRow("malformed 1") << QFINDTESTDATA("data/front-marker-malformed1.md") << 0 << 1;
|
||||
QTest::newRow("malformed 2") << QFINDTESTDATA("data/front-marker-malformed2.md") << 0 << 2;
|
||||
QTest::newRow("malformed 3") << QFINDTESTDATA("data/front-marker-malformed3.md") << 0 << 1;
|
||||
QTest::newRow("yaml + markdown") << QFINDTESTDATA("data/yaml.md") << false << 140 << 1;
|
||||
QTest::newRow("yaml + markdown with CRLFs") << QFINDTESTDATA("data/yaml.md") << true << 147 << 1;
|
||||
QTest::newRow("yaml only") << QFINDTESTDATA("data/yaml-only.md") << false << 59 << 0;
|
||||
QTest::newRow("malformed 1") << QFINDTESTDATA("data/front-marker-malformed1.md") << false << 0 << 1;
|
||||
QTest::newRow("malformed 2") << QFINDTESTDATA("data/front-marker-malformed2.md") << false << 0 << 2;
|
||||
QTest::newRow("malformed 3") << QFINDTESTDATA("data/front-marker-malformed3.md") << false << 0 << 1;
|
||||
}
|
||||
|
||||
void tst_QTextMarkdownImporter::frontMatter()
|
||||
{
|
||||
QFETCH(QString, inputFile);
|
||||
QFETCH(bool, convertToCrLf);
|
||||
QFETCH(int, expectedFrontMatterSize);
|
||||
QFETCH(int, expectedBlockCount);
|
||||
|
||||
@ -666,6 +668,10 @@ void tst_QTextMarkdownImporter::frontMatter()
|
||||
QVERIFY(f.open(QFile::ReadOnly | QIODevice::Text));
|
||||
QString md = QString::fromUtf8(f.readAll());
|
||||
f.close();
|
||||
if (convertToCrLf)
|
||||
md.replace("\n", "\r\n");
|
||||
qCDebug(lcTests) << inputFile << "begins with" << md.first(16).toLatin1().toHex(' ');
|
||||
|
||||
const int yamlBegin = md.indexOf("name:");
|
||||
const int yamlEnd = md.indexOf("---", yamlBegin);
|
||||
const QString yaml = md.sliced(yamlBegin, yamlEnd - yamlBegin);
|
||||
|
Loading…
x
Reference in New Issue
Block a user