Commit b434f0e3 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add autotests

parent 5647e32f
Pipeline #144038 passed with stages
in 2 minutes and 29 seconds
......@@ -7,7 +7,7 @@
#pragma once
#include "kpimtextedit/texteditfindbarbase.h"
#include "kpimtextedit_private_export.h"
#include <QChar>
#include <QStringView>
#include <QTextDocument>
......@@ -27,9 +27,11 @@ namespace FindUtils
*
* @return number of replacements done
*/
Q_REQUIRED_RESULT int replaceAll(QPlainTextEdit *view, const QString &str, const QString &replaceWidget, QTextDocument::FindFlags searchOptions);
Q_REQUIRED_RESULT int replaceAll(QTextEdit *view, const QString &str, const QString &replaceWidget, QTextDocument::FindFlags searchOptions);
Q_REQUIRED_RESULT int
Q_REQUIRED_RESULT KPIMTEXTEDIT_TESTS_EXPORT int
replaceAll(QPlainTextEdit *view, const QString &str, const QString &replaceWidget, QTextDocument::FindFlags searchOptions);
Q_REQUIRED_RESULT KPIMTEXTEDIT_TESTS_EXPORT int
replaceAll(QTextEdit *view, const QString &str, const QString &replaceWidget, QTextDocument::FindFlags searchOptions);
Q_REQUIRED_RESULT KPIMTEXTEDIT_TESTS_EXPORT int
replaceAll(QTextDocument *document, const QRegularExpression &regExp, const QString &replaceWidget, QTextDocument::FindFlags searchOptions);
Q_REQUIRED_RESULT QString normalize(QStringView str);
Q_REQUIRED_RESULT QChar normalize(QChar c);
......
......@@ -5,12 +5,14 @@
*/
#include "plaintexteditfindbartest.h"
#include "texteditor/commonwidget/findutils.h"
#include "texteditor/plaintexteditor/plaintexteditfindbar.h"
#include <QPlainTextEdit>
#include <QTest>
QTEST_MAIN(PlainTextEditFindBarTest)
Q_DECLARE_METATYPE(KPIMTextEdit::TextEditFindBarBase::FindFlags)
Q_DECLARE_METATYPE(QTextDocument::FindFlags)
PlainTextEditFindBarTest::PlainTextEditFindBarTest(QObject *parent)
: QObject{parent}
{
......@@ -89,3 +91,29 @@ void PlainTextEditFindBarTest::shouldSearchText()
QCOMPARE(w.searchInDocument(searchText, flags), found);
}
void PlainTextEditFindBarTest::shouldReplaceAllText_data()
{
QTest::addColumn<QString>("text");
QTest::addColumn<QString>("searchText");
QTest::addColumn<QString>("replaceText");
QTest::addColumn<QTextDocument::FindFlags>("flags");
QTest::addColumn<int>("nbElement");
QTest::newRow("empty") << QString() << QStringLiteral("blabla") << QStringLiteral("replace") << QTextDocument::FindFlags() << 0;
}
void PlainTextEditFindBarTest::shouldReplaceAllText()
{
QFETCH(QString, text);
QFETCH(QString, searchText);
QFETCH(QString, replaceText);
QFETCH(QTextDocument::FindFlags, flags);
QFETCH(int, nbElement);
QPlainTextEdit edit;
PlainTextEditFindBarExample w(&edit);
edit.setPlainText(text);
QCOMPARE(KPIMTextEdit::FindUtils::replaceAll(&edit, searchText, replaceText, flags), nbElement);
}
......@@ -18,4 +18,6 @@ private Q_SLOTS:
void shouldHaveDefaultValues();
void shouldSearchText_data();
void shouldSearchText();
void shouldReplaceAllText_data();
void shouldReplaceAllText();
};
Supports Markdown
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