unicode-test.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include <iomanip>
  8. #include <locale>
  9. #include <vector>
  10. #include "fmt/chrono.h"
  11. #include "gmock/gmock.h"
  12. #include "util.h" // get_locale
  13. using testing::Contains;
  14. TEST(unicode_test, is_utf8) { EXPECT_TRUE(fmt::detail::is_utf8()); }
  15. TEST(unicode_test, legacy_locale) {
  16. auto loc = get_locale("ru_RU.CP1251", "Russian_Russia.1251");
  17. if (loc == std::locale::classic()) return;
  18. auto s = std::string();
  19. try {
  20. s = fmt::format(loc, "День недели: {:L}", fmt::weekday(1));
  21. } catch (const fmt::format_error& e) {
  22. // Formatting can fail due to an unsupported encoding.
  23. fmt::print("Format error: {}\n", e.what());
  24. return;
  25. }
  26. #if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 500
  27. auto&& os = std::ostringstream();
  28. os.imbue(loc);
  29. auto tm = std::tm();
  30. tm.tm_wday = 1;
  31. os << std::put_time(&tm, "%a");
  32. auto wd = os.str();
  33. if (wd == "??") {
  34. EXPECT_EQ(s, "День недели: ??");
  35. fmt::print("std::locale gives ?? as a weekday.\n");
  36. return;
  37. }
  38. #endif
  39. EXPECT_THAT((std::vector<std::string>{"День недели: пн", "День недели: Пн"}),
  40. Contains(s));
  41. }