Skip to content

Commit

Permalink
Don't skip translations test (#2246)
Browse files Browse the repository at this point in the history
  • Loading branch information
olanti-p authored Jan 5, 2023
1 parent 7825993 commit 2667a52
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions tests/translations_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,19 @@ TEST_CASE( "translations_macro_char_address_translated", "[.][translations][i18n
CHECK( translated != test_string );
}

struct trans_test_case {
std::string id;
std::string str;
bool must_have_files = false;
};

// requires .mo files for languages listed below
TEST_CASE( "translations_actually_translate", "[translations][i18n]" )
{
const std::vector<std::pair<std::string, std::string>> test_cases = {{
{ "en_US", "Play <N|n>ow!" },
{ "fr_FR", "Jouer <M|m>aintenant!" },
{ "ru_RU", "Сразу в игру!" },
const std::vector<trans_test_case> test_cases = {{
{ "en_US", "Play <N|n>ow!", false },
{ "fr_FR", "Jouer <M|m>aintenant!", true },
{ "ru_RU", "Сразу в игру!", true },
}
};

Expand All @@ -153,10 +159,10 @@ TEST_CASE( "translations_actually_translate", "[translations][i18n]" )
};

for( const auto &test : test_cases ) {
const std::string &lang = test.first;
const std::string &lang = test.id;
CAPTURE( lang );
REQUIRE( has_lang( lang ) );
if( !translations_exists_for_lang( lang ) ) {
if( test.must_have_files && !translations_exists_for_lang( lang ) ) {
WARN( string_format( "Skipped (translation files not found for lang '%s')", lang ) );
return;
}
Expand All @@ -167,17 +173,17 @@ TEST_CASE( "translations_actually_translate", "[translations][i18n]" )
std::string lang_default = get_option<std::string>( USE_LANG );

for( const auto &test : test_cases ) {
CAPTURE( test.first );
CAPTURE( test.id );

get_options().get_option( USE_LANG ).setValue( test.first );
get_options().get_option( USE_LANG ).setValue( test.id );
get_options().save();
CHECK( get_option<std::string>( USE_LANG ) == test.first );
CHECK( get_option<std::string>( USE_LANG ) == test.id );

set_language();

// Should return translated string (or original/same string for English)
const char *translated = pgettext( test_msgctx, test_msgid );
CHECK( test.second == translated );
CHECK( test.str == translated );
}

// Restore language
Expand Down

0 comments on commit 2667a52

Please sign in to comment.