Commit 2198fa90 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Tobias Hunger

Git: Add tests for status line parsing

Change-Id: I1519672ffbaafc1367addde5cd2111b1fe9810b2
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent fc31836e
......@@ -1067,4 +1067,48 @@ GitClient *GitPlugin::gitClient() const
return m_gitClient;
}
#ifdef WITH_TESTS
#include <QTest>
Q_DECLARE_METATYPE(CommitData::FileState)
void GitPlugin::testStatusParsing_data()
{
QTest::addColumn<QString>("line");
QTest::addColumn<CommitData::FileState>("first");
QTest::addColumn<CommitData::FileState>("second");
#define STATUS_TEST(status, first, second) \
QTest::newRow(status) << QString::fromLatin1(status) << CommitData::first << CommitData::second;
STATUS_TEST(" M", ModifiedFile, UnknownFileState);
STATUS_TEST(" D", DeletedFile, UnknownFileState);
STATUS_TEST("M ", ModifiedStagedFile, UnknownFileState);
STATUS_TEST("MM", ModifiedStagedFile, ModifiedFile);
STATUS_TEST("MD", ModifiedStagedFile, DeletedFile);
STATUS_TEST("A ", AddedStagedFile, UnknownFileState);
STATUS_TEST("AM", AddedStagedFile, ModifiedFile);
STATUS_TEST("AD", AddedStagedFile, DeletedFile);
STATUS_TEST("D ", DeletedStagedFile, UnknownFileState);
STATUS_TEST("DM", DeletedStagedFile, ModifiedFile);
STATUS_TEST("R ", RenamedStagedFile, UnknownFileState);
STATUS_TEST("RM", RenamedStagedFile, ModifiedFile);
STATUS_TEST("RD", RenamedStagedFile, DeletedFile);
STATUS_TEST("C ", CopiedStagedFile, UnknownFileState);
STATUS_TEST("CM", CopiedStagedFile, ModifiedFile);
STATUS_TEST("CD", CopiedStagedFile, DeletedFile);
}
void GitPlugin::testStatusParsing()
{
CommitData data;
QFETCH(QString, line);
QFETCH(CommitData::FileState, first);
QFETCH(CommitData::FileState, second);
QString output = QLatin1String("## master...origin/master [ahead 1]\n");
output += line + QLatin1String(" main.cpp\n");
data.parseFilesFromStatus(output);
QCOMPARE(data.files.at(0).first, first);
if (second != CommitData::UnknownFileState)
QCOMPARE(data.files.at(1).first, second);
}
#endif
Q_EXPORT_PLUGIN(GitPlugin)
......@@ -132,6 +132,10 @@ private slots:
void pull();
void push();
#ifdef WITH_TESTS
void testStatusParsing_data();
void testStatusParsing();
#endif
protected:
virtual void updateActions(VcsBase::VcsBasePlugin::ActionState);
virtual bool submitEditorAboutToClose(VcsBase::VcsBaseSubmitEditor *submitEditor);
......
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