diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2023-07-27 15:02:56 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2023-08-16 16:25:48 +0200 |
commit | 91e70f239e166956c0db2d99cfb229c6b7d94598 (patch) | |
tree | 3613bca45096f6bd48b1ceaceb6906215c8c4dd4 /tests/auto/corelib/text/qlocale | |
parent | d7bad11a87a5edcc55e6d0a45201b48f52f54e23 (diff) |
Give QLocale::uiLanguages() a separator parameter
It has always returned dash-joined forms of the locale names, and
callers who need an underscore-joined form have been obliged to
replace('-', '_') before using them. Given that everything it adds to
the list comes from QLocaleId methods that accept a separator, it's
trivial to let it offer the same choice to its callers and save them
this hassle.
Amended code in QTranslater and QMimeType to save them that hassle.
[ChangeLog][CoreLib][QLocale] QLocale::uiLanguages() now lets the
caller choose what separator to use between the tags that make up each
locale-identifier in the list returned.
Change-Id: I91fcd0b988d9a64e0e9ad9e851f6cb8c1be8ae50
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/text/qlocale')
-rw-r--r-- | tests/auto/corelib/text/qlocale/tst_qlocale.cpp | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index c7017b8511..78f3ce6359 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -3602,11 +3602,51 @@ void tst_QLocale::uiLanguages() // Compare mySystemLocale(), which tests the same for a custom system locale. QFETCH(const QLocale, locale); QFETCH(const QStringList, all); - auto reporter = qScopeGuard([&locale]() { - qDebug("\n\t%s", qPrintable(locale.uiLanguages().join(u"\n\t"))); - }); - QCOMPARE(locale.uiLanguages(), all); - reporter.dismiss(); + const auto expected = [all](QChar sep) { + QStringList adjusted; + for (QString name : all) + adjusted << name.replace(u'-', sep); + return adjusted; + }; + + { + // By default tags are joined with a dash: + const QStringList actual = locale.uiLanguages(); + auto reporter = qScopeGuard([&actual]() { + qDebug("\n\t%ls", qUtf16Printable(actual.join("\n\t"_L1))); + }); + QCOMPARE(actual, all); + reporter.dismiss(); + } + { + // We also support joining with an underscore: + const QStringList actual = locale.uiLanguages(QLocale::TagSeparator::Underscore); + auto reporter = qScopeGuard([&actual]() { + qDebug("\n\t%ls", qUtf16Printable(actual.join("\n\t"_L1))); + }); + QCOMPARE(actual, expected(u'_')); + reporter.dismiss(); + } + { + // Or, in fact, any ASCII character: + const QStringList actual = locale.uiLanguages(QLocale::TagSeparator{'|'}); + auto reporter = qScopeGuard([&actual]() { + qDebug("\n\t%ls", qUtf16Printable(actual.join("\n\t"_L1))); + }); + QCOMPARE(actual, expected(u'|')); + reporter.dismiss(); + } + { + // Non-ASCII separator (here, y-umlaut) is unsupported. + QTest::ignoreMessage(QtWarningMsg, "QLocale::uiLanguages(): " + "Using non-ASCII separator '\u00ff' (ff) is unsupported"); + const QStringList actual = locale.uiLanguages(QLocale::TagSeparator{'\xff'}); + auto reporter = qScopeGuard([&actual]() { + qDebug("\n\t%ls", qUtf16Printable(actual.join("\n\t"_L1))); + }); + QCOMPARE(actual, QStringList{}); + reporter.dismiss(); + } } void tst_QLocale::weekendDays() |