Add better unit tests and imbue C locale in floating point to_string
ToStringTest.cpp is a better place than JSONProtoTest.cpp for to_string
tests. Move global locale-related unit tests there.
Also imbue the C locale in the floating point to_string functions to avoid
decimal number strings formatted with comma instead of decimal point.
In Dockerfiles, install de_DE locale because it uses decimal comma.
diff --git a/lib/cpp/test/ToStringTest.cpp b/lib/cpp/test/ToStringTest.cpp
index 5a05ed7..722e590 100644
--- a/lib/cpp/test/ToStringTest.cpp
+++ b/lib/cpp/test/ToStringTest.cpp
@@ -19,6 +19,7 @@
#include <vector>
#include <map>
+#include <locale>
#include <boost/test/unit_test.hpp>
@@ -40,6 +41,26 @@
BOOST_CHECK_EQUAL(to_string("abc"), "abc");
}
+BOOST_AUTO_TEST_CASE(locale_en_US_int_to_string) {
+#if _WIN32
+ std::locale::global(std::locale("en-US.UTF-8"));
+#else
+ std::locale::global(std::locale("en_US.UTF-8"));
+#endif
+ BOOST_CHECK_EQUAL(to_string(1000000), "1000000");
+}
+
+BOOST_AUTO_TEST_CASE(locale_de_DE_floating_point_to_string) {
+#if _WIN32
+ std::locale::global(std::locale("de-DE.UTF-8"));
+#else
+ std::locale::global(std::locale("de_DE.UTF-8"));
+#endif
+ BOOST_CHECK_EQUAL(to_string(1.5), "1.5");
+ BOOST_CHECK_EQUAL(to_string(1.5f), "1.5");
+ BOOST_CHECK_EQUAL(to_string(1.5L), "1.5");
+}
+
BOOST_AUTO_TEST_CASE(empty_vector_to_string) {
std::vector<int> l;
BOOST_CHECK_EQUAL(to_string(l), "[]");