summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-09-05 20:34:35 (GMT)
committerMontel Laurent <montel@kde.org>2016-09-05 20:34:35 (GMT)
commitc3ee531f33e97ca02c16de1cab7ca7f2207ea5d9 (patch)
tree35bdcfde0fbbdf322695b26c2bec7cb0f7cc47f7
parent60e128f577da3f26b68876eeba3432366c7f270f (diff)
improve autotest and migrate to QRegularExpression
-rw-r--r--src/composer-ng/autotests/richtextcomposertest.cpp20
-rw-r--r--src/composer-ng/autotests/richtextcomposertest.h3
-rw-r--r--src/composer-ng/richtextcomposercontroler.cpp5
3 files changed, 23 insertions, 5 deletions
diff --git a/src/composer-ng/autotests/richtextcomposertest.cpp b/src/composer-ng/autotests/richtextcomposertest.cpp
index a1c16d2..7206d53 100644
--- a/src/composer-ng/autotests/richtextcomposertest.cpp
+++ b/src/composer-ng/autotests/richtextcomposertest.cpp
@@ -464,16 +464,30 @@ void RichTextComposerTest::testLoadImage()
QCOMPARE(edit.composerControler()->composerImages()->embeddedImages().size(), 1);
}
+void RichTextComposerTest::testWrappedPlainText_data()
+{
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<QString>("output");
+
+ QString defaultStr = QStringLiteral("http://example.org/test-test-test-test-test-test-test-test-test-test-test-test-test\n https://example.org/test-test-test-test-test-test-test-test-test-test-test-test-test\ntest ftp://example.org/test-test-test-test-test-test-test-test-test-test-test-test-test\nftps://example.org/test-test-test-test-test-test-test-test-test-test-test-test-test\n ldap://example.org/test-test-test-test-test-test-test-test-test-test-test-test-test");
+ QTest::newRow("default") << defaultStr << defaultStr;
+ QTest::newRow("empty") << QString() << QString();
+ QTest::newRow("wrap") << QStringLiteral("foosdfsdf sdsf sdfsdfsfs fsf sdfs df sfsdf dsf sdfsdf sf sf sfsdf sdsdf") << QStringLiteral("foosdfsdf sdsf sdfsdfsfs fsf sdfs df sfsdf \ndsf sdfsdf sf sf sfsdf sdsdf");
+ QTest::newRow("wrap-2") << QStringLiteral("test-test-test-test-test-test-test-test-test-test-test-test-test") << QStringLiteral("test-test-test-test-test-test-test-test-test-\ntest-test-test-test");
+ QTest::newRow("wrap-3") << QStringLiteral("test-test-test-test-test-test-test-test-test-test-test-test-test\n\n") << QStringLiteral("test-test-test-test-test-test-test-test-test-\ntest-test-test-test\n\n");
+}
+
void RichTextComposerTest::testWrappedPlainText()
{
+ QFETCH(QString, input);
+ QFETCH(QString, output);
KPIMTextEdit::RichTextComposer edit;
edit.createActions(new KActionCollection(this));
- QString text(QStringLiteral("http://example.org/test-test-test-test-test-test-test-test-test-test-test-test-test\n https://example.org/test-test-test-test-test-test-test-test-test-test-test-test-test\ntest ftp://example.org/test-test-test-test-test-test-test-test-test-test-test-test-test\nftps://example.org/test-test-test-test-test-test-test-test-test-test-test-test-test\n ldap://example.org/test-test-test-test-test-test-test-test-test-test-test-test-test"));
- edit.setPlainText(text);
+ edit.setPlainText(input);
edit.show(); // < otherwise toWrappedPlainText can't work, it needs a layout
- QCOMPARE(edit.composerControler()->toWrappedPlainText(), text);
+ QCOMPARE(edit.composerControler()->toWrappedPlainText(), output);
}
void RichTextComposerTest::testEnableDisableActions()
diff --git a/src/composer-ng/autotests/richtextcomposertest.h b/src/composer-ng/autotests/richtextcomposertest.h
index 866b576..5a6a8b0 100644
--- a/src/composer-ng/autotests/richtextcomposertest.h
+++ b/src/composer-ng/autotests/richtextcomposertest.h
@@ -42,7 +42,10 @@ private Q_SLOTS:
void testDeleteLine();
void testDeleteLine_data();
void testLoadImage();
+
+ void testWrappedPlainText_data();
void testWrappedPlainText();
+
void testEnableDisableActions();
};
diff --git a/src/composer-ng/richtextcomposercontroler.cpp b/src/composer-ng/richtextcomposercontroler.cpp
index e587811..59791a4 100644
--- a/src/composer-ng/richtextcomposercontroler.cpp
+++ b/src/composer-ng/richtextcomposercontroler.cpp
@@ -24,6 +24,7 @@
#include "nestedlisthelper_p.h"
#include "inserthtmldialog.h"
#include <QApplication>
+#include <QRegularExpression>
#include <KColorScheme>
#include <KMessageBox>
@@ -35,6 +36,7 @@
#include <QPointer>
#include <QClipboard>
#include <QIcon>
+#include <QDebug>
#include "textutils.h"
#include "insertimagedialog.h"
@@ -884,7 +886,7 @@ QString RichTextComposerControler::toWrappedPlainText() const
QString RichTextComposerControler::toWrappedPlainText(QTextDocument *doc) const
{
QString temp;
- QRegExp rx(QLatin1String("(http|ftp|ldap)s?\\S+-$"));
+ QRegularExpression rx(QLatin1String("(http|ftp|ldap)s?\\S+-$"));
QTextBlock block = doc->begin();
while (block.isValid()) {
QTextLayout *layout = block.layout();
@@ -911,7 +913,6 @@ QString RichTextComposerControler::toWrappedPlainText(QTextDocument *doc) const
if (temp.endsWith(QLatin1Char('\n'))) {
temp.chop(1);
}
-
d->fixupTextEditString(temp);
return temp;
}