1: -module(translate_SUITE).
    2: -compile([export_all, nowarn_export_all]).
    3: -include_lib("eunit/include/eunit.hrl").
    4: 
    5: all() ->
    6:     [
    7:      test_english_translation,
    8:      test_polish_translation,
    9:      test_portuguese_translation
   10:     ].
   11: 
   12: 
   13: end_per_testcase(_, C) ->
   14:     mongoose_config:unset_opt(language),
   15:     C.
   16: 
   17: test_english_translation(_Config) ->
   18:     %% given
   19:     given_default_language(<<"en">>),
   20:     given_loaded_translations(),
   21: 
   22:     %% then
   23:     ?assertEqual(<<"cat">>, translate:translate(<<"en">>, <<"cat">>)),
   24:     ?assertEqual(<<"dog">>, translate:translate(<<"en-us">>, <<"dog">>)),
   25:     ?assertEqual(<<"rabbit">>, translate:translate(<<"en-br">>, <<"rabbit">>)),
   26:     ?assertEqual(<<"kangaroo">>, translate:translate(<<"en-au">>, <<"kangaroo">>)),
   27:     ?assertEqual(<<"wombat">>, translate:translate(<<"klingon">>, <<"wombat">>)),
   28: 
   29:     %% tear down mocks
   30:     meck:unload(),
   31:     ok.
   32: 
   33: test_polish_translation(_Config) ->
   34:     %% given
   35:     given_default_language(<<"pl">>),
   36:     given_loaded_translations(),
   37: 
   38:     ?assertEqual(<<"Dodaj nowe">>, translate:translate(<<"pl">>, <<"Add New">>)),
   39:     %% check if the languages in the form of en-us are handled correctly in case
   40:     %% of other languages
   41:     ?assertEqual(<<"Dodaj nowe">>, translate:translate(<<"pl-gr">>, <<"Add New">>)),
   42:     %% not existing key is not translated
   43:     ?assertEqual(<<"undef_test">>, translate:translate(<<"pl">>, <<"undef_test">>)),
   44:     %% in case of non-existing languege it will chouuse polish tranlation
   45:     ?assertEqual(<<"Dodaj nowe">>, translate:translate(<<"klingon">>, <<"Add New">>)),
   46: 
   47:     ok.
   48: 
   49: test_portuguese_translation(_Config)->
   50:     %% given
   51:     given_default_language(<<"pt">>),
   52:     given_loaded_translations(),
   53: 
   54:     ?assertEqual(<<"Adicionar usuário"/utf8>>, translate:translate(<<"pt-br">>, <<"Add User">>)),
   55:     %% check brasilian
   56:     ?assertEqual(<<"Adicionar utilizador"/utf8>>, translate:translate(<<"pt">>, <<"Add User">>)),
   57: 
   58:     ok.
   59: 
   60: given_loaded_translations() ->
   61:     translate:start().
   62: 
   63: given_default_language(Language) ->
   64:     mongoose_config:set_opt(language, Language).