Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit be109435 authored by Laurent Montel's avatar Laurent Montel 😁

Use class base

parent cdacc0f1
......@@ -18,7 +18,7 @@
*/
#include "grammalectegrammarerrortest.h"
#include "grammarerror.h"
#include "grammalectegrammarerror.h"
#include <QJsonDocument>
#include <QStandardPaths>
#include <QTest>
......@@ -32,7 +32,7 @@ GrammalecteGrammarErrorTest::GrammalecteGrammarErrorTest(QObject *parent)
void GrammalecteGrammarErrorTest::shouldHaveDefaultValue()
{
GrammarError info;
GrammalecteGrammarError info;
QCOMPARE(info.end(), -1);
QCOMPARE(info.start(), -1);
QCOMPARE(info.blockId(), -1);
......@@ -46,9 +46,9 @@ void GrammalecteGrammarErrorTest::shouldParseJson_data()
{
QTest::addColumn<QString>("fileName");
QTest::addColumn<int>("nbBlock");
QTest::addColumn<GrammarError>("error");
QTest::newRow("empty-error") << QStringLiteral("empty-error") << 1 << GrammarError();
GrammarError err;
QTest::addColumn<GrammalecteGrammarError>("error");
QTest::newRow("empty-error") << QStringLiteral("empty-error") << 1 << GrammalecteGrammarError();
GrammalecteGrammarError err;
err.setBlockId(1);
err.setStart(15);
err.setEnd(20);
......@@ -66,7 +66,7 @@ void GrammalecteGrammarErrorTest::shouldParseJson()
{
QFETCH(QString, fileName);
QFETCH(int, nbBlock);
QFETCH(GrammarError, error);
QFETCH(GrammalecteGrammarError, error);
const QString originalJsonFile = QLatin1String(GRAMMALECTE_DATA_DIR) + QLatin1Char('/') + fileName + QStringLiteral(".json");
QFile f(originalJsonFile);
QVERIFY(f.open(QIODevice::ReadOnly));
......@@ -74,7 +74,7 @@ void GrammalecteGrammarErrorTest::shouldParseJson()
f.close();
const QJsonDocument doc = QJsonDocument::fromJson(content);
const QJsonObject fields = doc.object();
GrammarError parser;
GrammalecteGrammarError parser;
parser.parse(fields, nbBlock);
const bool compare = (parser == error);
if (!compare) {
......
......@@ -24,6 +24,11 @@ GrammalecteGrammarError::GrammalecteGrammarError()
}
GrammalecteGrammarError::~GrammalecteGrammarError()
{
}
void GrammalecteGrammarError::parse(const QJsonObject &obj, int blockindex)
{
mEnd = obj[QStringLiteral("nEnd")].toInt(-1);
......
......@@ -21,12 +21,15 @@
#define GRAMMALECTEGRAMMARERROR_H
#include "grammarerror.h"
class GrammalecteGrammarError : public GrammarError
#include "libgrammalect_private_export.h"
class LIBGRAMMALECTPRIVATE_TESTS_EXPORT GrammalecteGrammarError : public GrammarError
{
public:
GrammalecteGrammarError();
void parse(const QJsonObject &obj, int blockindex);
~GrammalecteGrammarError() override;
void parse(const QJsonObject &obj, int blockindex) override;
};
Q_DECLARE_METATYPE(GrammalecteGrammarError)
Q_DECLARE_TYPEINFO(GrammalecteGrammarError, Q_MOVABLE_TYPE);
#endif // GRAMMALECTEGRAMMARERROR_H
......@@ -48,7 +48,7 @@ QVector<GrammarError> GrammalecteParser::parseResult(const QJsonObject &obj) con
const QJsonArray grammarErrorArray = grammaObject.value(QLatin1String("lGrammarErrors")).toArray();
for (const QJsonValue &error : grammarErrorArray) {
//qDebug() << " grammarErrorArray"<<error;
GrammarError info;
GrammalecteGrammarError info;
if (error.type() == QJsonValue::Object) {
info.parse(error.toObject(), blockId);
if (info.isValid()) {
......
......@@ -23,7 +23,7 @@
#include <QVector>
#include <QJsonObject>
#include "libgrammalect_private_export.h"
#include "grammarerror.h"
#include "grammalectegrammarerror.h"
class LIBGRAMMALECTPRIVATE_TESTS_EXPORT GrammalecteParser
{
public:
......
......@@ -22,7 +22,7 @@
#include <QWidget>
#include "libkmailgrammalecte_export.h"
#include "grammarerror.h"
#include "grammalectegrammarerror.h"
namespace MessageComposer {
class PluginGrammarAction;
}
......
......@@ -99,20 +99,10 @@ bool GrammarError::isValid() const
return false;
}
//Make as virtual
void GrammarError::parse(const QJsonObject &obj, int blockindex)
{
mEnd = obj[QStringLiteral("nEnd")].toInt(-1);
mStart = obj[QStringLiteral("nStart")].toInt(-1);
mError = obj[QStringLiteral("sMessage")].toString();
if (mEnd != -1) {
mBlockId = blockindex;
mColor = parseColor(obj);
mSuggestions = parseSuggestion(obj);
}
mRule = obj[QStringLiteral("sRuleId")].toString();
mOption = obj[QStringLiteral("sType")].toString();
mUrl = obj[QStringLiteral("URL")].toString();
Q_UNUSED(obj);
Q_UNUSED(blockindex);
}
bool GrammarError::operator ==(const GrammarError &other) const
......
......@@ -30,7 +30,7 @@ class GRAMMARCOMMON_EXPORT GrammarError
{
public:
GrammarError();
~GrammarError();
virtual ~GrammarError();
Q_REQUIRED_RESULT QColor color() const;
void setColor(const QColor &color);
......@@ -51,7 +51,7 @@ public:
Q_REQUIRED_RESULT bool isValid() const;
void parse(const QJsonObject &obj, int blockindex);
virtual void parse(const QJsonObject &obj, int blockindex);
Q_REQUIRED_RESULT bool operator ==(const GrammarError &other) const;
......
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