File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change 1
1
#include < iostream>
2
+ #include < sstream>
2
3
#include < locale>
3
4
#include < cassert>
4
5
#include < libjsonnet++.h>
5
6
6
7
// Regression test for the follwing issue: https://github.com/google/jsonnet/issues/722
7
8
9
+ // Define a custom numpunct facet, so that we don't rely on any particular locale
10
+ // being available on the system where the test is built and run.
11
+ class Punctuator : public std ::numpunct<char > {
12
+ protected:
13
+ virtual char do_decimal_point () const override { return ' !' ; }
14
+ virtual std::string do_grouping () const override { return " \1\2 " ; }
15
+ virtual char do_thousands_sep () const override { return ' \' ' ; }
16
+ };
17
+
8
18
int main () {
9
- std::string templatedJSONString { " 2000" };
10
- std::locale glocale (" en_US.UTF-8" );
19
+ std::string templatedJSONString { " 20000.5" };
20
+ Punctuator punctuator;
21
+ std::locale glocale (std::locale::classic (), &punctuator);
11
22
std::locale::global (glocale);
12
23
24
+ // Self-test to make sure the custom global locale is actually being applied.
25
+ std::ostringstream ss;
26
+ ss << 20000.5 ;
27
+ assert (ss.str () == " 20'00'0!5" );
28
+
13
29
jsonnet::Jsonnet jsonnet {};
14
30
jsonnet.init ();
15
31
@@ -18,7 +34,7 @@ int main() {
18
34
std::cerr << " Error parsing Jsonnet: " +jsonnet.lastError ();
19
35
exit (1 );
20
36
}
21
- std::string expected = " 2000 \n " ;
37
+ std::string expected = " 20000.5 \n " ;
22
38
assert (expected == expanded);
23
39
return 0 ;
24
40
}
You can’t perform that action at this time.
0 commit comments