Skip to content

Commit c6847ce

Browse files
committed
Add smoke test for std::regex compatibility
1 parent 5f24abe commit c6847ce

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

test/Jamfile.v2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ run test_ios_info.cpp ;
4343
run test_ios_prop.cpp ;
4444
run test_codecvt.cpp ;
4545
run test_codepage_converter.cpp ;
46+
run test_std_regex.cpp ;
4647
run test_stream_io.cpp ;
4748
run test_message.cpp : $(BOOST_ROOT)/libs/locale/test ;
4849
run test_generator.cpp ;

test/test_std_regex.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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

Comments
 (0)