2022-05-13 13:12:05 +00:00
|
|
|
// Copyright (C) 2019 The Qt Company Ltd.
|
2024-02-22 14:51:16 +00:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
2019-12-13 15:10:46 +00:00
|
|
|
|
2025-04-10 12:00:44 +00:00
|
|
|
#include <QtTest/QTest>
|
2020-03-18 08:19:31 +00:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
2019-12-13 15:10:46 +00:00
|
|
|
#include <QProcess>
|
|
|
|
#include <QString>
|
2020-03-18 08:19:31 +00:00
|
|
|
#include <QTemporaryDir>
|
2021-04-19 14:43:21 +00:00
|
|
|
#include <QtTest/private/qemulationdetector_p.h>
|
2021-08-06 10:27:35 +00:00
|
|
|
#include <QtQuickTestUtils/private/qmlutils_p.h>
|
2021-09-15 07:38:49 +00:00
|
|
|
#include <QtQmlDom/private/qqmldomitem_p.h>
|
|
|
|
#include <QtQmlDom/private/qqmldomlinewriter_p.h>
|
|
|
|
#include <QtQmlDom/private/qqmldomoutwriter_p.h>
|
|
|
|
#include <QtQmlDom/private/qqmldomtop_p.h>
|
2025-01-21 16:08:42 +00:00
|
|
|
#include <QtQmlToolingSettings/private/qqmltoolingsettings_p.h>
|
2025-01-27 11:06:07 +00:00
|
|
|
#include <QtQmlFormat/private/qqmlformatoptions_p.h>
|
2021-09-15 07:38:49 +00:00
|
|
|
|
2025-03-17 09:10:38 +00:00
|
|
|
#include "tst_qmlformat_base.h"
|
|
|
|
|
2021-09-15 07:38:49 +00:00
|
|
|
using namespace QQmlJS::Dom;
|
2019-12-13 15:10:46 +00:00
|
|
|
|
2025-03-13 08:53:29 +00:00
|
|
|
class TestQmlformat : public TestQmlformatBase
|
2019-12-13 15:10:46 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2021-08-06 10:27:35 +00:00
|
|
|
public:
|
2021-11-03 14:39:00 +00:00
|
|
|
enum class RunOption { OnCopy, OrigToCopy };
|
2021-08-06 10:27:35 +00:00
|
|
|
TestQmlformat();
|
|
|
|
|
2019-12-13 15:10:46 +00:00
|
|
|
private Q_SLOTS:
|
2020-01-15 10:25:18 +00:00
|
|
|
#if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled
|
|
|
|
void testExample();
|
|
|
|
void testExample_data();
|
2021-09-15 08:35:16 +00:00
|
|
|
void normalizeExample();
|
|
|
|
void normalizeExample_data();
|
2020-01-15 10:25:18 +00:00
|
|
|
#endif
|
2023-11-20 11:57:54 +00:00
|
|
|
void plainJS_data();
|
|
|
|
void plainJS();
|
2024-03-14 11:48:38 +00:00
|
|
|
|
|
|
|
void ecmascriptModule();
|
|
|
|
|
2025-03-17 08:48:53 +00:00
|
|
|
void qml_data();
|
|
|
|
void qml();
|
2025-01-24 12:51:04 +00:00
|
|
|
|
2019-12-13 15:10:46 +00:00
|
|
|
private:
|
2021-09-15 07:38:49 +00:00
|
|
|
QString formatInMemory(const QString &fileToFormat, bool *didSucceed = nullptr,
|
|
|
|
LineWriterOptions options = LineWriterOptions(),
|
|
|
|
WriteOutChecks extraChecks = WriteOutCheck::ReparseCompare,
|
|
|
|
WriteOutChecks largeChecks = WriteOutCheck::None);
|
2019-12-13 15:10:46 +00:00
|
|
|
};
|
|
|
|
|
2022-06-07 02:23:31 +00:00
|
|
|
// Don't fail on warnings because we read a lot of QML files that might intentionally be malformed.
|
2021-08-06 10:27:35 +00:00
|
|
|
TestQmlformat::TestQmlformat()
|
2025-03-13 08:53:29 +00:00
|
|
|
: TestQmlformatBase(QT_QMLTEST_DATADIR, FailOnWarningsPolicy::DoNotFailOnWarnings)
|
2021-08-06 10:27:35 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-11-20 11:57:54 +00:00
|
|
|
void TestQmlformat::plainJS_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("file");
|
|
|
|
QTest::addColumn<QString>("fileFormatted");
|
|
|
|
|
|
|
|
QTest::newRow("simpleStatement") << "simpleJSStatement.js"
|
|
|
|
<< "simpleJSStatement.formatted.js";
|
|
|
|
QTest::newRow("simpleFunction") << "simpleOnelinerJSFunc.js"
|
|
|
|
<< "simpleOnelinerJSFunc.formatted.js";
|
|
|
|
QTest::newRow("simpleLoop") << "simpleLoop.js"
|
|
|
|
<< "simpleLoop.formatted.js";
|
|
|
|
QTest::newRow("messyIfStatement") << "messyIfStatement.js"
|
|
|
|
<< "messyIfStatement.formatted.js";
|
|
|
|
QTest::newRow("lambdaFunctionWithLoop") << "lambdaFunctionWithLoop.js"
|
|
|
|
<< "lambdaFunctionWithLoop.formatted.js";
|
|
|
|
QTest::newRow("lambdaWithIfElse") << "lambdaWithIfElse.js"
|
|
|
|
<< "lambdaWithIfElse.formatted.js";
|
|
|
|
QTest::newRow("nestedLambdaWithIfElse") << "lambdaWithIfElseInsideLambda.js"
|
|
|
|
<< "lambdaWithIfElseInsideLambda.formatted.js";
|
|
|
|
QTest::newRow("twoFunctions") << "twoFunctions.js"
|
|
|
|
<< "twoFunctions.formatted.js";
|
|
|
|
QTest::newRow("pragma") << "pragma.js"
|
|
|
|
<< "pragma.formatted.js";
|
|
|
|
QTest::newRow("classConstructor") << "class.js"
|
|
|
|
<< "class.formatted.js";
|
|
|
|
QTest::newRow("legacyDirectives") << "directives.js"
|
|
|
|
<< "directives.formatted.js";
|
|
|
|
QTest::newRow("legacyDirectivesWithComments") << "directivesWithComments.js"
|
|
|
|
<< "directivesWithComments.formatted.js";
|
2025-01-28 09:33:45 +00:00
|
|
|
QTest::newRow("preserveOptionalTokens") << "preserveOptionalTokens.js"
|
|
|
|
<< "preserveOptionalTokens.formatted.js";
|
2025-01-28 15:45:28 +00:00
|
|
|
QTest::newRow("noSuperfluousSpaceInsertions.fail_pragma")
|
|
|
|
<< "noSuperfluousSpaceInsertions.fail_pragma.js"
|
|
|
|
<< "noSuperfluousSpaceInsertions.fail_pragma.formatted.js";
|
2025-01-29 14:51:09 +00:00
|
|
|
QTest::newRow("fromAsIdentifier") << "fromAsIdentifier.js"
|
|
|
|
<< "fromAsIdentifier.formatted.js";
|
2025-01-20 13:29:58 +00:00
|
|
|
QTest::newRow("caseWithComment") << "caseWithComment.js"
|
|
|
|
<< "caseWithComment.formatted.js";
|
2023-11-20 11:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestQmlformat::plainJS()
|
|
|
|
{
|
|
|
|
QFETCH(QString, file);
|
|
|
|
QFETCH(QString, fileFormatted);
|
|
|
|
|
|
|
|
bool wasSuccessful;
|
|
|
|
LineWriterOptions opts;
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
opts.lineEndings = QQmlJS::Dom::LineWriterOptions::LineEndings::Windows;
|
|
|
|
#endif
|
|
|
|
QString output = formatInMemory(testFile(file), &wasSuccessful, opts, WriteOutCheck::None);
|
|
|
|
|
|
|
|
QVERIFY(wasSuccessful && !output.isEmpty());
|
|
|
|
|
|
|
|
// TODO(QTBUG-119770)
|
|
|
|
QEXPECT_FAIL("legacyDirectivesWithComments", "see QTBUG-119770", Abort);
|
2025-01-28 15:45:28 +00:00
|
|
|
QEXPECT_FAIL("noSuperfluousSpaceInsertions.fail_pragma",
|
|
|
|
"Not all cases have been covered yet (QTBUG-133315)", Abort);
|
2023-11-20 11:57:54 +00:00
|
|
|
auto exp = readTestFile(fileFormatted);
|
2024-03-14 11:48:38 +00:00
|
|
|
QCOMPARE(output, exp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestQmlformat::ecmascriptModule()
|
|
|
|
{
|
|
|
|
QString file("esm.mjs");
|
|
|
|
QString formattedFile("esm.formatted.mjs");
|
|
|
|
|
|
|
|
bool wasSuccessful;
|
|
|
|
LineWriterOptions opts;
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
opts.lineEndings = QQmlJS::Dom::LineWriterOptions::LineEndings::Windows;
|
|
|
|
#endif
|
|
|
|
QString output = formatInMemory(testFile(file), &wasSuccessful, opts, WriteOutCheck::None);
|
|
|
|
|
|
|
|
QVERIFY(wasSuccessful && !output.isEmpty());
|
|
|
|
|
|
|
|
auto exp = readTestFile(formattedFile);
|
|
|
|
QCOMPARE(output, readTestFile(formattedFile));
|
2023-11-20 11:57:54 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 10:25:18 +00:00
|
|
|
#if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled
|
|
|
|
void TestQmlformat::testExample_data()
|
|
|
|
{
|
2021-04-19 14:43:21 +00:00
|
|
|
if (QTestPrivate::isRunningArmOnX86())
|
|
|
|
QSKIP("Crashes in QEMU. (timeout)");
|
2020-01-15 10:25:18 +00:00
|
|
|
QTest::addColumn<QString>("file");
|
|
|
|
|
|
|
|
QString examples = QLatin1String(SRCDIR) + "/../../../../examples/";
|
|
|
|
QString tests = QLatin1String(SRCDIR) + "/../../../../tests/";
|
|
|
|
|
2024-04-22 14:49:00 +00:00
|
|
|
QStringList exampleFiles;
|
|
|
|
QStringList testFiles;
|
2020-01-15 10:25:18 +00:00
|
|
|
QStringList files;
|
2024-04-22 14:49:00 +00:00
|
|
|
exampleFiles << findFiles(QDir(examples));
|
|
|
|
testFiles << findFiles(QDir(tests));
|
|
|
|
|
|
|
|
// Actually this test is an e2e test and not the unit test.
|
|
|
|
// At the moment of writing, CI lacks providing instruments for the automated tests
|
|
|
|
// which might be time-consuming, as for example this one.
|
|
|
|
// Therefore as part of QTBUG-122990 this test was copied to the /manual/e2e/qml/qmlformat
|
|
|
|
// however very small fraction of the test data is still preserved here for the sake of
|
|
|
|
// testing automatically at least a small part of the examples
|
|
|
|
const int nBatch = 10;
|
|
|
|
files << exampleFiles.mid(0, nBatch) << exampleFiles.mid(exampleFiles.size() / 2, nBatch)
|
|
|
|
<< exampleFiles.mid(exampleFiles.size() - nBatch, nBatch);
|
|
|
|
files << testFiles.mid(0, nBatch) << testFiles.mid(exampleFiles.size() / 2, nBatch)
|
|
|
|
<< testFiles.mid(exampleFiles.size() - nBatch, nBatch);
|
2020-01-15 10:25:18 +00:00
|
|
|
|
|
|
|
for (const QString &file : files)
|
|
|
|
QTest::newRow(qPrintable(file)) << file;
|
|
|
|
}
|
2021-09-15 08:35:16 +00:00
|
|
|
|
|
|
|
void TestQmlformat::normalizeExample_data()
|
|
|
|
{
|
|
|
|
if (QTestPrivate::isRunningArmOnX86())
|
|
|
|
QSKIP("Crashes in QEMU. (timeout)");
|
|
|
|
QTest::addColumn<QString>("file");
|
|
|
|
|
|
|
|
QString examples = QLatin1String(SRCDIR) + "/../../../../examples/";
|
|
|
|
QString tests = QLatin1String(SRCDIR) + "/../../../../tests/";
|
|
|
|
|
|
|
|
// normalizeExample is similar to testExample, so we test it only on nExamples + nTests
|
|
|
|
// files to avoid making too many
|
|
|
|
QStringList files;
|
|
|
|
const int nExamples = 10;
|
|
|
|
int i = 0;
|
|
|
|
for (const auto &f : findFiles(QDir(examples))) {
|
|
|
|
files << f;
|
|
|
|
if (++i == nExamples)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const int nTests = 10;
|
|
|
|
i = 0;
|
|
|
|
for (const auto &f : findFiles(QDir(tests))) {
|
|
|
|
files << f;
|
|
|
|
if (++i == nTests)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const QString &file : files)
|
|
|
|
QTest::newRow(qPrintable(file)) << file;
|
|
|
|
}
|
2020-01-15 10:25:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled
|
|
|
|
void TestQmlformat::testExample()
|
|
|
|
{
|
|
|
|
QFETCH(QString, file);
|
2020-11-14 13:30:42 +00:00
|
|
|
const bool isInvalid = isInvalidFile(QFileInfo(file));
|
2021-09-15 07:38:49 +00:00
|
|
|
bool wasSuccessful;
|
|
|
|
LineWriterOptions opts;
|
|
|
|
opts.attributesSequence = LineWriterOptions::AttributesSequence::Preserve;
|
|
|
|
QString output = formatInMemory(file, &wasSuccessful, opts);
|
2020-01-15 10:25:18 +00:00
|
|
|
|
2020-11-14 13:30:42 +00:00
|
|
|
if (!isInvalid)
|
2021-09-15 07:38:49 +00:00
|
|
|
QVERIFY(wasSuccessful && !output.isEmpty());
|
2020-01-15 10:25:18 +00:00
|
|
|
}
|
2021-09-15 08:35:16 +00:00
|
|
|
|
|
|
|
void TestQmlformat::normalizeExample()
|
|
|
|
{
|
|
|
|
QFETCH(QString, file);
|
|
|
|
const bool isInvalid = isInvalidFile(QFileInfo(file));
|
|
|
|
bool wasSuccessful;
|
|
|
|
LineWriterOptions opts;
|
|
|
|
opts.attributesSequence = LineWriterOptions::AttributesSequence::Normalize;
|
|
|
|
QString output = formatInMemory(file, &wasSuccessful, opts);
|
|
|
|
|
|
|
|
if (!isInvalid)
|
|
|
|
QVERIFY(wasSuccessful && !output.isEmpty());
|
|
|
|
}
|
2020-01-15 10:25:18 +00:00
|
|
|
#endif
|
|
|
|
|
2021-09-15 07:38:49 +00:00
|
|
|
QString TestQmlformat::formatInMemory(const QString &fileToFormat, bool *didSucceed,
|
|
|
|
LineWriterOptions options, WriteOutChecks extraChecks,
|
|
|
|
WriteOutChecks largeChecks)
|
|
|
|
{
|
2023-12-28 20:31:13 +00:00
|
|
|
auto env = DomEnvironment::create(
|
2021-09-15 07:38:49 +00:00
|
|
|
QStringList(), // as we load no dependencies we do not need any paths
|
|
|
|
QQmlJS::Dom::DomEnvironment::Option::SingleThreaded
|
|
|
|
| QQmlJS::Dom::DomEnvironment::Option::NoDependencies);
|
|
|
|
DomItem tFile;
|
2024-01-24 13:39:30 +00:00
|
|
|
env->loadFile(FileToLoad::fromFileSystem(env, fileToFormat),
|
|
|
|
[&tFile](Path, const DomItem &, const DomItem &newIt) { tFile = newIt; });
|
2024-01-08 16:52:18 +00:00
|
|
|
env->loadPendingDependencies();
|
2021-09-15 07:38:49 +00:00
|
|
|
MutableDomItem myFile = tFile.field(Fields::currentItem);
|
|
|
|
|
2025-04-10 13:43:17 +00:00
|
|
|
bool writtenOut = false;
|
2021-09-15 07:38:49 +00:00
|
|
|
QString resultStr;
|
|
|
|
if (myFile.field(Fields::isValid).value().toBool()) {
|
|
|
|
WriteOutChecks checks = extraChecks;
|
|
|
|
const qsizetype largeFileSize = 32000;
|
|
|
|
if (tFile.field(Fields::code).value().toString().size() > largeFileSize)
|
|
|
|
checks = largeChecks;
|
|
|
|
|
|
|
|
QTextStream res(&resultStr);
|
|
|
|
LineWriter lw([&res](QStringView s) { res << s; }, QLatin1String("*testStream*"), options);
|
|
|
|
OutWriter ow(lw);
|
|
|
|
ow.indentNextlines = true;
|
|
|
|
DomItem qmlFile = tFile.field(Fields::currentItem);
|
|
|
|
writtenOut = qmlFile.writeOutForFile(ow, checks);
|
|
|
|
lw.eof();
|
|
|
|
res.flush();
|
|
|
|
}
|
|
|
|
if (didSucceed)
|
QQmlJS::Dom::OutWriter. Refactoring
The refactoring consists of:
- Changing writeOut & writeOutForFile API
to return boolean instead of MutableDomItem, which better reflects
the existing usecases improving consistency of the data model*
Moreover, previous API was exposing DomItem, which was not "committed
to base" (MutableDomItem.commitToBase()), meaning it was exposing the
"unmerged" Item alongside with the "temporary environment"
- Refactoring & renaming OutWriter::updatedFile
breaking it into smaller chunks preserving
only necessary functionality
- Adding some comments / documentation
Before this commit, the writeOut API was "exposing",so called,
"updatedFile", which is basically the copy of the original fileItem +
renewed scriptExpressions which were modified during the writeOut of
the original fileItem.
The idea behind the "mutating" Dom API is that one has to create a
MutableDomItem, do some changes to it and then "commit" them.
This process is also facilitated by the creation of separate Env.
(git analogy might be handy here:
We create a separate branch, where all the mutation will happen and then
we "merge" this branch)
However, in the writeOutForFile usecase this "updatedFile" was needed
only for the verifying of the consistency of the "writtenOut" DOM,
however the API was exposing it further back to the caller sites,
without "committing".
The potential issue here is inconsistency of the data Model.
On one side we have an original File Item owned by the Base Env,
on the other side we have an "updatedFile" which is owned by another Env.
Taking into account that there are no usecases requiring "exposing"
"updatedFile", but also no need for "committing" the changes,
It's arguably better to keep that temporary "updatedFile" locally,
not exposing it outside the writeOutForFile function. Thereby improving
consistency of the data model.
Change-Id: If45eca4b4d6d703e2a76d0580f124d0292af5ed8
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
2023-12-05 09:42:23 +00:00
|
|
|
*didSucceed = writtenOut;
|
2021-09-15 07:38:49 +00:00
|
|
|
return resultStr;
|
|
|
|
}
|
|
|
|
|
2025-03-17 08:48:53 +00:00
|
|
|
void TestQmlformat::qml_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("file");
|
|
|
|
QTest::addColumn<QString>("fileFormatted");
|
|
|
|
|
|
|
|
QTest::newRow("example1") << "Example1.qml"
|
2025-03-17 08:52:52 +00:00
|
|
|
<< "Example1.formatted.qml";
|
2025-03-17 08:48:53 +00:00
|
|
|
QTest::newRow("annotation") << "Annotations.qml"
|
2025-03-17 08:52:52 +00:00
|
|
|
<< "Annotations.formatted.qml";
|
2025-03-17 08:48:53 +00:00
|
|
|
QTest::newRow("front inline") << "FrontInline.qml"
|
2025-03-17 08:52:52 +00:00
|
|
|
<< "FrontInline.formatted.qml";
|
2025-03-17 08:48:53 +00:00
|
|
|
QTest::newRow("if blocks") << "IfBlocks.qml"
|
2025-03-17 08:52:52 +00:00
|
|
|
<< "IfBlocks.formatted.qml";
|
|
|
|
QTest::newRow("read-only properties") << "readOnlyProps.qml"
|
|
|
|
<< "readOnlyProps.formatted.qml";
|
|
|
|
QTest::newRow("states and transitions") << "statesAndTransitions.qml"
|
|
|
|
<< "statesAndTransitions.formatted.qml";
|
|
|
|
QTest::newRow("large bindings") << "largeBindings.qml"
|
|
|
|
<< "largeBindings.formatted.qml";
|
|
|
|
QTest::newRow("verbatim strings") << "verbatimString.qml"
|
|
|
|
<< "verbatimString.formatted.qml";
|
|
|
|
QTest::newRow("inline components") << "inlineComponents.qml"
|
|
|
|
<< "inlineComponents.formatted.qml";
|
2025-03-17 08:48:53 +00:00
|
|
|
QTest::newRow("nested ifs") << "nestedIf.qml"
|
2025-03-17 08:52:52 +00:00
|
|
|
<< "nestedIf.formatted.qml";
|
2025-03-17 08:48:53 +00:00
|
|
|
QTest::newRow("QTBUG-85003") << "QtBug85003.qml"
|
2025-03-17 08:52:52 +00:00
|
|
|
<< "QtBug85003.formatted.qml";
|
|
|
|
QTest::newRow("nested functions") << "nestedFunctions.qml"
|
|
|
|
<< "nestedFunctions.formatted.qml";
|
|
|
|
QTest::newRow("multiline comments") << "multilineComment.qml"
|
|
|
|
<< "multilineComment.formatted.qml";
|
2025-03-17 08:48:53 +00:00
|
|
|
QTest::newRow("for of") << "forOf.qml"
|
2025-03-17 08:52:52 +00:00
|
|
|
<< "forOf.formatted.qml";
|
|
|
|
QTest::newRow("property names") << "propertyNames.qml"
|
|
|
|
<< "propertyNames.formatted.qml";
|
2025-03-17 08:48:53 +00:00
|
|
|
QTest::newRow("empty object") << "emptyObject.qml"
|
2025-03-17 08:52:52 +00:00
|
|
|
<< "emptyObject.formatted.qml";
|
|
|
|
QTest::newRow("arrow functions") << "arrowFunctions.qml"
|
|
|
|
<< "arrowFunctions.formatted.qml";
|
|
|
|
QTest::newRow("forWithLet") << "forWithLet.qml"
|
|
|
|
<< "forWithLet.formatted.qml";
|
|
|
|
QTest::newRow("dontRemoveComments") << "dontRemoveComments.qml"
|
|
|
|
<< "dontRemoveComments.formatted.qml";
|
|
|
|
QTest::newRow("ecmaScriptClassInQml") << "ecmaScriptClassInQml.qml"
|
|
|
|
<< "ecmaScriptClassInQml.formatted.qml";
|
|
|
|
QTest::newRow("arrowFunctionWithBinding") << "arrowFunctionWithBinding.qml"
|
|
|
|
<< "arrowFunctionWithBinding.formatted.qml";
|
|
|
|
QTest::newRow("blanklinesAfterComment") << "blanklinesAfterComment.qml"
|
|
|
|
<< "blanklinesAfterComment.formatted.qml";
|
|
|
|
QTest::newRow("pragmaValueList") << "pragma.qml"
|
|
|
|
<< "pragma.formatted.qml";
|
|
|
|
QTest::newRow("objectDestructuring") << "objectDestructuring.qml"
|
|
|
|
<< "objectDestructuring.formatted.qml";
|
2025-03-17 08:48:53 +00:00
|
|
|
QTest::newRow("destructuringFunctionParameter")
|
|
|
|
<< "destructuringFunctionParameter.qml"
|
2025-03-17 08:52:52 +00:00
|
|
|
<< "destructuringFunctionParameter.formatted.qml";
|
|
|
|
QTest::newRow("ellipsisFunctionArgument") << "ellipsisFunctionArgument.qml"
|
|
|
|
<< "ellipsisFunctionArgument.formatted.qml";
|
|
|
|
QTest::newRow("importStatements") << "importStatements.qml"
|
|
|
|
<< "importStatements.formatted.qml";
|
|
|
|
QTest::newRow("arrayEndComma") << "arrayEndComma.qml"
|
|
|
|
<< "arrayEndComma.formatted.qml";
|
|
|
|
QTest::newRow("escapeChars") << "escapeChars.qml"
|
|
|
|
<< "escapeChars.formatted.qml";
|
|
|
|
QTest::newRow("javascriptBlock") << "javascriptBlock.qml"
|
|
|
|
<< "javascriptBlock.formatted.qml";
|
|
|
|
QTest::newRow("enumWithValues") << "enumWithValues.qml"
|
|
|
|
<< "enumWithValues.formatted.qml";
|
|
|
|
QTest::newRow("typeAnnotatedSignal") << "signal.qml"
|
|
|
|
<< "signal.formatted.qml";
|
|
|
|
// plainJS
|
|
|
|
QTest::newRow("nestedLambdaWithIfElse") << "lambdaWithIfElseInsideLambda.js"
|
|
|
|
<< "lambdaWithIfElseInsideLambda.formatted.js";
|
|
|
|
QTest::newRow("noSuperfluousSpaceInsertions") << "noSuperfluousSpaceInsertions.qml"
|
|
|
|
<< "noSuperfluousSpaceInsertions.formatted.qml";
|
2025-03-17 08:48:53 +00:00
|
|
|
QTest::newRow("noSuperfluousSpaceInsertions.fail_id")
|
|
|
|
<< "noSuperfluousSpaceInsertions.fail_id.qml"
|
2025-03-17 08:52:52 +00:00
|
|
|
<< "noSuperfluousSpaceInsertions.fail_id.formatted.qml";
|
2025-03-17 08:48:53 +00:00
|
|
|
QTest::newRow("noSuperfluousSpaceInsertions.fail_QtObject")
|
|
|
|
<< "noSuperfluousSpaceInsertions.fail_QtObject.qml"
|
2025-03-17 08:52:52 +00:00
|
|
|
<< "noSuperfluousSpaceInsertions.fail_QtObject.formatted.qml";
|
2025-03-17 08:48:53 +00:00
|
|
|
QTest::newRow("noSuperfluousSpaceInsertions.fail_signal")
|
|
|
|
<< "noSuperfluousSpaceInsertions.fail_signal.qml"
|
2025-03-17 08:52:52 +00:00
|
|
|
<< "noSuperfluousSpaceInsertions.fail_signal.formatted.qml";
|
2025-03-17 08:48:53 +00:00
|
|
|
QTest::newRow("noSuperfluousSpaceInsertions.fail_enum")
|
|
|
|
<< "noSuperfluousSpaceInsertions.fail_enum.qml"
|
2025-03-17 08:52:52 +00:00
|
|
|
<< "noSuperfluousSpaceInsertions.fail_enum.formatted.qml";
|
2025-03-17 08:48:53 +00:00
|
|
|
QTest::newRow("noSuperfluousSpaceInsertions.fail_parameters")
|
|
|
|
<< "noSuperfluousSpaceInsertions.fail_parameters.qml"
|
2025-03-17 08:52:52 +00:00
|
|
|
<< "noSuperfluousSpaceInsertions.fail_parameters.formatted.qml";
|
2025-03-17 08:48:53 +00:00
|
|
|
QTest::newRow("nonInitializedPropertyInComponent")
|
|
|
|
<< "nonInitializedPropertyInComponent.qml"
|
2025-03-17 08:52:52 +00:00
|
|
|
<< "nonInitializedPropertyInComponent.formatted.qml";
|
|
|
|
QTest::newRow("fromAsIdentifier") << "fromAsIdentifier.qml"
|
|
|
|
<< "fromAsIdentifier.formatted.qml";
|
|
|
|
QTest::newRow("finalProperties") << "finalProperties.qml"
|
|
|
|
<< "finalProperties.formatted.qml";
|
2025-03-17 08:48:53 +00:00
|
|
|
}
|
|
|
|
void TestQmlformat::qml()
|
|
|
|
{
|
|
|
|
QFETCH(QString, file);
|
|
|
|
QFETCH(QString, fileFormatted);
|
|
|
|
|
|
|
|
bool wasSuccessful;
|
|
|
|
LineWriterOptions opts;
|
|
|
|
opts.attributesSequence = LineWriterOptions::AttributesSequence::Preserve;
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
opts.lineEndings = QQmlJS::Dom::LineWriterOptions::LineEndings::Windows;
|
|
|
|
#endif
|
|
|
|
QString output = formatInMemory(testFile(file), &wasSuccessful, opts, WriteOutCheck::None);
|
|
|
|
QVERIFY(wasSuccessful && !output.isEmpty());
|
|
|
|
auto exp = readTestFile(fileFormatted);
|
|
|
|
QEXPECT_FAIL("noSuperfluousSpaceInsertions.fail_id",
|
|
|
|
"Not all cases have been covered yet (QTBUG-133315, QTBUG-123386)", Abort);
|
|
|
|
QEXPECT_FAIL("noSuperfluousSpaceInsertions.fail_QtObject",
|
|
|
|
"Not all cases have been covered yet (QTBUG-133315, QTBUG-123386)", Abort);
|
|
|
|
QEXPECT_FAIL("noSuperfluousSpaceInsertions.fail_signal",
|
|
|
|
"Not all cases have been covered yet (QTBUG-133315, QTBUG-123386)", Abort);
|
|
|
|
QEXPECT_FAIL("noSuperfluousSpaceInsertions.fail_enum",
|
|
|
|
"Not all cases have been covered yet (QTBUG-133315, QTBUG-123386)", Abort);
|
|
|
|
QEXPECT_FAIL("noSuperfluousSpaceInsertions.fail_parameters",
|
|
|
|
"Not all cases have been covered yet (QTBUG-133315, QTBUG-123386)", Abort);
|
|
|
|
QCOMPARE(output, exp);
|
|
|
|
}
|
|
|
|
|
2019-12-13 15:10:46 +00:00
|
|
|
QTEST_MAIN(TestQmlformat)
|
|
|
|
#include "tst_qmlformat.moc"
|