]> git.proxmox.com Git - ceph.git/blob - ceph/src/fmt/test/unicode-test.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / fmt / test / unicode-test.cc
1 // Formatting library for C++ - Unicode tests
2 //
3 // Copyright (c) 2012 - present, Victor Zverovich
4 // All rights reserved.
5 //
6 // For the license information refer to format.h.
7
8 #include <iomanip>
9 #include <locale>
10 #include <vector>
11
12 #include "fmt/chrono.h"
13 #include "gmock/gmock.h"
14 #include "util.h" // get_locale
15
16 using testing::Contains;
17
18 TEST(unicode_test, is_utf8) { EXPECT_TRUE(fmt::detail::is_utf8()); }
19
20 TEST(unicode_test, legacy_locale) {
21 auto loc = get_locale("ru_RU.CP1251", "Russian.1251");
22 if (loc == std::locale::classic()) return;
23
24 auto s = std::string();
25 try {
26 s = fmt::format(loc, "День недели: {:L}", fmt::weekday(1));
27 } catch (const fmt::format_error& e) {
28 // Formatting can fail due to an unsupported encoding.
29 fmt::print("Format error: {}\n", e.what());
30 return;
31 }
32
33 #if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 500
34 auto&& os = std::ostringstream();
35 os.imbue(loc);
36 auto tm = std::tm();
37 tm.tm_wday = 1;
38 os << std::put_time(&tm, "%a");
39 auto wd = os.str();
40 if (wd == "??") {
41 EXPECT_EQ(s, "День недели: ??");
42 fmt::print("std::locale gives ?? as a weekday.\n");
43 return;
44 }
45 #endif
46 EXPECT_THAT((std::vector<std::string>{"День недели: пн", "День недели: Пн"}),
47 Contains(s));
48 }