Skip to content

Commit 46e08a9

Browse files
committed
Add test for GH #5780
1 parent 77f93aa commit 46e08a9

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

tests/std/test.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ tests\GH_005472_do_not_overlap
271271
tests\GH_005546_containers_size_type_cast
272272
tests\GH_005553_regex_character_translation
273273
tests\GH_005768_pow_accuracy
274+
tests\GH_005780_non_ascii_locales
274275
tests\LWG2381_num_get_floating_point
275276
tests\LWG2510_tag_classes
276277
tests\LWG2597_complex_branch_cut
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
RUNALL_INCLUDE ..\usual_matrix.lst
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <algorithm>
5+
#include <cassert>
6+
#include <clocale>
7+
#include <iomanip>
8+
#include <iostream>
9+
#include <string>
10+
11+
std::string set_locale(const std::string& locale_name) {
12+
const char* ret = std::setlocale(LC_ALL, locale_name.c_str());
13+
assert(ret != nullptr);
14+
return ret;
15+
}
16+
17+
std::string query_locale() {
18+
const char* ret = std::setlocale(LC_ALL, nullptr);
19+
assert(ret != nullptr);
20+
return ret;
21+
}
22+
23+
void assert_string_non_ascii(const std::string& string) {
24+
const auto char_not_ascii = [](const char c) { return (c & 0x80) != 0; };
25+
assert(std::any_of(string.begin(), string.end(), char_not_ascii));
26+
}
27+
28+
void test_gh_5780() {
29+
// https://learn.microsoft.com/en-us/cpp/c-runtime-library/language-strings#supported-language-strings
30+
std::string locale_name = set_locale("norwegian-bokmal.437");
31+
assert_string_non_ascii(locale_name);
32+
33+
std::cerr.imbue(std::locale::classic());
34+
std::cerr << std::setprecision(2) << 0.1 << std::endl;
35+
36+
assert(query_locale() == locale_name);
37+
}
38+
39+
int main() {
40+
test_gh_5780();
41+
}

0 commit comments

Comments
 (0)