Commit e09b700b authored by Michael Reeves's avatar Michael Reeves

Add simple auto test for CvsIgnoreList

parent 4e02946e
......@@ -9,3 +9,9 @@ ecm_add_test(commentparser.cpp ../CommentParser.cpp
TEST_NAME "commentparser"
LINK_LIBRARIES Qt5::Test
)
ecm_add_test(CvsIgnorelist.cpp ../cvsignorelist.cpp
TEST_NAME "cvsignorelisttest"
LINK_LIBRARIES Qt5::Test
)
/**
* Copyright (C) 2019 Michael Reeves <reeves.87@gmail.com>
*
* This file is part of KDiff3.
*
* KDiff3 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* KDiff3 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KDiff3. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QTest>
#include "../cvsignorelist.h"
class CvsIgnoreListTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void init()
{
CvsIgnoreList test;
//sanity check defaults
QVERIFY(test.m_exactPatterns.isEmpty());
QVERIFY(test.m_endPatterns.isEmpty());
QVERIFY(test.m_generalPatterns.isEmpty());
QVERIFY(test.m_startPatterns.isEmpty());
}
void addEntriesFromString()
{
CvsIgnoreList test;
QStringList expected;
test.addEntriesFromString(". .. core RCSLOG tags TAGS RCS SCCS .make.state");
expected = QStringList{".", "..", "core", "RCSLOG", "tags", "TAGS", "RCS", "SCCS", ".make.state"};
QVERIFY(!test.m_exactPatterns.isEmpty());
QVERIFY(test.m_exactPatterns == expected);
}
};
QTEST_MAIN(CvsIgnoreListTest);
#include "CvsIgnorelist.moc"
#include <QString>
#include <list>
typedef class MocIgnoreFile FileAccess;
typedef std::list<FileAccess> t_DirectoryList;
class MocIgnoreFile
{
public:
void mocSetPath(const QString& path) { mPath = path; }
void mocSetIsLocal(bool local) { mLocal = local; }
void addPath(const QString& txt) { Q_UNUSED(txt); }
QString absoluteFilePath() const { return mPath; }
bool createLocalCopy() { return true; }
bool isLocal() const { return mLocal; }
bool exists() const { return mExists; }
QString getTempName() const { return mPath; }
QString fileName(bool needTmp = false) const
{
Q_UNUSED(needTmp);
return ".cvsignore";
}
private:
QString mPath = "/test/ui/.cvsignore";
bool mLocal = true, mExists = true;
};
......@@ -62,8 +62,14 @@ void CvsIgnoreList::addEntriesFromString(const QString& str)
addEntry(str.mid(posLast));
}
/*
MocIgnoreFile is incapatiable with addEntriesFromFile so do nothing in AUTORUN mode
*/
void CvsIgnoreList::addEntriesFromFile(const QString& name)
{
#ifdef AUTORUN
Q_UNUSED(name)
#else
QFile file(name);
if(file.open(QIODevice::ReadOnly))
......@@ -74,6 +80,7 @@ void CvsIgnoreList::addEntriesFromFile(const QString& name)
addEntry(stream.readLine());
}
}
#endif
}
void CvsIgnoreList::addEntry(const QString& pattern)
......
......@@ -14,7 +14,14 @@
#ifndef CVSIGNORELIST_H
#define CVSIGNORELIST_H
#ifndef AUTOTEST
#include "fileaccess.h"
#else
#include "MocIgnoreFile.h"
#endif
#include <QStringList>
#include <QString>
class CvsIgnoreList
{
......@@ -24,6 +31,7 @@ class CvsIgnoreList
bool matches(const QString& text, bool bCaseSensitive) const;
private:
friend class CvsIgnoreListTest;
bool cvsIgnoreExists(const t_DirectoryList* pDirList);
void addEntriesFromString(const QString& str);
......
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