[libcalamares] Tighten tests, add special case

- The tests should be run in C locale, otherwise the plain get()
   function uses the current locale, which will fail (e.g. running
   LANG=nl ./libcalamareslocaletest returns the Dutch strings for
   plain get, which isn't what we expect).
 - sr@latin is still special.
This commit is contained in:
Adriaan de Groot 2019-08-06 00:05:24 +02:00
parent a9292d0c75
commit 764c775f08
2 changed files with 22 additions and 0 deletions

View file

@ -108,6 +108,7 @@ LocaleTests::testTranslatableLanguages()
void
LocaleTests::testTranslatableConfig1()
{
QCOMPARE( QLocale().name(), "C" ); // Otherwise plain get() is dubious
CalamaresUtils::Locale::TranslatedString ts1( "Hello" );
QCOMPARE( ts1.count(), 1 );
@ -126,6 +127,7 @@ LocaleTests::testTranslatableConfig1()
void
LocaleTests::testTranslatableConfig2()
{
QCOMPARE( QLocale().name(), "C" ); // Otherwise plain get() is dubious
QVariantMap map;
for ( const auto& language : someLanguages() )
@ -144,6 +146,20 @@ LocaleTests::testTranslatableConfig2()
QCOMPARE( ts1.get(), "description" ); // it wasn't set
QCOMPARE( ts1.get( QLocale( "nl" ) ), "description (language nl)" );
for ( const auto& language : someLanguages() )
{
// Skip Serbian (latin) because QLocale() constructed with it
// doesn't retain the @latin part.
if ( language == "sr@latin" )
{
continue;
}
// Could be QVERIFY, but then we don't see what language code fails
QCOMPARE( ts1.get( language ) == QString( "description (language %1)" ).arg( language ) ? language : QString(),
language );
}
QCOMPARE( ts1.get( QLocale( QLocale::Language::Serbian, QLocale::Script::LatinScript, QLocale::Country::Serbia ) ),
"description (language sr@latin)" );
CalamaresUtils::Locale::TranslatedString ts2( map, "name" );
// We skipped dutch this time

View file

@ -73,6 +73,12 @@ QString
TranslatedString::get( const QLocale& locale ) const
{
QString localeName = locale.name();
// Special case, sr@latin doesn't have the @latin reflected in the name
if ( locale.language() == QLocale::Language::Serbian && locale.script() == QLocale::Script::LatinScript )
{
localeName = QStringLiteral( "sr@latin" );
}
cDebug() << "Getting locale" << localeName;
if ( m_strings.contains( localeName ) )
{