From 2a640218cdcc129d51256dd8afbc56ac85436595 Mon Sep 17 00:00:00 2001 From: Alexander Borsuk Date: Sun, 25 Jul 2021 08:58:53 +0200 Subject: [PATCH] Fixed categories tests (they need more refactorings) Signed-off-by: Alexander Borsuk --- indexer/categories_holder.cpp | 10 ++-- indexer/categories_holder.hpp | 68 ++++++++++++----------- indexer/indexer_tests/categories_test.cpp | 2 +- 3 files changed, 42 insertions(+), 38 deletions(-) diff --git a/indexer/categories_holder.cpp b/indexer/categories_holder.cpp index 6eaca26679..b679a49066 100644 --- a/indexer/categories_holder.cpp +++ b/indexer/categories_holder.cpp @@ -324,10 +324,10 @@ int8_t CategoriesHolder::MapLocaleToInteger(string const & locale) find(kDisabledLanguages.begin(), kDisabledLanguages.end(), "en") == kDisabledLanguages.end(), ()); - for (auto const & entry : kLocaleMapping) + for (auto it = kLocaleMapping.crbegin(); it != kLocaleMapping.crend(); ++it) { - if (locale.find(entry.m_name) == 0) - return entry.m_code; + if (locale.find(it->m_name) == 0) + return it->m_code; } // Special cases for different Chinese variations @@ -339,10 +339,10 @@ int8_t CategoriesHolder::MapLocaleToInteger(string const & locale) for (char const * s : {"hant", "tw", "hk", "mo"}) { if (lower.find(s) != string::npos) - return 12; // Traditional Chinese + return 36; // Traditional Chinese } - return 17; // Simplified Chinese by default for all other cases + return 35; // Simplified Chinese by default for all other cases } return kUnsupportedLocaleCode; diff --git a/indexer/categories_holder.hpp b/indexer/categories_holder.hpp index be0f10c867..623d9a4fca 100644 --- a/indexer/categories_holder.hpp +++ b/indexer/categories_holder.hpp @@ -70,40 +70,44 @@ public: // CategoriesHolder::MapLocaleToInteger() and // CategoriesHolder::MapIntegerToLocale() as their implementations // strongly depend on the contents of the variable. - static std::array constexpr kLocaleMapping = {{ + // TODO: Refactor for more flexibility and to avoid breaking rules in two methods mentioned above. + static std::array constexpr kLocaleMapping = {{ {"en", 1}, - {"ru", 2}, - {"uk", 3}, - {"de", 4}, - {"fr", 5}, - {"it", 6}, - {"es", 7}, - {"ko", 8}, - {"ja", 9}, - {"cs", 10}, - {"nl", 11}, - {"zh-Hant", 12}, - {"pl", 13}, - {"pt", 14}, - {"hu", 15}, - {"th", 16}, - {"zh-Hans", 17}, - {"ar", 18}, - {"da", 19}, - {"tr", 20}, - {"sk", 21}, - {"sv", 22}, - {"vi", 23}, - {"id", 24}, - {"ro", 25}, - {"nb", 26}, - {"fi", 27}, - {"el", 28}, - {"he", 29}, + {"en-AU", 2}, + {"en-GB", 3}, + {"en-US", 4}, + {"ru", 5}, + {"ar", 6}, + {"bg", 7}, + {"cs", 8}, + {"da", 9}, + {"de", 10}, + {"el", 11}, + {"es", 12}, + {"fa", 13}, + {"fi", 14}, + {"fr", 15}, + {"he", 16}, + {"hu", 17}, + {"id", 18}, + {"it", 19}, + {"ja", 20}, + {"ko", 21}, + {"nb", 22}, + {"nl", 23}, + {"pl", 24}, + {"pt", 25}, + {"pt-BR", 26}, + {"ro", 27}, + {"sk", 28}, + {"sv", 29}, {"sw", 30}, - {"fa", 31}, - {"bg", 32}, - {"pt-BR", 33}, + {"th", 31}, + {"tr", 32}, + {"uk", 33}, + {"vi", 34}, + {"zh-Hans", 35}, + {"zh-Hant", 36}, }}; // List of languages that are currently disabled in the application diff --git a/indexer/indexer_tests/categories_test.cpp b/indexer/indexer_tests/categories_test.cpp index 592790d7a7..2e70eda73d 100644 --- a/indexer/indexer_tests/categories_test.cpp +++ b/indexer/indexer_tests/categories_test.cpp @@ -112,7 +112,7 @@ UNIT_TEST(CategoriesHolder_Smoke) auto const & mapping = mappings[i]; TEST_EQUAL(static_cast(i + 1), mapping.m_code, ()); TEST_EQUAL(static_cast(i + 1), - CategoriesHolder::MapLocaleToInteger(mapping.m_name), ()); + CategoriesHolder::MapLocaleToInteger(mapping.m_name), (mapping.m_name)); TEST_EQUAL(CategoriesHolder::MapIntegerToLocale(i + 1), mapping.m_name, ()); } }