Files
mojibake/tests/ext/cpp/locales.cpp
T
2026-07-20 22:04:20 +02:00

30 lines
935 B
C++

/**
* The Mojibake library
*
* This file is distributed under the MIT License. See LICENSE for details.
*/
#include "../../../src/cpp/mojibake.hpp"
#include "../../test.h"
int test_cpp_locales(void *arg) {
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 &&
error.error() == MJB_ERROR_INVALID_ARGUMENT;
}
ATT_ASSERT(locale_error, true, "LocaleError preserves locale error")
mjb::set_locale(MJB_LOCALE_EN);
return 0;
}