Commit 28e47cdc authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add searchText autotest

parent 27ec874d
Pipeline #142511 passed with stages
in 2 minutes and 39 seconds
......@@ -10,6 +10,7 @@
#include <QTest>
QTEST_MAIN(PlainTextEditFindBarTest)
Q_DECLARE_METATYPE(KPIMTextEdit::TextEditFindBarBase::FindFlags)
PlainTextEditFindBarTest::PlainTextEditFindBarTest(QObject *parent)
: QObject{parent}
{
......@@ -21,3 +22,70 @@ void PlainTextEditFindBarTest::shouldHaveDefaultValues()
KPIMTextEdit::PlainTextEditFindBar w(&edit);
QVERIFY(w.text().isEmpty());
}
class PlainTextEditFindBarExample : public KPIMTextEdit::PlainTextEditFindBar
{
public:
explicit PlainTextEditFindBarExample(QPlainTextEdit *view, QWidget *parent = nullptr)
: PlainTextEditFindBar(view, parent)
{
}
~PlainTextEditFindBarExample() override = default;
Q_REQUIRED_RESULT bool searchInDocument(const QString &text, TextEditFindBarBase::FindFlags searchOptions) override
{
return KPIMTextEdit::PlainTextEditFindBar::searchInDocument(text, searchOptions);
}
Q_REQUIRED_RESULT bool searchInDocument(const QRegularExpression &regExp, TextEditFindBarBase::FindFlags searchOptions) override
{
return KPIMTextEdit::PlainTextEditFindBar::searchInDocument(regExp, searchOptions);
}
};
void PlainTextEditFindBarTest::shouldSearchText_data()
{
QTest::addColumn<QString>("text");
QTest::addColumn<QString>("searchText");
QTest::addColumn<KPIMTextEdit::TextEditFindBarBase::FindFlags>("flags");
QTest::addColumn<bool>("found");
QTest::newRow("empty") << QString() << QStringLiteral("blabla") << KPIMTextEdit::TextEditFindBarBase::FindFlags() << false;
{
KPIMTextEdit::TextEditFindBarBase::FindFlags flags;
flags |= KPIMTextEdit::TextEditFindBarBase::FindRespectDiacritics;
QTest::newRow("empty-1") << QString() << QStringLiteral("blabla") << flags << false;
}
{
KPIMTextEdit::TextEditFindBarBase::FindFlags flags;
flags |= KPIMTextEdit::TextEditFindBarBase::FindCaseSensitively;
QTest::newRow("empty-2") << QString() << QStringLiteral("blabla") << flags << false;
}
{
KPIMTextEdit::TextEditFindBarBase::FindFlags flags;
flags |= KPIMTextEdit::TextEditFindBarBase::FindWholeWords;
QTest::newRow("findwholewords-1") << QStringLiteral("bla bla") << QStringLiteral("bla") << flags << true;
QTest::newRow("findwholewords-2") << QStringLiteral("blabla") << QStringLiteral("bla") << flags << false;
}
{
KPIMTextEdit::TextEditFindBarBase::FindFlags flags;
flags |= KPIMTextEdit::TextEditFindBarBase::FindRespectDiacritics;
QTest::newRow("find-diacritics-1") << QStringLiteral("numéro numéro") << QStringLiteral("numero") << flags << false;
QTest::newRow("find-diacritics-2") << QStringLiteral("numéro numéro") << QStringLiteral("numéro") << flags << true;
}
}
void PlainTextEditFindBarTest::shouldSearchText()
{
QFETCH(QString, text);
QFETCH(QString, searchText);
QFETCH(KPIMTextEdit::TextEditFindBarBase::FindFlags, flags);
QFETCH(bool, found);
QPlainTextEdit edit;
PlainTextEditFindBarExample w(&edit);
edit.setPlainText(text);
QCOMPARE(w.searchInDocument(searchText, flags), found);
}
......@@ -16,4 +16,6 @@ public:
~PlainTextEditFindBarTest() override = default;
private Q_SLOTS:
void shouldHaveDefaultValues();
void shouldSearchText_data();
void shouldSearchText();
};
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