2013-02-15 12:49:50 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2013-02-15 12:49:50 +01:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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 Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2013-02-15 12:49:50 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2013-02-15 12:49:50 +01:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "diffeditorplugin.h"
|
2013-05-30 12:15:22 +02:00
|
|
|
#include "diffeditor.h"
|
2013-02-15 12:49:50 +01:00
|
|
|
#include "diffeditorconstants.h"
|
2014-02-13 16:43:28 +01:00
|
|
|
#include "diffeditordocument.h"
|
2013-06-17 13:55:31 +02:00
|
|
|
#include "diffeditorfactory.h"
|
2014-02-11 13:00:35 +01:00
|
|
|
#include "diffeditormanager.h"
|
2014-02-13 16:43:28 +01:00
|
|
|
#include "diffeditorreloader.h"
|
|
|
|
|
#include "differ.h"
|
2013-02-15 12:49:50 +01:00
|
|
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include <QTextCodec>
|
2013-05-07 14:02:08 +02:00
|
|
|
#include <QtPlugin>
|
2013-02-15 12:49:50 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2014-01-30 16:37:21 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2013-02-15 12:49:50 +01:00
|
|
|
|
2013-02-21 17:03:00 +01:00
|
|
|
namespace DiffEditor {
|
2013-05-07 14:02:08 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
class SimpleDiffEditorReloader : public DiffEditorReloader
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2014-10-24 14:11:12 +02:00
|
|
|
SimpleDiffEditorReloader(const QString &leftFileName,
|
2014-02-13 16:43:28 +01:00
|
|
|
const QString &rightFileName);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void reload();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QString m_leftFileName;
|
|
|
|
|
QString m_rightFileName;
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-24 14:11:12 +02:00
|
|
|
SimpleDiffEditorReloader::SimpleDiffEditorReloader(const QString &leftFileName,
|
2014-02-13 16:43:28 +01:00
|
|
|
const QString &rightFileName)
|
2014-10-24 14:11:12 +02:00
|
|
|
: m_leftFileName(leftFileName),
|
2014-02-13 16:43:28 +01:00
|
|
|
m_rightFileName(rightFileName)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SimpleDiffEditorReloader::reload()
|
|
|
|
|
{
|
2014-06-30 15:04:36 +02:00
|
|
|
QString errorString;
|
|
|
|
|
Utils::TextFileFormat format;
|
|
|
|
|
format.codec = Core::EditorManager::defaultTextCodec();
|
|
|
|
|
|
|
|
|
|
QString leftText;
|
|
|
|
|
if (Utils::TextFileFormat::readFile(m_leftFileName,
|
|
|
|
|
format.codec,
|
|
|
|
|
&leftText, &format, &errorString)
|
|
|
|
|
!= Utils::TextFileFormat::ReadSuccess) {
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString rightText;
|
|
|
|
|
if (Utils::TextFileFormat::readFile(m_rightFileName,
|
|
|
|
|
format.codec,
|
|
|
|
|
&rightText, &format, &errorString)
|
|
|
|
|
!= Utils::TextFileFormat::ReadSuccess) {
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
Differ differ;
|
|
|
|
|
QList<Diff> diffList = differ.cleanupSemantics(
|
|
|
|
|
differ.diff(leftText, rightText));
|
|
|
|
|
|
|
|
|
|
QList<Diff> leftDiffList;
|
|
|
|
|
QList<Diff> rightDiffList;
|
|
|
|
|
Differ::splitDiffList(diffList, &leftDiffList, &rightDiffList);
|
|
|
|
|
QList<Diff> outputLeftDiffList;
|
|
|
|
|
QList<Diff> outputRightDiffList;
|
|
|
|
|
|
2014-07-07 10:23:11 +02:00
|
|
|
if (controller()->isIgnoreWhitespace()) {
|
2014-02-13 16:43:28 +01:00
|
|
|
const QList<Diff> leftIntermediate =
|
|
|
|
|
Differ::moveWhitespaceIntoEqualities(leftDiffList);
|
|
|
|
|
const QList<Diff> rightIntermediate =
|
|
|
|
|
Differ::moveWhitespaceIntoEqualities(rightDiffList);
|
|
|
|
|
Differ::ignoreWhitespaceBetweenEqualities(leftIntermediate,
|
|
|
|
|
rightIntermediate,
|
|
|
|
|
&outputLeftDiffList,
|
|
|
|
|
&outputRightDiffList);
|
|
|
|
|
} else {
|
|
|
|
|
outputLeftDiffList = leftDiffList;
|
|
|
|
|
outputRightDiffList = rightDiffList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ChunkData chunkData = DiffUtils::calculateOriginalData(
|
|
|
|
|
outputLeftDiffList, outputRightDiffList);
|
|
|
|
|
FileData fileData = DiffUtils::calculateContextData(
|
2014-07-07 10:23:11 +02:00
|
|
|
chunkData, controller()->contextLinesNumber(), 0);
|
2014-02-13 16:43:28 +01:00
|
|
|
fileData.leftFileInfo.fileName = m_leftFileName;
|
|
|
|
|
fileData.rightFileInfo.fileName = m_rightFileName;
|
|
|
|
|
|
|
|
|
|
QList<FileData> fileDataList;
|
|
|
|
|
fileDataList << fileData;
|
|
|
|
|
|
2014-07-11 12:55:31 +02:00
|
|
|
controller()->requestSaveState();
|
2014-07-07 10:23:11 +02:00
|
|
|
controller()->setDiffFiles(fileDataList);
|
2014-07-11 12:55:31 +02:00
|
|
|
controller()->requestRestoreState();
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
reloadFinished();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////
|
|
|
|
|
|
2013-02-15 12:49:50 +01:00
|
|
|
DiffEditorPlugin::DiffEditorPlugin()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DiffEditorPlugin::~DiffEditorPlugin()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DiffEditorPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(arguments)
|
|
|
|
|
Q_UNUSED(errorMessage)
|
|
|
|
|
|
|
|
|
|
//register actions
|
|
|
|
|
Core::ActionContainer *toolsContainer =
|
|
|
|
|
Core::ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
2014-02-13 16:43:28 +01:00
|
|
|
toolsContainer->insertGroup(Core::Constants::G_TOOLS_OPTIONS,
|
|
|
|
|
Constants::G_TOOLS_DIFF);
|
2013-02-15 12:49:50 +01:00
|
|
|
|
|
|
|
|
Core::Context globalcontext(Core::Constants::C_GLOBAL);
|
|
|
|
|
|
|
|
|
|
QAction *diffAction = new QAction(tr("Diff..."), this);
|
|
|
|
|
Core::Command *diffCommand = Core::ActionManager::registerAction(diffAction,
|
|
|
|
|
"DiffEditor.Diff", globalcontext);
|
|
|
|
|
connect(diffAction, SIGNAL(triggered()), this, SLOT(diff()));
|
|
|
|
|
toolsContainer->addAction(diffCommand, Constants::G_TOOLS_DIFF);
|
|
|
|
|
|
|
|
|
|
addAutoReleasedObject(new DiffEditorFactory(this));
|
|
|
|
|
|
2014-02-11 13:00:35 +01:00
|
|
|
new DiffEditorManager(this);
|
|
|
|
|
|
2013-02-15 12:49:50 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiffEditorPlugin::extensionsInitialized()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiffEditorPlugin::diff()
|
|
|
|
|
{
|
2014-01-30 16:37:21 +01:00
|
|
|
QString fileName1 = QFileDialog::getOpenFileName(Core::ICore::dialogParent(),
|
2013-02-20 08:51:36 +01:00
|
|
|
tr("Select First File for Diff"),
|
2013-02-15 12:49:50 +01:00
|
|
|
QString());
|
|
|
|
|
if (fileName1.isNull())
|
|
|
|
|
return;
|
|
|
|
|
|
2014-01-30 16:37:21 +01:00
|
|
|
QString fileName2 = QFileDialog::getOpenFileName(Core::ICore::dialogParent(),
|
2013-02-20 08:51:36 +01:00
|
|
|
tr("Select Second File for Diff"),
|
2013-02-15 12:49:50 +01:00
|
|
|
QString());
|
|
|
|
|
if (fileName2.isNull())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
const QString documentId = QLatin1String("Diff ") + fileName1
|
|
|
|
|
+ QLatin1String(", ") + fileName2;
|
2014-07-04 13:55:51 +02:00
|
|
|
QString title = tr("Diff \"%1\", \"%2\"").arg(fileName1).arg(fileName2);
|
2014-11-19 10:25:46 +01:00
|
|
|
DiffEditorDocument * const document = DiffEditorManager::findOrCreate(documentId, title);
|
2014-07-04 13:55:51 +02:00
|
|
|
if (!document)
|
|
|
|
|
return;
|
2013-05-23 13:36:27 +02:00
|
|
|
|
2014-07-04 13:55:51 +02:00
|
|
|
DiffEditorController *controller = document->controller();
|
|
|
|
|
if (!controller->reloader()) {
|
2014-02-13 16:43:28 +01:00
|
|
|
SimpleDiffEditorReloader *reloader =
|
2014-10-24 14:11:12 +02:00
|
|
|
new SimpleDiffEditorReloader(fileName1, fileName2);
|
2014-07-04 13:55:51 +02:00
|
|
|
controller->setReloader(reloader);
|
2014-02-13 16:43:28 +01:00
|
|
|
}
|
2013-05-23 13:36:27 +02:00
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
Core::EditorManager::activateEditorForDocument(document);
|
2013-05-23 13:36:27 +02:00
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
document->controller()->requestReload();
|
2013-02-15 12:49:50 +01:00
|
|
|
}
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace DiffEditor
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
|
|
|
|
|
#include <QTest>
|
|
|
|
|
|
|
|
|
|
#include "diffutils.h"
|
|
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(DiffEditor::ChunkData)
|
|
|
|
|
Q_DECLARE_METATYPE(QList<DiffEditor::FileData>)
|
|
|
|
|
|
2014-07-26 22:57:42 +03:00
|
|
|
static inline QString _(const char *string) { return QString::fromLatin1(string); }
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data()
|
2013-02-15 12:49:50 +01:00
|
|
|
{
|
2014-02-13 16:43:28 +01:00
|
|
|
QTest::addColumn<ChunkData>("sourceChunk");
|
|
|
|
|
QTest::addColumn<QString>("leftFileName");
|
|
|
|
|
QTest::addColumn<QString>("rightFileName");
|
|
|
|
|
QTest::addColumn<bool>("lastChunk");
|
|
|
|
|
QTest::addColumn<QString>("patchText");
|
|
|
|
|
|
2014-07-26 22:57:42 +03:00
|
|
|
const QString fileName = _("a.txt");
|
|
|
|
|
const QString header = _("--- ") + fileName + _("\n+++ ") + fileName + _("\n");
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
QList<RowData> rows;
|
2014-07-26 22:57:42 +03:00
|
|
|
rows << RowData(_("ABCD"), TextLineData::Separator);
|
|
|
|
|
rows << RowData(_("EFGH"));
|
2014-02-13 16:43:28 +01:00
|
|
|
ChunkData chunk;
|
|
|
|
|
chunk.rows = rows;
|
2014-07-26 22:57:42 +03:00
|
|
|
QString patchText = header + _("@@ -1,2 +1,1 @@\n"
|
|
|
|
|
"-ABCD\n"
|
|
|
|
|
" EFGH\n");
|
2014-07-09 12:37:47 +02:00
|
|
|
QTest::newRow("Simple not a last chunk") << chunk
|
|
|
|
|
<< fileName
|
|
|
|
|
<< fileName
|
|
|
|
|
<< false
|
|
|
|
|
<< patchText;
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
|
|
|
|
|
|
// chunk the same here
|
2014-07-26 22:57:42 +03:00
|
|
|
patchText = header + _("@@ -1,2 +1,1 @@\n"
|
|
|
|
|
"-ABCD\n"
|
|
|
|
|
" EFGH\n"
|
|
|
|
|
"\\ No newline at end of file\n");
|
2014-07-09 12:37:47 +02:00
|
|
|
|
|
|
|
|
QTest::newRow("Simple last chunk") << chunk
|
2014-02-13 16:43:28 +01:00
|
|
|
<< fileName
|
|
|
|
|
<< fileName
|
|
|
|
|
<< true
|
|
|
|
|
<< patchText;
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
|
|
|
|
|
|
rows.clear();
|
2014-07-26 22:57:42 +03:00
|
|
|
rows << RowData(_("ABCD"));
|
|
|
|
|
rows << RowData(_(""), TextLineData::Separator);
|
2014-02-13 16:43:28 +01:00
|
|
|
chunk.rows = rows;
|
2014-07-26 22:57:42 +03:00
|
|
|
patchText = header + _("@@ -1,1 +1,1 @@\n"
|
|
|
|
|
"-ABCD\n"
|
|
|
|
|
"+ABCD\n"
|
|
|
|
|
"\\ No newline at end of file\n");
|
2014-02-13 16:43:28 +01:00
|
|
|
|
2014-07-09 12:37:47 +02:00
|
|
|
QTest::newRow("EOL in last line removed") << chunk
|
2014-02-13 16:43:28 +01:00
|
|
|
<< fileName
|
|
|
|
|
<< fileName
|
|
|
|
|
<< true
|
|
|
|
|
<< patchText;
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
|
|
|
|
|
|
// chunk the same here
|
2014-07-26 22:57:42 +03:00
|
|
|
patchText = header + _("@@ -1,2 +1,1 @@\n"
|
|
|
|
|
" ABCD\n"
|
|
|
|
|
"-\n");
|
2014-02-13 16:43:28 +01:00
|
|
|
|
2014-07-09 12:37:47 +02:00
|
|
|
QTest::newRow("Last empty line removed") << chunk
|
2014-02-13 16:43:28 +01:00
|
|
|
<< fileName
|
|
|
|
|
<< fileName
|
|
|
|
|
<< false
|
|
|
|
|
<< patchText;
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
|
|
2014-08-06 15:03:26 +03:00
|
|
|
rows.clear();
|
|
|
|
|
rows << RowData(_("ABCD"));
|
|
|
|
|
rows << RowData(_(""), TextLineData::Separator);
|
|
|
|
|
rows << RowData(_(""), TextLineData::Separator);
|
|
|
|
|
chunk.rows = rows;
|
|
|
|
|
patchText = header + _("@@ -1,2 +1,1 @@\n"
|
|
|
|
|
"-ABCD\n"
|
|
|
|
|
"-\n"
|
|
|
|
|
"+ABCD\n"
|
|
|
|
|
"\\ No newline at end of file\n");
|
|
|
|
|
|
|
|
|
|
QTest::newRow("Two last EOLs removed") << chunk
|
|
|
|
|
<< fileName
|
|
|
|
|
<< fileName
|
|
|
|
|
<< true
|
|
|
|
|
<< patchText;
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
rows.clear();
|
2014-07-26 22:57:42 +03:00
|
|
|
rows << RowData(_("ABCD"));
|
|
|
|
|
rows << RowData(TextLineData::Separator, _(""));
|
2014-02-13 16:43:28 +01:00
|
|
|
chunk.rows = rows;
|
2014-07-26 22:57:42 +03:00
|
|
|
patchText = header + _("@@ -1,1 +1,1 @@\n"
|
|
|
|
|
"-ABCD\n"
|
|
|
|
|
"\\ No newline at end of file\n"
|
|
|
|
|
"+ABCD\n");
|
2014-02-13 16:43:28 +01:00
|
|
|
|
2014-07-09 12:37:47 +02:00
|
|
|
QTest::newRow("EOL to last line added") << chunk
|
2014-02-13 16:43:28 +01:00
|
|
|
<< fileName
|
|
|
|
|
<< fileName
|
|
|
|
|
<< true
|
|
|
|
|
<< patchText;
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
|
|
|
|
|
|
// chunk the same here
|
2014-07-26 22:57:42 +03:00
|
|
|
patchText = header + _("@@ -1,1 +1,2 @@\n"
|
|
|
|
|
" ABCD\n"
|
|
|
|
|
"+\n");
|
2014-02-13 16:43:28 +01:00
|
|
|
|
2014-07-09 12:37:47 +02:00
|
|
|
QTest::newRow("Last empty line added") << chunk
|
2014-02-13 16:43:28 +01:00
|
|
|
<< fileName
|
|
|
|
|
<< fileName
|
|
|
|
|
<< false
|
|
|
|
|
<< patchText;
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
|
|
|
|
|
|
rows.clear();
|
2014-07-26 22:57:42 +03:00
|
|
|
rows << RowData(_("ABCD"), _("EFGH"));
|
2014-02-13 16:43:28 +01:00
|
|
|
chunk.rows = rows;
|
2014-07-26 22:57:42 +03:00
|
|
|
patchText = header + _("@@ -1,1 +1,1 @@\n"
|
|
|
|
|
"-ABCD\n"
|
|
|
|
|
"+EFGH\n");
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
QTest::newRow("Last line with a newline modified") << chunk
|
|
|
|
|
<< fileName
|
|
|
|
|
<< fileName
|
2014-07-09 12:37:47 +02:00
|
|
|
<< false
|
2014-02-13 16:43:28 +01:00
|
|
|
<< patchText;
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
|
|
2014-07-09 12:37:47 +02:00
|
|
|
rows.clear();
|
2014-07-26 22:57:42 +03:00
|
|
|
rows << RowData(_("ABCD"), _("EFGH"));
|
|
|
|
|
rows << RowData(_(""));
|
2014-07-09 12:37:47 +02:00
|
|
|
chunk.rows = rows;
|
2014-07-26 22:57:42 +03:00
|
|
|
patchText = header + _("@@ -1,2 +1,2 @@\n"
|
|
|
|
|
"-ABCD\n"
|
|
|
|
|
"+EFGH\n"
|
|
|
|
|
" \n");
|
2014-02-13 16:43:28 +01:00
|
|
|
QTest::newRow("Not a last line with a newline modified") << chunk
|
|
|
|
|
<< fileName
|
|
|
|
|
<< fileName
|
|
|
|
|
<< false
|
|
|
|
|
<< patchText;
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
|
|
|
|
|
|
rows.clear();
|
2014-07-26 22:57:42 +03:00
|
|
|
rows << RowData(_("ABCD"), _("EFGH"));
|
2014-02-13 16:43:28 +01:00
|
|
|
chunk.rows = rows;
|
2014-07-26 22:57:42 +03:00
|
|
|
patchText = header + _("@@ -1,1 +1,1 @@\n"
|
|
|
|
|
"-ABCD\n"
|
|
|
|
|
"\\ No newline at end of file\n"
|
|
|
|
|
"+EFGH\n"
|
|
|
|
|
"\\ No newline at end of file\n");
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
QTest::newRow("Last line without a newline modified") << chunk
|
|
|
|
|
<< fileName
|
|
|
|
|
<< fileName
|
|
|
|
|
<< true
|
|
|
|
|
<< patchText;
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
|
|
|
|
|
|
// chunk the same here
|
2014-07-26 22:57:42 +03:00
|
|
|
patchText = header + _("@@ -1,1 +1,1 @@\n"
|
|
|
|
|
"-ABCD\n"
|
|
|
|
|
"+EFGH\n");
|
2014-02-13 16:43:28 +01:00
|
|
|
QTest::newRow("Not a last line without a newline modified") << chunk
|
|
|
|
|
<< fileName
|
|
|
|
|
<< fileName
|
|
|
|
|
<< false
|
|
|
|
|
<< patchText;
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
|
|
|
|
|
|
rows.clear();
|
2014-07-26 22:57:42 +03:00
|
|
|
rows << RowData(_("ABCD"), _("EFGH"));
|
|
|
|
|
rows << RowData(_("IJKL"));
|
2014-02-13 16:43:28 +01:00
|
|
|
chunk.rows = rows;
|
2014-07-26 22:57:42 +03:00
|
|
|
patchText = header + _("@@ -1,2 +1,2 @@\n"
|
|
|
|
|
"-ABCD\n"
|
|
|
|
|
"+EFGH\n"
|
|
|
|
|
" IJKL\n"
|
|
|
|
|
"\\ No newline at end of file\n");
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
QTest::newRow("Last but one line modified, last line without a newline")
|
|
|
|
|
<< chunk
|
|
|
|
|
<< fileName
|
|
|
|
|
<< fileName
|
|
|
|
|
<< true
|
|
|
|
|
<< patchText;
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
|
|
|
|
|
|
// chunk the same here
|
2014-07-26 22:57:42 +03:00
|
|
|
patchText = header + _("@@ -1,2 +1,2 @@\n"
|
|
|
|
|
"-ABCD\n"
|
|
|
|
|
"+EFGH\n"
|
|
|
|
|
" IJKL\n");
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
QTest::newRow("Last but one line modified, last line with a newline")
|
|
|
|
|
<< chunk
|
|
|
|
|
<< fileName
|
|
|
|
|
<< fileName
|
|
|
|
|
<< false
|
|
|
|
|
<< patchText;
|
2014-08-06 15:03:26 +03:00
|
|
|
|
|
|
|
|
///////////
|
|
|
|
|
|
|
|
|
|
rows.clear();
|
|
|
|
|
rows << RowData(_("ABCD"));
|
|
|
|
|
rows << RowData(TextLineData::Separator, _(""));
|
|
|
|
|
rows << RowData(_(""), _("EFGH"));
|
|
|
|
|
chunk.rows = rows;
|
|
|
|
|
patchText = header + _("@@ -1,1 +1,3 @@\n"
|
|
|
|
|
" ABCD\n"
|
|
|
|
|
"+\n"
|
|
|
|
|
"+EFGH\n"
|
|
|
|
|
"\\ No newline at end of file\n");
|
|
|
|
|
|
|
|
|
|
QTest::newRow("Blank line followed by No newline")
|
|
|
|
|
<< chunk
|
|
|
|
|
<< fileName
|
|
|
|
|
<< fileName
|
|
|
|
|
<< true
|
|
|
|
|
<< patchText;
|
2013-02-15 12:49:50 +01:00
|
|
|
}
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
void DiffEditor::Internal::DiffEditorPlugin::testMakePatch()
|
|
|
|
|
{
|
|
|
|
|
QFETCH(ChunkData, sourceChunk);
|
|
|
|
|
QFETCH(QString, leftFileName);
|
|
|
|
|
QFETCH(QString, rightFileName);
|
|
|
|
|
QFETCH(bool, lastChunk);
|
|
|
|
|
QFETCH(QString, patchText);
|
|
|
|
|
|
|
|
|
|
QString result = DiffUtils::makePatch(sourceChunk, leftFileName, rightFileName, lastChunk);
|
|
|
|
|
|
2014-07-09 12:37:47 +02:00
|
|
|
QCOMPARE(result, patchText);
|
|
|
|
|
|
|
|
|
|
bool ok;
|
2014-10-24 14:11:12 +02:00
|
|
|
QList<FileData> resultList = DiffUtils::readPatch(result, &ok);
|
2014-07-09 12:37:47 +02:00
|
|
|
|
|
|
|
|
QVERIFY(ok);
|
|
|
|
|
QCOMPARE(resultList.count(), 1);
|
|
|
|
|
for (int i = 0; i < resultList.count(); i++) {
|
|
|
|
|
const FileData &resultFileData = resultList.at(i);
|
|
|
|
|
QCOMPARE(resultFileData.leftFileInfo.fileName, leftFileName);
|
|
|
|
|
QCOMPARE(resultFileData.rightFileInfo.fileName, rightFileName);
|
|
|
|
|
QCOMPARE(resultFileData.chunks.count(), 1);
|
|
|
|
|
for (int j = 0; j < resultFileData.chunks.count(); j++) {
|
|
|
|
|
const ChunkData &resultChunkData = resultFileData.chunks.at(j);
|
|
|
|
|
QCOMPARE(resultChunkData.leftStartingLineNumber, sourceChunk.leftStartingLineNumber);
|
|
|
|
|
QCOMPARE(resultChunkData.rightStartingLineNumber, sourceChunk.rightStartingLineNumber);
|
|
|
|
|
QCOMPARE(resultChunkData.contextChunk, sourceChunk.contextChunk);
|
|
|
|
|
QCOMPARE(resultChunkData.rows.count(), sourceChunk.rows.count());
|
|
|
|
|
for (int k = 0; k < sourceChunk.rows.count(); k++) {
|
|
|
|
|
const RowData &sourceRowData = sourceChunk.rows.at(k);
|
|
|
|
|
const RowData &resultRowData = resultChunkData.rows.at(k);
|
|
|
|
|
QCOMPARE(resultRowData.equal, sourceRowData.equal);
|
|
|
|
|
QCOMPARE(resultRowData.leftLine.text, sourceRowData.leftLine.text);
|
|
|
|
|
QCOMPARE(resultRowData.leftLine.textLineType, sourceRowData.leftLine.textLineType);
|
|
|
|
|
QCOMPARE(resultRowData.rightLine.text, sourceRowData.rightLine.text);
|
|
|
|
|
QCOMPARE(resultRowData.rightLine.textLineType, sourceRowData.rightLine.textLineType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-13 16:43:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|
|
|
|
{
|
|
|
|
|
QTest::addColumn<QString>("sourcePatch");
|
|
|
|
|
QTest::addColumn<QList<FileData> >("fileDataList");
|
|
|
|
|
|
2014-07-26 22:57:42 +03:00
|
|
|
QString patch = _("diff --git a/src/plugins/diffeditor/diffeditor.cpp b/src/plugins/diffeditor/diffeditor.cpp\n"
|
|
|
|
|
"index eab9e9b..082c135 100644\n"
|
|
|
|
|
"--- a/src/plugins/diffeditor/diffeditor.cpp\n"
|
|
|
|
|
"+++ b/src/plugins/diffeditor/diffeditor.cpp\n"
|
|
|
|
|
"@@ -187,9 +187,6 @@ void DiffEditor::ctor()\n"
|
|
|
|
|
" m_controller = m_document->controller();\n"
|
|
|
|
|
" m_guiController = new DiffEditorGuiController(m_controller, this);\n"
|
|
|
|
|
" \n"
|
|
|
|
|
"-// m_sideBySideEditor->setDiffEditorGuiController(m_guiController);\n"
|
|
|
|
|
"-// m_unifiedEditor->setDiffEditorGuiController(m_guiController);\n"
|
|
|
|
|
"-\n"
|
|
|
|
|
" connect(m_controller, SIGNAL(cleared(QString)),\n"
|
|
|
|
|
" this, SLOT(slotCleared(QString)));\n"
|
|
|
|
|
" connect(m_controller, SIGNAL(diffContentsChanged(QList<DiffEditorController::DiffFilesContents>,QString)),\n"
|
|
|
|
|
"diff --git a/src/plugins/diffeditor/diffutils.cpp b/src/plugins/diffeditor/diffutils.cpp\n"
|
|
|
|
|
"index 2f641c9..f8ff795 100644\n"
|
|
|
|
|
"--- a/src/plugins/diffeditor/diffutils.cpp\n"
|
|
|
|
|
"+++ b/src/plugins/diffeditor/diffutils.cpp\n"
|
|
|
|
|
"@@ -464,5 +464,12 @@ QString DiffUtils::makePatch(const ChunkData &chunkData,\n"
|
|
|
|
|
" return diffText;\n"
|
|
|
|
|
" }\n"
|
|
|
|
|
" \n"
|
|
|
|
|
"+FileData DiffUtils::makeFileData(const QString &patch)\n"
|
|
|
|
|
"+{\n"
|
|
|
|
|
"+ FileData fileData;\n"
|
|
|
|
|
"+\n"
|
|
|
|
|
"+ return fileData;\n"
|
|
|
|
|
"+}\n"
|
|
|
|
|
"+\n"
|
|
|
|
|
" } // namespace Internal\n"
|
|
|
|
|
" } // namespace DiffEditor\n"
|
|
|
|
|
"diff --git a/new b/new\n"
|
|
|
|
|
"new file mode 100644\n"
|
|
|
|
|
"index 0000000..257cc56\n"
|
|
|
|
|
"--- /dev/null\n"
|
|
|
|
|
"+++ b/new\n"
|
|
|
|
|
"@@ -0,0 +1 @@\n"
|
|
|
|
|
"+foo\n"
|
|
|
|
|
"diff --git a/deleted b/deleted\n"
|
|
|
|
|
"deleted file mode 100644\n"
|
|
|
|
|
"index 257cc56..0000000\n"
|
|
|
|
|
"--- a/deleted\n"
|
|
|
|
|
"+++ /dev/null\n"
|
|
|
|
|
"@@ -1 +0,0 @@\n"
|
|
|
|
|
"-foo\n"
|
|
|
|
|
"diff --git a/empty b/empty\n"
|
|
|
|
|
"new file mode 100644\n"
|
|
|
|
|
"index 0000000..e69de29\n"
|
|
|
|
|
"diff --git a/empty b/empty\n"
|
|
|
|
|
"deleted file mode 100644\n"
|
|
|
|
|
"index e69de29..0000000\n"
|
|
|
|
|
"diff --git a/file a.txt b/file b.txt\n"
|
|
|
|
|
"similarity index 99%\n"
|
|
|
|
|
"copy from file a.txt\n"
|
|
|
|
|
"copy to file b.txt\n"
|
|
|
|
|
"index 1234567..9876543\n"
|
|
|
|
|
"--- a/file a.txt\n"
|
|
|
|
|
"+++ b/file b.txt\n"
|
|
|
|
|
"@@ -20,3 +20,3 @@\n"
|
|
|
|
|
" A\n"
|
|
|
|
|
"-B\n"
|
|
|
|
|
"+C\n"
|
|
|
|
|
" D\n"
|
|
|
|
|
"diff --git a/file a.txt b/file b.txt\n"
|
|
|
|
|
"similarity index 99%\n"
|
|
|
|
|
"rename from file a.txt\n"
|
|
|
|
|
"rename to file b.txt\n"
|
|
|
|
|
);
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
FileData fileData1;
|
2014-07-26 22:57:42 +03:00
|
|
|
fileData1.leftFileInfo = DiffFileInfo(_("src/plugins/diffeditor/diffeditor.cpp"), _("eab9e9b"));
|
|
|
|
|
fileData1.rightFileInfo = DiffFileInfo(_("src/plugins/diffeditor/diffeditor.cpp"), _("082c135"));
|
2014-02-13 16:43:28 +01:00
|
|
|
ChunkData chunkData1;
|
2014-06-08 23:09:51 +03:00
|
|
|
chunkData1.leftStartingLineNumber = 186;
|
|
|
|
|
chunkData1.rightStartingLineNumber = 186;
|
2014-02-13 16:43:28 +01:00
|
|
|
QList<RowData> rows1;
|
2014-07-26 22:57:42 +03:00
|
|
|
rows1 << RowData(_(" m_controller = m_document->controller();"));
|
|
|
|
|
rows1 << RowData(_(" m_guiController = new DiffEditorGuiController(m_controller, this);"));
|
|
|
|
|
rows1 << RowData(_(""));
|
|
|
|
|
rows1 << RowData(_("// m_sideBySideEditor->setDiffEditorGuiController(m_guiController);"), TextLineData::Separator);
|
|
|
|
|
rows1 << RowData(_("// m_unifiedEditor->setDiffEditorGuiController(m_guiController);"), TextLineData::Separator);
|
|
|
|
|
rows1 << RowData(_(""), TextLineData::Separator);
|
|
|
|
|
rows1 << RowData(_(" connect(m_controller, SIGNAL(cleared(QString)),"));
|
|
|
|
|
rows1 << RowData(_(" this, SLOT(slotCleared(QString)));"));
|
|
|
|
|
rows1 << RowData(_(" connect(m_controller, SIGNAL(diffContentsChanged(QList<DiffEditorController::DiffFilesContents>,QString)),"));
|
2014-02-13 16:43:28 +01:00
|
|
|
chunkData1.rows = rows1;
|
2014-07-26 22:57:42 +03:00
|
|
|
fileData1.chunks << chunkData1;
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
FileData fileData2;
|
2014-07-26 22:57:42 +03:00
|
|
|
fileData2.leftFileInfo = DiffFileInfo(_("src/plugins/diffeditor/diffutils.cpp"), _("2f641c9"));
|
|
|
|
|
fileData2.rightFileInfo = DiffFileInfo(_("src/plugins/diffeditor/diffutils.cpp"), _("f8ff795"));
|
2014-02-13 16:43:28 +01:00
|
|
|
ChunkData chunkData2;
|
2014-06-08 23:09:51 +03:00
|
|
|
chunkData2.leftStartingLineNumber = 463;
|
|
|
|
|
chunkData2.rightStartingLineNumber = 463;
|
2014-02-13 16:43:28 +01:00
|
|
|
QList<RowData> rows2;
|
2014-07-26 22:57:42 +03:00
|
|
|
rows2 << RowData(_(" return diffText;"));
|
|
|
|
|
rows2 << RowData(_("}"));
|
|
|
|
|
rows2 << RowData(_(""));
|
|
|
|
|
rows2 << RowData(TextLineData::Separator, _("FileData DiffUtils::makeFileData(const QString &patch)"));
|
|
|
|
|
rows2 << RowData(TextLineData::Separator, _("{"));
|
|
|
|
|
rows2 << RowData(TextLineData::Separator, _(" FileData fileData;"));
|
|
|
|
|
rows2 << RowData(TextLineData::Separator, _(""));
|
|
|
|
|
rows2 << RowData(TextLineData::Separator, _(" return fileData;"));
|
|
|
|
|
rows2 << RowData(TextLineData::Separator, _("}"));
|
|
|
|
|
rows2 << RowData(TextLineData::Separator, _(""));
|
|
|
|
|
rows2 << RowData(_("} // namespace Internal"));
|
|
|
|
|
rows2 << RowData(_("} // namespace DiffEditor"));
|
2014-02-13 16:43:28 +01:00
|
|
|
chunkData2.rows = rows2;
|
2014-07-26 22:57:42 +03:00
|
|
|
fileData2.chunks << chunkData2;
|
2014-02-13 16:43:28 +01:00
|
|
|
|
2014-06-08 23:31:46 +03:00
|
|
|
FileData fileData3;
|
2014-07-26 22:57:42 +03:00
|
|
|
fileData3.leftFileInfo = DiffFileInfo(_("new"), _("0000000"));
|
|
|
|
|
fileData3.rightFileInfo = DiffFileInfo(_("new"), _("257cc56"));
|
2014-07-07 14:26:41 +02:00
|
|
|
fileData3.fileOperation = FileData::NewFile;
|
2014-06-08 23:31:46 +03:00
|
|
|
ChunkData chunkData3;
|
|
|
|
|
chunkData3.leftStartingLineNumber = -1;
|
|
|
|
|
chunkData3.rightStartingLineNumber = 0;
|
|
|
|
|
QList<RowData> rows3;
|
2014-07-26 22:57:42 +03:00
|
|
|
rows3 << RowData(TextLineData::Separator, _("foo"));
|
2014-06-08 23:31:46 +03:00
|
|
|
TextLineData textLineData3(TextLineData::TextLine);
|
2014-07-26 22:57:42 +03:00
|
|
|
rows3 << RowData(TextLineData::Separator, textLineData3);
|
2014-06-08 23:31:46 +03:00
|
|
|
chunkData3.rows = rows3;
|
2014-07-26 22:57:42 +03:00
|
|
|
fileData3.chunks << chunkData3;
|
2014-06-08 23:31:46 +03:00
|
|
|
|
|
|
|
|
FileData fileData4;
|
2014-07-26 22:57:42 +03:00
|
|
|
fileData4.leftFileInfo = DiffFileInfo(_("deleted"), _("257cc56"));
|
|
|
|
|
fileData4.rightFileInfo = DiffFileInfo(_("deleted"), _("0000000"));
|
2014-07-07 14:26:41 +02:00
|
|
|
fileData4.fileOperation = FileData::DeleteFile;
|
2014-06-08 23:31:46 +03:00
|
|
|
ChunkData chunkData4;
|
|
|
|
|
chunkData4.leftStartingLineNumber = 0;
|
|
|
|
|
chunkData4.rightStartingLineNumber = -1;
|
|
|
|
|
QList<RowData> rows4;
|
2014-07-26 22:57:42 +03:00
|
|
|
rows4 << RowData(_("foo"), TextLineData::Separator);
|
2014-06-08 23:31:46 +03:00
|
|
|
TextLineData textLineData4(TextLineData::TextLine);
|
2014-07-26 22:57:42 +03:00
|
|
|
rows4 << RowData(textLineData4, TextLineData::Separator);
|
2014-06-08 23:31:46 +03:00
|
|
|
chunkData4.rows = rows4;
|
2014-07-26 22:57:42 +03:00
|
|
|
fileData4.chunks << chunkData4;
|
2014-06-08 23:31:46 +03:00
|
|
|
|
2014-06-08 23:34:01 +03:00
|
|
|
FileData fileData5;
|
2014-07-26 22:57:42 +03:00
|
|
|
fileData5.leftFileInfo = DiffFileInfo(_("empty"), _("0000000"));
|
|
|
|
|
fileData5.rightFileInfo = DiffFileInfo(_("empty"), _("e69de29"));
|
2014-07-07 14:26:41 +02:00
|
|
|
fileData5.fileOperation = FileData::NewFile;
|
2014-06-08 23:34:01 +03:00
|
|
|
|
|
|
|
|
FileData fileData6;
|
2014-07-26 22:57:42 +03:00
|
|
|
fileData6.leftFileInfo = DiffFileInfo(_("empty"), _("e69de29"));
|
|
|
|
|
fileData6.rightFileInfo = DiffFileInfo(_("empty"), _("0000000"));
|
2014-07-07 14:26:41 +02:00
|
|
|
fileData6.fileOperation = FileData::DeleteFile;
|
|
|
|
|
|
|
|
|
|
FileData fileData7;
|
2014-07-26 22:57:42 +03:00
|
|
|
fileData7.leftFileInfo = DiffFileInfo(_("file a.txt"), _("1234567"));
|
|
|
|
|
fileData7.rightFileInfo = DiffFileInfo(_("file b.txt"), _("9876543"));
|
2014-07-07 14:26:41 +02:00
|
|
|
fileData7.fileOperation = FileData::CopyFile;
|
|
|
|
|
ChunkData chunkData7;
|
|
|
|
|
chunkData7.leftStartingLineNumber = 19;
|
|
|
|
|
chunkData7.rightStartingLineNumber = 19;
|
|
|
|
|
QList<RowData> rows7;
|
2014-07-26 22:57:42 +03:00
|
|
|
rows7 << RowData(_("A"));
|
|
|
|
|
rows7 << RowData(_("B"), _("C"));
|
|
|
|
|
rows7 << RowData(_("D"));
|
2014-07-07 14:26:41 +02:00
|
|
|
chunkData7.rows = rows7;
|
2014-07-26 22:57:42 +03:00
|
|
|
fileData7.chunks << chunkData7;
|
2014-07-07 14:26:41 +02:00
|
|
|
|
|
|
|
|
FileData fileData8;
|
2014-07-26 22:57:42 +03:00
|
|
|
fileData8.leftFileInfo = DiffFileInfo(_("file a.txt"));
|
|
|
|
|
fileData8.rightFileInfo = DiffFileInfo(_("file b.txt"));
|
2014-07-07 14:26:41 +02:00
|
|
|
fileData8.fileOperation = FileData::RenameFile;
|
2014-06-08 23:34:01 +03:00
|
|
|
|
2014-07-09 12:37:47 +02:00
|
|
|
QList<FileData> fileDataList1;
|
|
|
|
|
fileDataList1 << fileData1 << fileData2 << fileData3 << fileData4 << fileData5 << fileData6 << fileData7 << fileData8;
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
QTest::newRow("Git patch") << patch
|
2014-07-09 12:37:47 +02:00
|
|
|
<< fileDataList1;
|
|
|
|
|
|
|
|
|
|
//////////////
|
|
|
|
|
|
2014-07-26 22:57:42 +03:00
|
|
|
patch = _("diff --git a/file foo.txt b/file foo.txt\n"
|
|
|
|
|
"index 1234567..9876543 100644\n"
|
|
|
|
|
"--- a/file foo.txt\n"
|
|
|
|
|
"+++ b/file foo.txt\n"
|
|
|
|
|
"@@ -50,4 +50,5 @@ void DiffEditor::ctor()\n"
|
|
|
|
|
" A\n"
|
|
|
|
|
" B\n"
|
|
|
|
|
" C\n"
|
|
|
|
|
"+\n");
|
|
|
|
|
|
|
|
|
|
fileData1.leftFileInfo = DiffFileInfo(_("file foo.txt"), _("1234567"));
|
|
|
|
|
fileData1.rightFileInfo = DiffFileInfo(_("file foo.txt"), _("9876543"));
|
2014-07-09 12:37:47 +02:00
|
|
|
fileData1.fileOperation = FileData::ChangeFile;
|
|
|
|
|
chunkData1.leftStartingLineNumber = 49;
|
|
|
|
|
chunkData1.rightStartingLineNumber = 49;
|
|
|
|
|
rows1.clear();
|
2014-07-26 22:57:42 +03:00
|
|
|
rows1 << RowData(_("A"));
|
|
|
|
|
rows1 << RowData(_("B"));
|
|
|
|
|
rows1 << RowData(_("C"));
|
|
|
|
|
rows1 << RowData(TextLineData::Separator, _(""));
|
2014-07-09 12:37:47 +02:00
|
|
|
chunkData1.rows = rows1;
|
|
|
|
|
fileData1.chunks.clear();
|
2014-07-26 22:57:42 +03:00
|
|
|
fileData1.chunks << chunkData1;
|
2014-07-09 12:37:47 +02:00
|
|
|
|
|
|
|
|
QList<FileData> fileDataList2;
|
|
|
|
|
fileDataList2 << fileData1;
|
|
|
|
|
|
|
|
|
|
QTest::newRow("Added line") << patch
|
|
|
|
|
<< fileDataList2;
|
|
|
|
|
|
|
|
|
|
//////////////
|
|
|
|
|
|
2014-07-26 22:57:42 +03:00
|
|
|
patch = _("diff --git a/file foo.txt b/file foo.txt\n"
|
|
|
|
|
"index 1234567..9876543 100644\n"
|
|
|
|
|
"--- a/file foo.txt\n"
|
|
|
|
|
"+++ b/file foo.txt\n"
|
|
|
|
|
"@@ -1,1 +1,1 @@\n"
|
|
|
|
|
"-ABCD\n"
|
|
|
|
|
"\\ No newline at end of file\n"
|
|
|
|
|
"+ABCD\n");
|
|
|
|
|
|
|
|
|
|
fileData1.leftFileInfo = DiffFileInfo(_("file foo.txt"), _("1234567"));
|
|
|
|
|
fileData1.rightFileInfo = DiffFileInfo(_("file foo.txt"), _("9876543"));
|
2014-07-09 12:37:47 +02:00
|
|
|
fileData1.fileOperation = FileData::ChangeFile;
|
|
|
|
|
chunkData1.leftStartingLineNumber = 0;
|
|
|
|
|
chunkData1.rightStartingLineNumber = 0;
|
|
|
|
|
rows1.clear();
|
2014-07-26 22:57:42 +03:00
|
|
|
rows1 << RowData(_("ABCD"));
|
|
|
|
|
rows1 << RowData(TextLineData::Separator, _(""));
|
2014-07-09 12:37:47 +02:00
|
|
|
chunkData1.rows = rows1;
|
|
|
|
|
fileData1.chunks.clear();
|
2014-07-26 22:57:42 +03:00
|
|
|
fileData1.chunks << chunkData1;
|
2014-07-09 12:37:47 +02:00
|
|
|
|
|
|
|
|
QList<FileData> fileDataList3;
|
|
|
|
|
fileDataList3 << fileData1;
|
|
|
|
|
|
|
|
|
|
QTest::newRow("Last newline added to a line without newline") << patch
|
|
|
|
|
<< fileDataList3;
|
2014-07-28 12:15:01 +03:00
|
|
|
|
|
|
|
|
patch = _("diff --git a/difftest.txt b/difftest.txt\n"
|
|
|
|
|
"index 1234567..9876543 100644\n"
|
|
|
|
|
"--- a/difftest.txt\n"
|
|
|
|
|
"+++ b/difftest.txt\n"
|
|
|
|
|
"@@ -2,5 +2,5 @@ void func()\n"
|
|
|
|
|
" A\n"
|
|
|
|
|
" B\n"
|
|
|
|
|
"-C\n"
|
|
|
|
|
"+Z\n"
|
|
|
|
|
" D\n"
|
|
|
|
|
" \n"
|
|
|
|
|
"@@ -9,2 +9,4 @@ void OtherFunc()\n"
|
|
|
|
|
" \n"
|
|
|
|
|
" D\n"
|
|
|
|
|
"+E\n"
|
|
|
|
|
"+F\n"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
fileData1.leftFileInfo = DiffFileInfo(_("difftest.txt"), _("1234567"));
|
|
|
|
|
fileData1.rightFileInfo = DiffFileInfo(_("difftest.txt"), _("9876543"));
|
|
|
|
|
fileData1.fileOperation = FileData::ChangeFile;
|
|
|
|
|
chunkData1.leftStartingLineNumber = 1;
|
|
|
|
|
chunkData1.rightStartingLineNumber = 1;
|
|
|
|
|
rows1.clear();
|
|
|
|
|
rows1 << RowData(_("A"));
|
|
|
|
|
rows1 << RowData(_("B"));
|
|
|
|
|
rows1 << RowData(_("C"), _("Z"));
|
|
|
|
|
rows1 << RowData(_("D"));
|
|
|
|
|
rows1 << RowData(_(""));
|
|
|
|
|
chunkData1.rows = rows1;
|
|
|
|
|
|
|
|
|
|
chunkData2.leftStartingLineNumber = 8;
|
|
|
|
|
chunkData2.rightStartingLineNumber = 8;
|
|
|
|
|
rows2.clear();
|
|
|
|
|
rows2 << RowData(_(""));
|
|
|
|
|
rows2 << RowData(_("D"));
|
|
|
|
|
rows2 << RowData(TextLineData::Separator, _("E"));
|
|
|
|
|
rows2 << RowData(TextLineData::Separator, _("F"));
|
|
|
|
|
chunkData2.rows = rows2;
|
|
|
|
|
fileData1.chunks.clear();
|
|
|
|
|
fileData1.chunks << chunkData1;
|
|
|
|
|
fileData1.chunks << chunkData2;
|
|
|
|
|
|
|
|
|
|
QList<FileData> fileDataList4;
|
|
|
|
|
fileDataList4 << fileData1;
|
|
|
|
|
|
|
|
|
|
QTest::newRow("2 chunks - first ends with blank line") << patch
|
|
|
|
|
<< fileDataList4;
|
2014-08-06 15:03:26 +03:00
|
|
|
|
|
|
|
|
//////////////
|
|
|
|
|
|
|
|
|
|
patch = _("diff --git a/file foo.txt b/file foo.txt\n"
|
|
|
|
|
"index 1234567..9876543 100644\n"
|
|
|
|
|
"--- a/file foo.txt\n"
|
|
|
|
|
"+++ b/file foo.txt\n"
|
|
|
|
|
"@@ -1,1 +1,3 @@ void DiffEditor::ctor()\n"
|
|
|
|
|
" ABCD\n"
|
|
|
|
|
"+\n"
|
|
|
|
|
"+EFGH\n"
|
|
|
|
|
"\\ No newline at end of file\n");
|
|
|
|
|
|
|
|
|
|
fileData1.leftFileInfo = DiffFileInfo(_("file foo.txt"), _("1234567"));
|
|
|
|
|
fileData1.rightFileInfo = DiffFileInfo(_("file foo.txt"), _("9876543"));
|
|
|
|
|
fileData1.fileOperation = FileData::ChangeFile;
|
|
|
|
|
chunkData1.leftStartingLineNumber = 0;
|
|
|
|
|
chunkData1.rightStartingLineNumber = 0;
|
|
|
|
|
rows1.clear();
|
|
|
|
|
rows1 << RowData(_("ABCD"));
|
|
|
|
|
rows1 << RowData(TextLineData::Separator, _(""));
|
|
|
|
|
rows1 << RowData(_(""), _("EFGH"));
|
|
|
|
|
chunkData1.rows = rows1;
|
|
|
|
|
fileData1.chunks.clear();
|
|
|
|
|
fileData1.chunks << chunkData1;
|
|
|
|
|
|
|
|
|
|
QList<FileData> fileDataList5;
|
|
|
|
|
fileDataList5 << fileData1;
|
|
|
|
|
|
|
|
|
|
QTest::newRow("Blank line followed by No newline") << patch
|
|
|
|
|
<< fileDataList5;
|
2014-09-29 12:14:15 +03:00
|
|
|
|
|
|
|
|
//////////////
|
|
|
|
|
|
|
|
|
|
// Based on 953cdb97
|
|
|
|
|
patch = _("diff --git a/src/plugins/texteditor/basetextdocument.h b/src/plugins/texteditor/textdocument.h\n"
|
|
|
|
|
"similarity index 100%\n"
|
|
|
|
|
"rename from src/plugins/texteditor/basetextdocument.h\n"
|
|
|
|
|
"rename to src/plugins/texteditor/textdocument.h\n"
|
|
|
|
|
"diff --git a/src/plugins/texteditor/basetextdocumentlayout.cpp b/src/plugins/texteditor/textdocumentlayout.cpp\n"
|
|
|
|
|
"similarity index 79%\n"
|
|
|
|
|
"rename from src/plugins/texteditor/basetextdocumentlayout.cpp\n"
|
|
|
|
|
"rename to src/plugins/texteditor/textdocumentlayout.cpp\n"
|
|
|
|
|
"index 0121933..01cc3a0 100644\n"
|
|
|
|
|
"--- a/src/plugins/texteditor/basetextdocumentlayout.cpp\n"
|
|
|
|
|
"+++ b/src/plugins/texteditor/textdocumentlayout.cpp\n"
|
|
|
|
|
"@@ -2,5 +2,5 @@ void func()\n"
|
|
|
|
|
" A\n"
|
|
|
|
|
" B\n"
|
|
|
|
|
"-C\n"
|
|
|
|
|
"+Z\n"
|
|
|
|
|
" D\n"
|
|
|
|
|
" \n"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
fileData1 = FileData();
|
|
|
|
|
fileData1.leftFileInfo = DiffFileInfo(_("src/plugins/texteditor/basetextdocument.h"));
|
|
|
|
|
fileData1.rightFileInfo = DiffFileInfo(_("src/plugins/texteditor/textdocument.h"));
|
|
|
|
|
fileData1.fileOperation = FileData::RenameFile;
|
|
|
|
|
fileData2 = FileData();
|
|
|
|
|
fileData2.leftFileInfo = DiffFileInfo(_("src/plugins/texteditor/basetextdocumentlayout.cpp"), _("0121933"));
|
|
|
|
|
fileData2.rightFileInfo = DiffFileInfo(_("src/plugins/texteditor/textdocumentlayout.cpp"), _("01cc3a0"));
|
|
|
|
|
fileData2.fileOperation = FileData::RenameFile;
|
|
|
|
|
chunkData2.leftStartingLineNumber = 1;
|
|
|
|
|
chunkData2.rightStartingLineNumber = 1;
|
|
|
|
|
rows2.clear();
|
|
|
|
|
rows2 << RowData(_("A"));
|
|
|
|
|
rows2 << RowData(_("B"));
|
|
|
|
|
rows2 << RowData(_("C"), _("Z"));
|
|
|
|
|
rows2 << RowData(_("D"));
|
|
|
|
|
rows2 << RowData(_(""));
|
|
|
|
|
chunkData2.rows = rows2;
|
|
|
|
|
fileData2.chunks.clear();
|
|
|
|
|
fileData2.chunks << chunkData2;
|
|
|
|
|
|
|
|
|
|
QList<FileData> fileDataList6;
|
|
|
|
|
fileDataList6 << fileData1 << fileData2;
|
|
|
|
|
|
|
|
|
|
QTest::newRow("Multiple renames") << patch
|
|
|
|
|
<< fileDataList6;
|
|
|
|
|
|
2014-11-02 22:10:15 +02:00
|
|
|
//////////////
|
|
|
|
|
|
|
|
|
|
// Dirty submodule
|
|
|
|
|
patch = _("diff --git a/src/shared/qbs b/src/shared/qbs\n"
|
|
|
|
|
"--- a/src/shared/qbs\n"
|
|
|
|
|
"+++ b/src/shared/qbs\n"
|
|
|
|
|
"@@ -1 +1 @@\n"
|
|
|
|
|
"-Subproject commit eda76354077a427d692fee05479910de31040d3f\n"
|
|
|
|
|
"+Subproject commit eda76354077a427d692fee05479910de31040d3f-dirty\n"
|
|
|
|
|
);
|
|
|
|
|
fileData1 = FileData();
|
|
|
|
|
fileData1.leftFileInfo = DiffFileInfo(_("src/shared/qbs"));
|
|
|
|
|
fileData1.rightFileInfo = DiffFileInfo(_("src/shared/qbs"));
|
|
|
|
|
chunkData1.leftStartingLineNumber = 0;
|
|
|
|
|
chunkData1.rightStartingLineNumber = 0;
|
|
|
|
|
rows1.clear();
|
|
|
|
|
rows1 << RowData(_("Subproject commit eda76354077a427d692fee05479910de31040d3f"),
|
|
|
|
|
_("Subproject commit eda76354077a427d692fee05479910de31040d3f-dirty"));
|
|
|
|
|
chunkData1.rows = rows1;
|
|
|
|
|
fileData1.chunks.clear();
|
|
|
|
|
fileData1.chunks << chunkData1;
|
|
|
|
|
|
|
|
|
|
QList<FileData> fileDataList7;
|
|
|
|
|
fileDataList7 << fileData1;
|
|
|
|
|
QTest::newRow("Dirty submodule") << patch
|
|
|
|
|
<< fileDataList7;
|
2014-02-13 16:43:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiffEditor::Internal::DiffEditorPlugin::testReadPatch()
|
|
|
|
|
{
|
|
|
|
|
QFETCH(QString, sourcePatch);
|
|
|
|
|
QFETCH(QList<FileData>, fileDataList);
|
|
|
|
|
|
|
|
|
|
bool ok;
|
2014-10-24 14:11:12 +02:00
|
|
|
QList<FileData> result = DiffUtils::readPatch(sourcePatch, &ok);
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
QVERIFY(ok);
|
|
|
|
|
QCOMPARE(fileDataList.count(), result.count());
|
|
|
|
|
for (int i = 0; i < fileDataList.count(); i++) {
|
|
|
|
|
const FileData &origFileData = fileDataList.at(i);
|
|
|
|
|
const FileData &resultFileData = result.at(i);
|
2014-06-08 23:09:51 +03:00
|
|
|
QCOMPARE(resultFileData.leftFileInfo.fileName, origFileData.leftFileInfo.fileName);
|
|
|
|
|
QCOMPARE(resultFileData.leftFileInfo.typeInfo, origFileData.leftFileInfo.typeInfo);
|
|
|
|
|
QCOMPARE(resultFileData.rightFileInfo.fileName, origFileData.rightFileInfo.fileName);
|
|
|
|
|
QCOMPARE(resultFileData.rightFileInfo.typeInfo, origFileData.rightFileInfo.typeInfo);
|
|
|
|
|
QCOMPARE(resultFileData.chunks.count(), origFileData.chunks.count());
|
2014-07-07 14:26:41 +02:00
|
|
|
QCOMPARE(resultFileData.fileOperation, origFileData.fileOperation);
|
2014-02-13 16:43:28 +01:00
|
|
|
for (int j = 0; j < origFileData.chunks.count(); j++) {
|
|
|
|
|
const ChunkData &origChunkData = origFileData.chunks.at(j);
|
|
|
|
|
const ChunkData &resultChunkData = resultFileData.chunks.at(j);
|
2014-06-08 23:09:51 +03:00
|
|
|
QCOMPARE(resultChunkData.leftStartingLineNumber, origChunkData.leftStartingLineNumber);
|
|
|
|
|
QCOMPARE(resultChunkData.rightStartingLineNumber, origChunkData.rightStartingLineNumber);
|
|
|
|
|
QCOMPARE(resultChunkData.contextChunk, origChunkData.contextChunk);
|
|
|
|
|
QCOMPARE(resultChunkData.rows.count(), origChunkData.rows.count());
|
2014-02-13 16:43:28 +01:00
|
|
|
for (int k = 0; k < origChunkData.rows.count(); k++) {
|
|
|
|
|
const RowData &origRowData = origChunkData.rows.at(k);
|
|
|
|
|
const RowData &resultRowData = resultChunkData.rows.at(k);
|
2014-06-08 23:09:51 +03:00
|
|
|
QCOMPARE(resultRowData.equal, origRowData.equal);
|
|
|
|
|
QCOMPARE(resultRowData.leftLine.text, origRowData.leftLine.text);
|
|
|
|
|
QCOMPARE(resultRowData.leftLine.textLineType, origRowData.leftLine.textLineType);
|
|
|
|
|
QCOMPARE(resultRowData.rightLine.text, origRowData.rightLine.text);
|
|
|
|
|
QCOMPARE(resultRowData.rightLine.textLineType, origRowData.rightLine.textLineType);
|
2014-02-13 16:43:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // WITH_TESTS
|
|
|
|
|
|
|
|
|
|
#include "diffeditorplugin.moc"
|