diff --git a/src/libs/qmljs/qmljsreformatter.cpp b/src/libs/qmljs/qmljsreformatter.cpp index 097119eb270..bad58e414ca 100644 --- a/src/libs/qmljs/qmljsreformatter.cpp +++ b/src/libs/qmljs/qmljsreformatter.cpp @@ -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 &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); diff --git a/tests/auto/qml/reformatter/tst_reformatter.cpp b/tests/auto/qml/reformatter/tst_reformatter.cpp index 42d98e02bed..68b192fa600 100644 --- a/tests/auto/qml/reformatter/tst_reformatter.cpp +++ b/tests/auto/qml/reformatter/tst_reformatter.cpp @@ -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);