forked from qt-creator/qt-creator
Fix tst_qml_reformatter auto test
Add source location to pragma library writer so that the comments before .pragma line are also written. Fix tst_qml_reformatter by skipping the blankline comparisons. Line by line comparison with the non-formatted code is not a good idea to test reformatting. Ideally test should have compared the formatted file with the original one character wise, yet it is not worth changing into that at this point. Amends 0ce57fcf5e90f8bf8cfbe681f2954a0c1ef0e945 Change-Id: I39bcee2c881e1a0928c17ebb45aa1c85e6cf3b99 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -101,16 +101,16 @@ public:
|
||||
_hadEmptyLine = false;
|
||||
_binaryExpDepth = 0;
|
||||
|
||||
|
||||
const QString &source = _doc->source();
|
||||
// emit directives
|
||||
if (_doc->bind()->isJsLibrary()) {
|
||||
out(QLatin1String(".pragma library"));
|
||||
const QLatin1String pragmaLine(".pragma library");
|
||||
out(pragmaLine, SourceLocation(source.indexOf(".pragma"), pragmaLine.length()));
|
||||
newLine();
|
||||
}
|
||||
const QList<SourceLocation> &directives = _doc->jsDirectives();
|
||||
for (const auto &d: directives) {
|
||||
quint32 line = 0;
|
||||
const QString &source = _doc->source();
|
||||
int i = -1;
|
||||
while (++line < d.startLine)
|
||||
i = source.indexOf(QChar('\n'), i + 1);
|
||||
|
@@ -68,25 +68,15 @@ void tst_Reformatter::test()
|
||||
|
||||
QString rewritten = reformat(doc);
|
||||
|
||||
QStringList sourceLines = source.split(QLatin1Char('\n'));
|
||||
QStringList newLines = rewritten.split(QLatin1Char('\n'));
|
||||
QStringList sourceLines = source.split(QLatin1Char('\n'), Qt::SkipEmptyParts);
|
||||
QStringList newLines = rewritten.split(QLatin1Char('\n'), Qt::SkipEmptyParts);
|
||||
|
||||
// compare line by line
|
||||
int commonLines = qMin(newLines.size(), sourceLines.size());
|
||||
bool insideMultiLineComment = false;
|
||||
for (int i = 0; i < commonLines; ++i) {
|
||||
// names intentional to make 'Actual (sourceLine): ...\nExpected (newLinee): ...' line up
|
||||
const QString &sourceLine = sourceLines.at(i);
|
||||
const QString &newLinee = newLines.at(i);
|
||||
if (!insideMultiLineComment && sourceLine.trimmed().startsWith("/*")) {
|
||||
insideMultiLineComment = true;
|
||||
sourceLines.insert(i, "\n");
|
||||
continue;
|
||||
}
|
||||
if (sourceLine.trimmed().endsWith("*/"))
|
||||
insideMultiLineComment = false;
|
||||
if (sourceLine.trimmed().isEmpty() && newLinee.trimmed().isEmpty())
|
||||
continue;
|
||||
bool fail = !QCOMPARE_NOEXIT(newLinee, sourceLine);
|
||||
if (fail) {
|
||||
qDebug() << "in line" << (i + 1);
|
||||
|
Reference in New Issue
Block a user