Refactoring.

This commit is contained in:
Roman Telezhynskyi 2024-04-18 16:33:58 +03:00
parent 73cbe7cecb
commit df0d430c2b

View File

@ -273,7 +273,7 @@ void TST_TSLocaleTranslation::TestHTMLTags_data()
for (qint32 i = 0, num = messages.size(); i < num; ++i) for (qint32 i = 0, num = messages.size(); i < num; ++i)
{ {
const QDomElement message = messages.at(i).toElement(); const QDomElement message = messages.at(i).toElement();
if (message.isNull() == false) if (!message.isNull())
{ {
const QString source = message.firstChildElement(TagSource).text(); const QString source = message.firstChildElement(TagSource).text();
if (source.isEmpty()) if (source.isEmpty())
@ -313,22 +313,22 @@ void TST_TSLocaleTranslation::TestHTMLTags()
QFETCH(QString, source); QFETCH(QString, source);
QFETCH(QString, translation); QFETCH(QString, translation);
static const QStringList tags = QStringList() << "p"_L1 QRegularExpression::PatternOptions const patternOption = QRegularExpression::DotMatchesEverythingOption;
<< "html"_L1 static const QVector<std::pair<QRegularExpression, QRegularExpression>> regexes{
<< "body"_L1; std::make_pair(QRegularExpression(QStringLiteral("<p{1}.*>"), patternOption),
static const QString pattern("{1}.*>"); QRegularExpression(QStringLiteral("</p{1}.*>"), patternOption)),
for (const auto &tag : tags) std::make_pair(QRegularExpression(QStringLiteral("<html{1}.*>"), patternOption),
QRegularExpression(QStringLiteral("</html{1}.*>"), patternOption)),
std::make_pair(QRegularExpression(QStringLiteral("<body{1}.*>"), patternOption),
QRegularExpression(QStringLiteral("</body{1}.*>"), patternOption))};
for (const auto &regex : regexes)
{ {
const QRegularExpression openRegex("<"_L1 + tag + pattern, QRegularExpression::DotMatchesEverythingOption); if (source.contains(regex.first))
if (source.contains(openRegex))
{ {
const auto countOpenTag = source.count(openRegex); if (not translation.contains(regex.second) || translation.count(regex.second) != source.count(regex.first))
const QRegularExpression closeRegex("</"_L1 + tag + pattern,
QRegularExpression::DotMatchesEverythingOption);
const auto countCloseTag = translation.count(closeRegex);
if (not translation.contains(closeRegex) || countCloseTag != countOpenTag)
{ {
const QString message = u"Tag mismatch. Tag: '<%1>'. "_s.arg(tag) + const QString message = u"Tag mismatch. Pattern: '<%1>'. "_s.arg(regex.first.pattern()) +
u"Original name:'%1'"_s.arg(source) + u"Original name:'%1'"_s.arg(source) +
u", translated name:'%1'"_s.arg(translation); u", translated name:'%1'"_s.arg(translation);
QFAIL(qUtf8Printable(message)); QFAIL(qUtf8Printable(message));