New test. Check ellipsis at the end of line.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-09-24 10:33:35 +03:00
parent d44638eab2
commit 0fd36056d4
2 changed files with 80 additions and 32 deletions

View File

@ -116,37 +116,7 @@ void TST_TSTranslation::CheckEnglishLocalization()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TST_TSTranslation::CheckEmptyToolButton_data() void TST_TSTranslation::CheckEmptyToolButton_data()
{ {
QTest::addColumn<QString>("source"); PrepareOriginalStrings();
QTest::addColumn<QDomElement>("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));
}
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -367,7 +337,8 @@ void TST_TSTranslation::TestPunctuation()
<< QLatin1String("\n") << QLatin1String("\n")
<< QLatin1String("!") << QLatin1String("!")
<< QLatin1String("?") << QLatin1String("?")
<< QLatin1String(";"); << QLatin1String(";")
<< "";
bool testFail = false; bool testFail = false;
const QChar cSource = source.at(source.length()-1); const QChar cSource = source.at(source.length()-1);
QChar cPunctuation = cSource; 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) QDomNodeList TST_TSTranslation::LoadTSFile(const QString &filename)
{ {
@ -535,3 +543,39 @@ QDomNodeList TST_TSTranslation::LoadTSFile(const QString &filename)
return messages; return messages;
} }
//---------------------------------------------------------------------------------------------------------------------
void TST_TSTranslation::PrepareOriginalStrings()
{
QTest::addColumn<QString>("source");
QTest::addColumn<QDomElement>("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));
}
}
}

View File

@ -51,6 +51,8 @@ private slots:
void TestPunctuation(); void TestPunctuation();
void TestHTMLTags_data(); void TestHTMLTags_data();
void TestHTMLTags(); void TestHTMLTags();
void CheckEllipsis_data();
void CheckEllipsis();
private: private:
Q_DISABLE_COPY(TST_TSTranslation) Q_DISABLE_COPY(TST_TSTranslation)
@ -68,6 +70,8 @@ private:
static const QString AttrValObsolete; static const QString AttrValObsolete;
QDomNodeList LoadTSFile(const QString &filename); QDomNodeList LoadTSFile(const QString &filename);
void PrepareOriginalStrings();
}; };
#endif // TST_TSTRANSLATION_H #endif // TST_TSTRANSLATION_H