File indexing completed on 2024-12-22 04:28:19

0001 /*
0002    SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "grammalecteparsertest.h"
0008 #include "grammalecte/grammalecteparser.h"
0009 #include <QJsonDocument>
0010 #include <QStandardPaths>
0011 #include <QTest>
0012 QTEST_MAIN(GrammalecteParserTest)
0013 
0014 GrammalecteParserTest::GrammalecteParserTest(QObject *parent)
0015     : QObject(parent)
0016 {
0017     QStandardPaths::setTestModeEnabled(true);
0018 }
0019 
0020 void GrammalecteParserTest::shouldParseJson_data()
0021 {
0022     QTest::addColumn<QString>("fileName");
0023     QTest::addColumn<int>("numberOfElement");
0024     QTest::newRow("noerror") << QStringLiteral("noerror") << 0;
0025     QTest::newRow("noerror2") << QStringLiteral("noerror2") << 0;
0026     QTest::newRow("result2") << QStringLiteral("result2") << 3;
0027 }
0028 
0029 void GrammalecteParserTest::shouldParseJson()
0030 {
0031     QFETCH(QString, fileName);
0032     QFETCH(int, numberOfElement);
0033     const QString originalJsonFile = QLatin1String(GRAMMALECTE_DATA_DIR) + QLatin1Char('/') + fileName + QStringLiteral(".json");
0034     QFile f(originalJsonFile);
0035     QVERIFY(f.open(QIODevice::ReadOnly));
0036     const QByteArray content = f.readAll();
0037     f.close();
0038     const QJsonDocument doc = QJsonDocument::fromJson(content);
0039     const QJsonObject fields = doc.object();
0040     TextGrammarCheck::GrammalecteParser parser;
0041     QCOMPARE(parser.parseResult(fields).count(), numberOfElement);
0042 }
0043 
0044 #include "moc_grammalecteparsertest.cpp"