Files
mojibake/tests/ext/cpp/locales.cpp
T
Francesco Bigiarini c2c17c8a2a Update Attractor (#83)
* Update Attractor

* Ignore attractor.h on format job
2026-09-01 23:15:47 +02:00

32 lines
1.1 KiB
C++

/**
* The Mojibake library
*
* This file is distributed under the MIT License. See LICENSE for details.
*/
#include "../../../src/cpp/mojibake.hpp"
#include "../../test.h"
ATT_TEST(cpp_locales) {
const auto locale = mjb::parse_locale("sr-Latn-RS");
ATT_ASSERT(std::string(locale.language()), std::string("sr"), "parse_locale language");
ATT_ASSERT(std::string(locale.script()), std::string("Latn"), "parse_locale script");
ATT_ASSERT(std::string(locale.region()), std::string("RS"), "parse_locale region");
bool locale_error = false;
try {
(void)mjb::parse_locale("not_a_locale");
} catch(const mjb::LocaleError &error) {
locale_error = error.status() == MJB_STATUS_INVALID_ARGUMENT;
}
ATT_ASSERT(locale_error, true, "LocaleError preserves status");
mjb::set_locale(MJB_LOCALE_IT);
ATT_ASSERT((unsigned int)mjb::get_locale(), (unsigned int)MJB_LOCALE_IT,
"get_locale returns selected locale");
mjb::reset_locale();
ATT_ASSERT((unsigned int)mjb::get_locale(), (unsigned int)MJB_LOCALE_EN,
"reset_locale restores English");
}