mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-07-26 08:15:32 -04:00
Refactor wildcard matcher test.
This commit is contained in:
parent
53ce522c08
commit
c0e91e4f16
2 changed files with 37 additions and 97 deletions
|
@ -25,95 +25,35 @@
|
||||||
const QString TestWildcardMatcher::DefaultText = QString("some text");
|
const QString TestWildcardMatcher::DefaultText = QString("some text");
|
||||||
const QString TestWildcardMatcher::AlternativeText = QString("some other text");
|
const QString TestWildcardMatcher::AlternativeText = QString("some other text");
|
||||||
|
|
||||||
void TestWildcardMatcher::testMatchWithoutWildcard()
|
void TestWildcardMatcher::testMatcher_data()
|
||||||
{
|
{
|
||||||
initMatcher(DefaultText);
|
QTest::addColumn<QString>("text");
|
||||||
QString pattern = DefaultText;
|
QTest::addColumn<QString>("pattern");
|
||||||
verifyMatch(pattern);
|
QTest::addColumn<bool>("match");
|
||||||
|
|
||||||
|
QTest::newRow("MatchWithoutWildcard") << DefaultText << DefaultText << true;
|
||||||
|
QTest::newRow("NoMatchWithoutWildcard") << DefaultText << QString("no match text") << false;
|
||||||
|
QTest::newRow("MatchWithOneWildcardInTheMiddle") << AlternativeText << QString("some*text") << true;
|
||||||
|
QTest::newRow("NoMatchWithOneWildcardInTheMiddle") << AlternativeText << QString("differen*text") << false;
|
||||||
|
QTest::newRow("MatchWithOneWildcardAtBegin") << DefaultText << QString("*text") << true;
|
||||||
|
QTest::newRow("NoMatchWithOneWildcardAtBegin") << DefaultText << QString("*text something else") << false;
|
||||||
|
QTest::newRow("NatchWithOneWildcardAtEnd") << DefaultText << QString("some*") << true;
|
||||||
|
QTest::newRow("NoMatchWithOneWildcardAtEnd") << DefaultText << QString("some other*") << false;
|
||||||
|
QTest::newRow("MatchWithMultipleWildcards") << AlternativeText << QString("some*th*text") << true;
|
||||||
|
QTest::newRow("NoMatchWithMultipleWildcards") << AlternativeText << QString("some*abc*text") << false;
|
||||||
|
QTest::newRow("MatchJustWildcard") << DefaultText << QString("*") << true;
|
||||||
|
QTest::newRow("MatchFollowingWildcards") << DefaultText << QString("some t**t") << true;
|
||||||
|
QTest::newRow("CaseSensitivity") << DefaultText.toUpper() << QString("some t**t") << true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestWildcardMatcher::testNoMatchWithoutWildcard()
|
void TestWildcardMatcher::testMatcher()
|
||||||
{
|
{
|
||||||
initMatcher(DefaultText);
|
QFETCH(QString, text);
|
||||||
QString pattern = QString("no match text");
|
QFETCH(QString, pattern);
|
||||||
verifyNoMatch(pattern);
|
QFETCH(bool, match);
|
||||||
}
|
|
||||||
|
|
||||||
void TestWildcardMatcher::testMatchWithOneWildcardInTheMiddle()
|
initMatcher(text);
|
||||||
{
|
verifyMatchResult(pattern, match);
|
||||||
initMatcher(AlternativeText);
|
|
||||||
QString pattern("some*text");
|
|
||||||
verifyMatch(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestWildcardMatcher::testNoMatchWithOneWildcardInTheMiddle()
|
|
||||||
{
|
|
||||||
initMatcher(AlternativeText);
|
|
||||||
QString pattern("differen*text");
|
|
||||||
verifyNoMatch(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestWildcardMatcher::testMatchWithOneWildcardAtBegin()
|
|
||||||
{
|
|
||||||
initMatcher(DefaultText);
|
|
||||||
QString pattern("*text");
|
|
||||||
verifyMatch(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestWildcardMatcher::testNoMatchWithOneWildcardAtBegin()
|
|
||||||
{
|
|
||||||
initMatcher(DefaultText);
|
|
||||||
QString pattern("*text something else");
|
|
||||||
verifyNoMatch(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestWildcardMatcher::testMatchWithOneWildcardAtEnd()
|
|
||||||
{
|
|
||||||
initMatcher(DefaultText);
|
|
||||||
QString pattern("some*");
|
|
||||||
verifyMatch(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestWildcardMatcher::testNoMatchWithOneWildcardAtEnd()
|
|
||||||
{
|
|
||||||
initMatcher(DefaultText);
|
|
||||||
QString pattern("some other*");
|
|
||||||
verifyNoMatch(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestWildcardMatcher::testMatchWithMultipleWildcards()
|
|
||||||
{
|
|
||||||
initMatcher(AlternativeText);
|
|
||||||
QString pattern("some*th*text");
|
|
||||||
verifyMatch(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestWildcardMatcher::testNoMatchWithMultipleWildcards()
|
|
||||||
{
|
|
||||||
initMatcher(AlternativeText);
|
|
||||||
QString pattern("some*abc*text");
|
|
||||||
verifyNoMatch(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestWildcardMatcher::testMatchJustWildcard()
|
|
||||||
{
|
|
||||||
initMatcher(AlternativeText);
|
|
||||||
QString pattern("*");
|
|
||||||
verifyMatch(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestWildcardMatcher::testMatchFollowingWildcards()
|
|
||||||
{
|
|
||||||
initMatcher(DefaultText);
|
|
||||||
QString pattern("some t**t");
|
|
||||||
verifyMatch(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestWildcardMatcher::testCaseSensitivity()
|
|
||||||
{
|
|
||||||
initMatcher(DefaultText.toUpper());
|
|
||||||
QString pattern("some t**t");
|
|
||||||
verifyMatch(pattern);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestWildcardMatcher::initMatcher(QString text)
|
void TestWildcardMatcher::initMatcher(QString text)
|
||||||
|
@ -121,6 +61,16 @@ void TestWildcardMatcher::initMatcher(QString text)
|
||||||
m_matcher = new WildcardMatcher(text);
|
m_matcher = new WildcardMatcher(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestWildcardMatcher::verifyMatchResult(QString pattern, bool expected)
|
||||||
|
{
|
||||||
|
if (expected) {
|
||||||
|
verifyMatch(pattern);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
verifyNoMatch(pattern);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TestWildcardMatcher::verifyMatch(QString pattern)
|
void TestWildcardMatcher::verifyMatch(QString pattern)
|
||||||
{
|
{
|
||||||
bool matchResult = m_matcher->match(pattern);
|
bool matchResult = m_matcher->match(pattern);
|
||||||
|
|
|
@ -27,25 +27,15 @@ class TestWildcardMatcher : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void testMatchWithoutWildcard();
|
void testMatcher();
|
||||||
void testNoMatchWithoutWildcard();
|
void testMatcher_data();
|
||||||
void testMatchWithOneWildcardInTheMiddle();
|
|
||||||
void testNoMatchWithOneWildcardInTheMiddle();
|
|
||||||
void testNoMatchWithOneWildcardAtBegin();
|
|
||||||
void testMatchWithOneWildcardAtBegin();
|
|
||||||
void testNoMatchWithOneWildcardAtEnd();
|
|
||||||
void testMatchWithOneWildcardAtEnd();
|
|
||||||
void testMatchWithMultipleWildcards();
|
|
||||||
void testNoMatchWithMultipleWildcards();
|
|
||||||
void testMatchJustWildcard();
|
|
||||||
void testMatchFollowingWildcards();
|
|
||||||
void testCaseSensitivity();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const QString DefaultText;
|
static const QString DefaultText;
|
||||||
static const QString AlternativeText;
|
static const QString AlternativeText;
|
||||||
|
|
||||||
void initMatcher(QString text);
|
void initMatcher(QString text);
|
||||||
|
void verifyMatchResult(QString pattern, bool expected);
|
||||||
void verifyMatch(QString pattern);
|
void verifyMatch(QString pattern);
|
||||||
void verifyNoMatch(QString pattern);
|
void verifyNoMatch(QString pattern);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue