File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ set(CLI11_TESTS
49
49
StringParseTest
50
50
ComplexTypeTest
51
51
TrueFalseTest
52
+ localeTest
52
53
OptionGroupTest
53
54
EncodingTest )
54
55
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2017-2025, University of Cincinnati, developed by Henry Schreiner
2
+ // under NSF AWARD 1414736 and by the respective contributors.
3
+ // All rights reserved.
4
+ //
5
+ // SPDX-License-Identifier: BSD-3-Clause
6
+
7
+ #include " app_helper.hpp"
8
+
9
+ #include < complex>
10
+ #include < cstdint>
11
+ #include < iomanip>
12
+ #include < iostream>
13
+ #include < locale>
14
+ #include < numeric>
15
+ #include < string>
16
+ #include < utility>
17
+ #include < vector>
18
+
19
+ // Custom facet for thousands separator
20
+ class CustomThousandsSeparator : public std ::numpunct<char > {
21
+ protected:
22
+ char do_thousands_sep () const override { return ' |' ; } // Space separator
23
+ std::string do_grouping () const override { return " \2 " ; } // Group digits in sets of 2
24
+ };
25
+
26
+ // derived from https://github.com/CLIUtils/CLI11/pull/1160
27
+ TEST_CASE_METHOD (TApp, " locale" , " [separators]" ) {
28
+ std::locale customLocale (std::locale::classic (), new CustomThousandsSeparator);
29
+ std::locale::global (customLocale); // Set as the default system-wide locale
30
+
31
+ // Ensure standard streams use the custom locale automatically
32
+ std::cout.imbue (std::locale ());
33
+ std::int64_t foo;
34
+ std::uint64_t bar;
35
+ float qux;
36
+
37
+ app.add_option (" FOO" , foo, " Foo option" )->default_val (1234567 )->force_callback ();
38
+ app.add_option (" BAR" , bar, " Bar option" )->default_val (2345678 )->force_callback ();
39
+ app.add_option (" QUX" , qux, " QUX option" )->default_val (3456.78 )->force_callback ();
40
+
41
+ CHECK_NOTHROW (run ());
42
+ CHECK (foo == 1234567 );
43
+ CHECK (bar == 2345678 );
44
+ CHECK_THAT (qux, Catch::Matchers::WithinAbs (13456.78 , 0.01 ));
45
+ }
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ testnames = [
57
57
[' StringParseTest' , {}],
58
58
[' ComplexTypeTest' , {}],
59
59
[' TrueFalseTest' , {}],
60
+ [' localeTest' , {}],
60
61
[' OptionGroupTest' , {}],
61
62
[' EncodingTest' , {}],
62
63
# multi-only
You can’t perform that action at this time.
0 commit comments