From 0fd36056d4a89a13fd913146a8411627dd328ac4 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 24 Sep 2017 10:33:35 +0300 Subject: [PATCH] New test. Check ellipsis at the end of line. --HG-- branch : develop --- .../TranslationsTest/tst_tstranslation.cpp | 108 ++++++++++++------ src/test/TranslationsTest/tst_tstranslation.h | 4 + 2 files changed, 80 insertions(+), 32 deletions(-) diff --git a/src/test/TranslationsTest/tst_tstranslation.cpp b/src/test/TranslationsTest/tst_tstranslation.cpp index 2d0c76a7d..320276856 100644 --- a/src/test/TranslationsTest/tst_tstranslation.cpp +++ b/src/test/TranslationsTest/tst_tstranslation.cpp @@ -116,37 +116,7 @@ void TST_TSTranslation::CheckEnglishLocalization() //--------------------------------------------------------------------------------------------------------------------- void TST_TSTranslation::CheckEmptyToolButton_data() { - QTest::addColumn("source"); - QTest::addColumn("message"); - - const QString fileName = QStringLiteral("valentina.ts"); - const QDomNodeList messages = LoadTSFile(fileName); - if (messages.isEmpty()) - { - QFAIL("Can't begin test."); - } - - for (qint32 i = 0, num = messages.size(); i < num; ++i) - { - const QDomElement message = messages.at(i).toElement(); - if (message.isNull() == false) - { - const QString source = message.firstChildElement(TagSource).text(); - if (source.isEmpty()) - { - continue; - } - - const QString tag = QString("File '%1'. Check modification source message '%2'.").arg(fileName) - .arg(source); - QTest::newRow(qUtf8Printable(tag)) << source << message; - } - else - { - const QString message = QString("Message %1 is null.").arg(i); - QFAIL(qUtf8Printable(message)); - } - } + PrepareOriginalStrings(); } //--------------------------------------------------------------------------------------------------------------------- @@ -367,7 +337,8 @@ void TST_TSTranslation::TestPunctuation() << QLatin1String("\n") << QLatin1String("!") << QLatin1String("?") - << QLatin1String(";"); + << QLatin1String(";") + << "…"; bool testFail = false; const QChar cSource = source.at(source.length()-1); QChar cPunctuation = cSource; @@ -494,6 +465,43 @@ void TST_TSTranslation::TestHTMLTags() } } +//--------------------------------------------------------------------------------------------------------------------- +void TST_TSTranslation::CheckEllipsis_data() +{ + PrepareOriginalStrings(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_TSTranslation::CheckEllipsis() +{ + QFETCH(QString, source); + QFETCH(QDomElement, message); + + if (source.endsWith("...")) + { + const QDomElement translationTag = message.firstChildElement(TagTranslation); + if (translationTag.hasAttribute(AttrType)) + { + const QString attrVal = translationTag.attribute(AttrType); + if (attrVal == AttrValVanished || attrVal == AttrValObsolete) + { + return; + } + } + + const QDomNode context = message.parentNode(); + if (context.isNull()) + { + QFAIL("Can't get context."); + } + + const QString contextName = context.firstChildElement(TagName).text(); + const QString error = QString("String '%1' ends with '...' in context '%2'. Repalce it with '…'.") + .arg(source, contextName); + QFAIL(qUtf8Printable(error)); + } +} + //--------------------------------------------------------------------------------------------------------------------- QDomNodeList TST_TSTranslation::LoadTSFile(const QString &filename) { @@ -535,3 +543,39 @@ QDomNodeList TST_TSTranslation::LoadTSFile(const QString &filename) return messages; } + +//--------------------------------------------------------------------------------------------------------------------- +void TST_TSTranslation::PrepareOriginalStrings() +{ + QTest::addColumn("source"); + QTest::addColumn("message"); + + const QString fileName = QStringLiteral("valentina.ts"); + const QDomNodeList messages = LoadTSFile(fileName); + if (messages.isEmpty()) + { + QFAIL("Can't begin test."); + } + + for (qint32 i = 0, num = messages.size(); i < num; ++i) + { + const QDomElement message = messages.at(i).toElement(); + if (message.isNull() == false) + { + const QString source = message.firstChildElement(TagSource).text(); + if (source.isEmpty()) + { + continue; + } + + const QString tag = QString("File '%1'. Check modification source message '%2'.").arg(fileName) + .arg(source); + QTest::newRow(qUtf8Printable(tag)) << source << message; + } + else + { + const QString message = QString("Message %1 is null.").arg(i); + QFAIL(qUtf8Printable(message)); + } + } +} diff --git a/src/test/TranslationsTest/tst_tstranslation.h b/src/test/TranslationsTest/tst_tstranslation.h index aa68586cd..d814deea4 100644 --- a/src/test/TranslationsTest/tst_tstranslation.h +++ b/src/test/TranslationsTest/tst_tstranslation.h @@ -51,6 +51,8 @@ private slots: void TestPunctuation(); void TestHTMLTags_data(); void TestHTMLTags(); + void CheckEllipsis_data(); + void CheckEllipsis(); private: Q_DISABLE_COPY(TST_TSTranslation) @@ -68,6 +70,8 @@ private: static const QString AttrValObsolete; QDomNodeList LoadTSFile(const QString &filename); + + void PrepareOriginalStrings(); }; #endif // TST_TSTRANSLATION_H