/ externals / fmt / test / unicode-test.cc
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("be_BY.CP1251", "Belarusian_Belarus.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  }