|
| 1 | +// |
| 2 | +// Copyright (c) 2025 Alexander Grund |
| 3 | +// |
| 4 | +// Distributed under the Boost Software License, Version 1.0. |
| 5 | +// https://www.boost.org/LICENSE_1_0.txt |
| 6 | + |
| 7 | +#include <boost/locale/generator.hpp> |
| 8 | +#include <boost/locale/localization_backend.hpp> |
| 9 | +#include "boostLocale/test/tools.hpp" |
| 10 | +#include <boost/core/detail/string_view.hpp> |
| 11 | +#include <regex> |
| 12 | + |
| 13 | +/// Smoke test that std::regex works with generated locales |
| 14 | +template<typename CharType> |
| 15 | +void test_by_char(const std::locale& l) |
| 16 | +{ |
| 17 | + using string_type = std::basic_string<CharType>; |
| 18 | + std::basic_regex<CharType> pattern; |
| 19 | + pattern.imbue(l); |
| 20 | + pattern = ascii_to<CharType>("[[:alnum:]]+"); |
| 21 | + const string_type text = ascii_to<CharType>("ab12cd"); |
| 22 | + std::match_results<typename string_type::const_iterator> pieces; |
| 23 | + if TEST(std::regex_match(text, pieces, pattern)) { |
| 24 | + TEST_EQ(pieces.size(), 1u); |
| 25 | + TEST_EQ(pieces[0].str(), text); |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +void test_main(int /*argc*/, char** /*argv*/) |
| 30 | +{ |
| 31 | + for(const std::string& backend_name : boost::locale::localization_backend_manager::global().get_all_backends()) { |
| 32 | + TEST_CONTEXT("Backend: " << backend_name); |
| 33 | + boost::locale::localization_backend_manager tmp_backend = boost::locale::localization_backend_manager::global(); |
| 34 | + tmp_backend.select(backend_name); |
| 35 | + boost::locale::localization_backend_manager::global(tmp_backend); |
| 36 | + |
| 37 | + boost::locale::generator gen; |
| 38 | + const std::locale loc = gen("en_US.UTF-8"); |
| 39 | + gen.categories(gen.categories() ^ boost::locale::category_t::collation); |
| 40 | + const std::locale loc_no_collation = gen("en_US.UTF-8"); |
| 41 | + gen.categories(boost::locale::category_t::collation); |
| 42 | + const std::locale loc_collation = gen("en_US.UTF-8"); |
| 43 | + { |
| 44 | + TEST_CONTEXT("char"); |
| 45 | + test_by_char<char>(loc); |
| 46 | + { |
| 47 | + TEST_CONTEXT("without collation"); |
| 48 | + test_by_char<char>(loc_no_collation); |
| 49 | + } |
| 50 | + { |
| 51 | + TEST_CONTEXT("just collation"); |
| 52 | + test_by_char<char>(loc_collation); |
| 53 | + } |
| 54 | + } |
| 55 | + { |
| 56 | + TEST_CONTEXT("wchar_t"); |
| 57 | + test_by_char<wchar_t>(loc); |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments