Commit 3b66b11a authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Tobias Hunger
Browse files

VCS: Add diff pattern tests for CVS and Mercurial



* Fix Mercurial pattern
* Make fileNameFromDiffSpecification protected again (it was made
  public for running tests, but they are now run from VCSBaseEditor)
* Remove DiffHighlighter::filePattern(). Not used anymore.

Change-Id: Ifc99f761f0ab96cc79f1d018e3f3c8cf4603da10
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 23844410
......@@ -71,6 +71,10 @@
#include <QMenu>
#include <QMessageBox>
#ifdef WITH_TESTS
#include <QTest>
#endif
using namespace VcsBase;
using namespace Core;
......@@ -1376,6 +1380,28 @@ CvsControl *CvsPlugin::cvsVersionControl() const
return static_cast<CvsControl *>(versionControl());
}
#ifdef WITH_TESTS
void CvsPlugin::testDiffFileResolving_data()
{
QTest::addColumn<QByteArray>("header");
QTest::addColumn<QByteArray>("fileName");
QTest::newRow("Modified") << QByteArray(
"Index: src/plugins/cvs/cvseditor.cpp\n"
"===================================================================\n"
"--- src/plugins/cvs/cvseditor.cpp\t21 Jan 2013 20:34:20 -0000\t1.1\n"
"+++ src/plugins/cvs/cvseditor.cpp\t21 Jan 2013 20:34:28 -0000\n"
"@@ -120,7 +120,7 @@\n\n")
<< QByteArray("src/plugins/cvs/cvseditor.cpp");
}
void CvsPlugin::testDiffFileResolving()
{
CvsEditor editor(editorParameters + 3, 0);
VcsBase::VcsBaseEditorWidget::testDiffFileResolving(&editor);
}
#endif
} // namespace Internal
} // namespace Cvs
......
......@@ -123,6 +123,10 @@ private slots:
void uneditCurrentFile();
void uneditCurrentRepository();
void cvsDiff(const Cvs::Internal::CvsDiffParameters &p);
#ifdef WITH_TESTS
void testDiffFileResolving_data();
void testDiffFileResolving();
#endif
protected:
void updateActions(VcsBase::VcsBasePlugin::ActionState);
......
......@@ -42,7 +42,8 @@ const char CHANGESETID12[] = " ([a-f0-9]{12,12}) "; //match 12 hex chars and cap
const char CHANGESETID40[] = " ([a-f0-9]{40,40}) ";
const char CHANGEIDEXACT12[] = "[a-f0-9]{12,12}"; //match 12 hex chars a
const char CHANGEIDEXACT40[] = "[a-f0-9]{40,40}";
const char DIFFIDENTIFIER[] = "^[-+]{3} [ab]/(.+)$"; // match e.g. +++ b/filename
// match diff header. e.g. +++ b/filename
const char DIFFIDENTIFIER[] = "^(?:diff --git a/|[+-]{3} (?:/dev/null|[ab]/(.+$)))";
// Base editor parameters
const char COMMANDLOG_ID[] = "Mercurial Command Log Editor";
......
......@@ -685,4 +685,41 @@ void MercurialPlugin::updateActions(VcsBasePlugin::ActionState as)
repoAction->setEnabled(repoEnabled);
}
#ifdef WITH_TESTS
#include <QTest>
void MercurialPlugin::testDiffFileResolving_data()
{
QTest::addColumn<QByteArray>("header");
QTest::addColumn<QByteArray>("fileName");
QTest::newRow("New") << QByteArray(
"diff --git a/src/plugins/mercurial/mercurialeditor.cpp b/src/plugins/mercurial/mercurialeditor.cpp\n"
"new file mode 100644\n"
"--- /dev/null\n"
"+++ b/src/plugins/mercurial/mercurialeditor.cpp\n"
"@@ -0,0 +1,112 @@\n\n")
<< QByteArray("src/plugins/mercurial/mercurialeditor.cpp");
QTest::newRow("Deleted") << QByteArray(
"diff --git a/src/plugins/mercurial/mercurialeditor.cpp b/src/plugins/mercurial/mercurialeditor.cpp\n"
"deleted file mode 100644\n"
"--- a/src/plugins/mercurial/mercurialeditor.cpp\n"
"+++ /dev/null\n"
"@@ -1,112 +0,0 @@\n\n")
<< QByteArray("src/plugins/mercurial/mercurialeditor.cpp");
QTest::newRow("Normal") << QByteArray(
"diff --git a/src/plugins/mercurial/mercurialeditor.cpp b/src/plugins/mercurial/mercurialeditor.cpp\n"
"--- a/src/plugins/mercurial/mercurialeditor.cpp\n"
"+++ b/src/plugins/mercurial/mercurialeditor.cpp\n"
"@@ -49,6 +49,8 @@\n\n")
<< QByteArray("src/plugins/mercurial/mercurialeditor.cpp");
}
void MercurialPlugin::testDiffFileResolving()
{
MercurialEditor editor(editorParameters + 3, 0);
VcsBase::VcsBaseEditorWidget::testDiffFileResolving(&editor);
}
#endif
Q_EXPORT_PLUGIN(MercurialPlugin)
......@@ -103,6 +103,10 @@ private slots:
void showCommitWidget(const QList<VcsBase::VcsBaseClient::StatusItem> &status);
void commitFromEditor();
void diffFromEditorSelected(const QStringList &files);
#ifdef WITH_TESTS
void testDiffFileResolving_data();
void testDiffFileResolving();
#endif
//TODO implement
/* //repository management action slots
......
......@@ -255,9 +255,4 @@ void DiffHighlighter::setFormats(const QVector<QTextCharFormat> &s)
}
}
QRegExp DiffHighlighter::filePattern() const
{
return d->m_filePattern;
}
} // namespace VcsBase
......@@ -59,8 +59,6 @@ public:
// Set formats from a sequence of type QTextCharFormat
void setFormats(const QVector<QTextCharFormat> &s);
QRegExp filePattern() const;
private:
Internal::DiffHighlighterPrivate *const d;
};
......
......@@ -184,10 +184,6 @@ public:
bool setConfigurationWidget(QWidget *w);
QWidget *configurationWidget() const;
// Returns a local file name from the diff file specification
// (text cursor at position above change hunk)
QString fileNameFromDiffSpecification(const QTextBlock &inBlock) const;
/* Tagging editors: Sometimes, an editor should be re-used, for example, when showing
* a diff of the same file with different diff-options. In order to be able to find
* the editor, they get a 'tag' containing type and parameters (dynamic property string). */
......@@ -248,6 +244,10 @@ protected:
// Factory functions for highlighters
virtual BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes,
const QColor &bg) const = 0;
// Returns a local file name from the diff file specification
// (text cursor at position above change hunk)
QString fileNameFromDiffSpecification(const QTextBlock &inBlock) const;
// Implement to return decorated annotation change for "Annotate version"
virtual QString decorateVersion(const QString &revision) const;
// Implement to return the previous version[s] of an annotation change
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment