summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-09-05 20:33:32 (GMT)
committerMontel Laurent <montel@kde.org>2016-09-05 20:33:32 (GMT)
commitc2b51f1b8d22c455c17d8bb2ae5eecaf59e6e433 (patch)
tree847345a090a409d50f3dae062dd4da34531d64b1
parentd7ce6efa81f74e7d6f5e749807676c01c7832e01 (diff)
Add autotest to migrate to QRegularExpression
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/addressline/addresslineedit/addresseelineedit.cpp21
-rw-r--r--src/addressline/addresslineedit/addresseelineeditutil.cpp50
-rw-r--r--src/addressline/addresslineedit/addresseelineeditutil.h34
-rw-r--r--src/addressline/autotests/CMakeLists.txt5
-rw-r--r--src/addressline/autotests/addresseelineeditutiltest.cpp53
-rw-r--r--src/addressline/autotests/addresseelineeditutiltest.h37
7 files changed, 182 insertions, 19 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 62b557d..e63a83e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -75,6 +75,7 @@ set(kdepim_addressline_LIB_SRCS
addressline/recentaddress/recentaddressdialog.cpp
addressline/recentaddress/recentaddresswidget.cpp
addressline/recentaddress/recentaddresses.cpp
+ addressline/addresslineedit/addresseelineeditutil.cpp
)
set(kdepim_addressline_blacklist_baloo_LIB_SRCS
diff --git a/src/addressline/addresslineedit/addresseelineedit.cpp b/src/addressline/addresslineedit/addresseelineedit.cpp
index d5272c8..789608c 100644
--- a/src/addressline/addresslineedit/addresseelineedit.cpp
+++ b/src/addressline/addresslineedit/addresseelineedit.cpp
@@ -26,6 +26,7 @@
#include "addresseelineedit.h"
#include "addresseelineedit_p.h"
+#include "addresseelineeditutil.h"
#include "ldap/ldapclientsearch.h"
#include <KContacts/VCardConverter>
@@ -238,25 +239,7 @@ void AddresseeLineEdit::insert(const QString &t)
return;
}
- // remove newlines in the to-be-pasted string
- QStringList lines = newText.split(QRegExp(QLatin1String("\r?\n")), QString::SkipEmptyParts);
- QStringList::iterator end(lines.end());
- for (QStringList::iterator it = lines.begin(); it != end; ++it) {
- // remove trailing commas and whitespace
- (*it).remove(QRegExp(QLatin1String(",?\\s*$")));
- }
- newText = lines.join(QStringLiteral(", "));
-
- if (newText.startsWith(QStringLiteral("mailto:"))) {
- const QUrl url(newText);
- newText = url.path();
- } else if (newText.indexOf(QStringLiteral(" at ")) != -1) {
- // Anti-spam stuff
- newText.replace(QStringLiteral(" at "), QStringLiteral("@"));
- newText.replace(QStringLiteral(" dot "), QStringLiteral("."));
- } else if (newText.indexOf(QStringLiteral("(at)")) != -1) {
- newText.replace(QRegularExpression(QStringLiteral("\\s*\\(at\\)\\s*")), QStringLiteral("@"));
- }
+ newText = KPIM::AddresseeLineEditUtil::adaptPasteMails(newText);
QString contents = text();
int start_sel = 0;
diff --git a/src/addressline/addresslineedit/addresseelineeditutil.cpp b/src/addressline/addresslineedit/addresseelineeditutil.cpp
new file mode 100644
index 0000000..c2137f3
--- /dev/null
+++ b/src/addressline/addresslineedit/addresseelineeditutil.cpp
@@ -0,0 +1,50 @@
+/*
+ Copyright (C) 2016 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+
+#include "addresseelineeditutil.h"
+#include <QRegExp>
+#include <QRegularExpression>
+#include <QUrl>
+
+
+QString KPIM::AddresseeLineEditUtil::adaptPasteMails(QString str)
+{
+ QString newText = str;
+ // remove newlines in the to-be-pasted string
+ QStringList lines = newText.split(QRegExp(QLatin1String("\r?\n")), QString::SkipEmptyParts);
+ QStringList::iterator end(lines.end());
+ for (QStringList::iterator it = lines.begin(); it != end; ++it) {
+ // remove trailing commas and whitespace
+ (*it).remove(QRegExp(QLatin1String(",?\\s*$")));
+ }
+ newText = lines.join(QStringLiteral(", "));
+
+ if (newText.startsWith(QStringLiteral("mailto:"))) {
+ const QUrl url(newText);
+ newText = url.path();
+ } else if (newText.indexOf(QStringLiteral(" at ")) != -1) {
+ // Anti-spam stuff
+ newText.replace(QStringLiteral(" at "), QStringLiteral("@"));
+ newText.replace(QStringLiteral(" dot "), QStringLiteral("."));
+ } else if (newText.indexOf(QStringLiteral("(at)")) != -1) {
+ newText.replace(QRegularExpression(QStringLiteral("\\s*\\(at\\)\\s*")), QStringLiteral("@"));
+ }
+ return newText;
+}
diff --git a/src/addressline/addresslineedit/addresseelineeditutil.h b/src/addressline/addresslineedit/addresseelineeditutil.h
new file mode 100644
index 0000000..c61a8ab
--- /dev/null
+++ b/src/addressline/addresslineedit/addresseelineeditutil.h
@@ -0,0 +1,34 @@
+/*
+ Copyright (C) 2016 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+
+#ifndef ADDRESSEELINEEDITUTIL_H
+#define ADDRESSEELINEEDITUTIL_H
+
+#include <QString>
+
+namespace KPIM
+{
+namespace AddresseeLineEditUtil
+{
+ QString adaptPasteMails(QString str);
+}
+}
+
+#endif // ADDRESSEELINEEDITUTIL_H
diff --git a/src/addressline/autotests/CMakeLists.txt b/src/addressline/autotests/CMakeLists.txt
index f11c011..896fc70 100644
--- a/src/addressline/autotests/CMakeLists.txt
+++ b/src/addressline/autotests/CMakeLists.txt
@@ -27,3 +27,8 @@ add_libkdepim_addressline_unittest(completionconfiguredialogtest
add_libkdepim_addressline_unittest(completionorderwidgettest
completionorderwidgettest.cpp
)
+
+add_libkdepim_addressline_unittest(addresseelineeditutiltest
+ addresseelineeditutiltest.cpp
+ ../addresslineedit/addresseelineeditutil.cpp
+)
diff --git a/src/addressline/autotests/addresseelineeditutiltest.cpp b/src/addressline/autotests/addresseelineeditutiltest.cpp
new file mode 100644
index 0000000..3154c8d
--- /dev/null
+++ b/src/addressline/autotests/addresseelineeditutiltest.cpp
@@ -0,0 +1,53 @@
+/*
+ Copyright (C) 2016 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "addresseelineeditutiltest.h"
+#include "../addresslineedit/addresseelineeditutil.h"
+#include <QTest>
+
+AddresseeLineEditUtilTest::AddresseeLineEditUtilTest(QObject *parent)
+ : QObject(parent)
+{
+
+}
+
+AddresseeLineEditUtilTest::~AddresseeLineEditUtilTest()
+{
+
+}
+
+void AddresseeLineEditUtilTest::shouldAdaptPasteMails_data()
+{
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<QString>("output");
+
+ QTest::newRow("empty") << QString() << QString();
+ QTest::newRow("onemail") << QStringLiteral("foo@kde.org") << QStringLiteral("foo@kde.org");
+ QTest::newRow("onemailwithat") << QStringLiteral("foo (at) kde.org") << QStringLiteral("foo@kde.org");
+ QTest::newRow("text") << QStringLiteral("fookde.org") << QStringLiteral("fookde.org");
+}
+
+void AddresseeLineEditUtilTest::shouldAdaptPasteMails()
+{
+ QFETCH(QString, input);
+ QFETCH(QString, output);
+ QCOMPARE(KPIM::AddresseeLineEditUtil::adaptPasteMails(input), output);
+}
+
+QTEST_MAIN(AddresseeLineEditUtilTest)
diff --git a/src/addressline/autotests/addresseelineeditutiltest.h b/src/addressline/autotests/addresseelineeditutiltest.h
new file mode 100644
index 0000000..01efef3
--- /dev/null
+++ b/src/addressline/autotests/addresseelineeditutiltest.h
@@ -0,0 +1,37 @@
+/*
+ Copyright (C) 2016 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef ADDRESSEELINEEDITUTILTEST_H
+#define ADDRESSEELINEEDITUTILTEST_H
+
+#include <QObject>
+
+class AddresseeLineEditUtilTest : public QObject
+{
+ Q_OBJECT
+public:
+ explicit AddresseeLineEditUtilTest(QObject *parent = Q_NULLPTR);
+ ~AddresseeLineEditUtilTest();
+
+private Q_SLOTS:
+ void shouldAdaptPasteMails_data();
+ void shouldAdaptPasteMails();
+};
+
+#endif // ADDRESSEELINEEDITUTILTEST_H