Something went wrong. Try again.
[Mirror] Libreopolis is a cross-platform city simulation game fully compatible with SimCity 2000. gitlab.com/conasg/libreopolis
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171// City Wire commentary catalogue coverage, copy uniqueness, and bilingual parity.#include "sc2k/ui/commentary_catalogue.hpp"
#include <array>#include <cstdio>#include <set>#include <string>#include <string_view>
#include "sc2k/i18n.hpp"#include "test_harness.hpp"
using namespace sc2k;
namespace {
constexpr std::array<std::string_view, ui::kCommentTopicCount> kTopicNames{ "general", "construction", "civic services", "ordinances", "finance", "economy", "population", "employment", "education", "health", "environment", "traffic", "utilities", "weather", "disaster", "sport", "technology", "neighbors",};
constexpr std::array<std::size_t, ui::kCommentTopicCount> kExpectedFamilies{ 20, 3, 18, 5, 14, 7, 7, 2, 6, 5, 8, 8, 8, 13, 6, 5, 2, 3,};
std::set<std::string> placeholders(std::string_view value) { std::set<std::string> result; for (std::size_t begin = value.find('{'); begin != std::string_view::npos; begin = value.find('{', begin + 1)) { const std::size_t end = value.find('}', begin + 1); if (end == std::string_view::npos) break; result.emplace(value.substr(begin + 1, end - begin - 1)); begin = end; } return result;}
std::size_t utf8_length(std::string_view value) { std::size_t result = 0; for (const unsigned char byte : value) if ((byte & 0xC0) != 0x80) ++result; return result;}
std::set<std::string> comment_keys(const i18n::Catalog& catalogue) { std::set<std::string> result; for (const auto& [key, value] : catalogue.kv) { (void)value; if (key.starts_with("citywire.comment.")) result.insert(key); } return result;}
} // namespace
int main() { const auto rules = ui::commentary_rules(); CHECK(rules.size() == 140); std::array<std::size_t, ui::kCommentTopicCount> familyCounts{}; std::array<std::size_t, ui::kCommentTopicCount> variantCounts{}; std::set<std::string> referencedKeys; std::size_t totalVariants = 0;
for (std::size_t index = 0; index < rules.size(); ++index) { const ui::CommentRuleDefinition& rule = rules[index]; const std::size_t topic = static_cast<std::size_t>(rule.topic); CHECK(topic < ui::kCommentTopicCount); if (topic >= ui::kCommentTopicCount) continue; CHECK(rule.variantCount >= 2 && rule.variantCount <= 4); CHECK(rule.variantCount <= ui::commentary_catalogue_detail::kCommentaryCopy[index].size()); ++familyCounts[topic]; variantCounts[topic] += rule.variantCount; totalVariants += rule.variantCount;
for (std::uint8_t variant = 0; variant < rule.variantCount; ++variant) { const auto* definition = ui::commentary_catalogue_detail::commentary_definition( {rule.id, rule.topic, variant, rule.priority}); CHECK(definition != nullptr); if (!definition) continue; CHECK(std::string_view(definition->titleKey).starts_with("citywire.comment.")); CHECK(std::string_view(definition->titleKey).ends_with(".title")); CHECK(std::string_view(definition->descriptionKey).starts_with("citywire.comment.")); CHECK(std::string_view(definition->descriptionKey).ends_with(".description")); CHECK(referencedKeys.emplace(definition->titleKey).second); CHECK(referencedKeys.emplace(definition->descriptionKey).second); } }
CHECK(familyCounts == kExpectedFamilies); CHECK(totalVariants == 280); CHECK(referencedKeys.size() == totalVariants * 2);
i18n::Catalog english; i18n::Catalog ukrainian; CHECK(i18n::detail::parse_file("assets/lang/en.txt", english)); CHECK(i18n::detail::parse_file("assets/lang/uk.txt", ukrainian)); CHECK(comment_keys(english) == referencedKeys); CHECK(comment_keys(ukrainian) == referencedKeys);
for (const i18n::Catalog* catalogue : {&english, &ukrainian}) { std::set<std::string> titles; std::set<std::string> descriptions; for (const std::string& key : referencedKeys) { const std::string* value = catalogue->find(key); CHECK(value != nullptr && !value->empty()); if (!value) continue; const bool title = key.ends_with(".title"); CHECK(utf8_length(*value) <= (title ? 80 : 220)); CHECK((title ? titles : descriptions).insert(*value).second); if (catalogue == &english && title) { const bool hasLowercase = value->find_first_of( "abcdefghijklmnopqrstuvwxyz") != std::string::npos; CHECK(hasLowercase); } } }
for (const std::string& key : referencedKeys) { const std::string* englishValue = english.find(key); const std::string* ukrainianValue = ukrainian.find(key); CHECK(englishValue != nullptr && ukrainianValue != nullptr); if (englishValue && ukrainianValue) CHECK(placeholders(*englishValue) == placeholders(*ukrainianValue)); }
std::printf("commentary catalogue: %zu families, %zu variants\n", rules.size(), totalVariants); for (std::size_t topic = 0; topic < ui::kCommentTopicCount; ++topic) std::printf(" %-16.*s %2zu families %2zu variants\n", static_cast<int>(kTopicNames[topic].size()), kTopicNames[topic].data(), familyCounts[topic], variantCounts[topic]); std::printf("commentary catalogue: %s (%d failures)\n", failures ? "FAIL" : "PASS", failures); return failures ? 1 : 0;}