enforce-checks-test.cc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Formatting library for C++ - formatting library 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 <iterator>
  8. #include <vector>
  9. #include "fmt/chrono.h"
  10. #include "fmt/color.h"
  11. #include "fmt/format.h"
  12. #include "fmt/ostream.h"
  13. #include "fmt/ranges.h"
  14. #include "fmt/xchar.h"
  15. // Exercise the API to verify that everything we expect to can compile.
  16. void test_format_api() {
  17. (void)fmt::format(FMT_STRING("{}"), 42);
  18. (void)fmt::format(FMT_STRING(L"{}"), 42);
  19. (void)fmt::format(FMT_STRING("noop"));
  20. (void)fmt::to_string(42);
  21. (void)fmt::to_wstring(42);
  22. std::vector<char> out;
  23. fmt::format_to(std::back_inserter(out), FMT_STRING("{}"), 42);
  24. char buffer[4];
  25. fmt::format_to_n(buffer, 3, FMT_STRING("{}"), 12345);
  26. wchar_t wbuffer[4];
  27. fmt::format_to_n(wbuffer, 3, FMT_STRING(L"{}"), 12345);
  28. }
  29. void test_chrono() {
  30. (void)fmt::format(FMT_STRING("{}"), std::chrono::seconds(42));
  31. (void)fmt::format(FMT_STRING(L"{}"), std::chrono::seconds(42));
  32. }
  33. void test_text_style() {
  34. fmt::print(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)");
  35. (void)fmt::format(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"),
  36. "rgb(255,20,30)");
  37. fmt::text_style ts = fg(fmt::rgb(255, 20, 30));
  38. std::string out;
  39. fmt::format_to(std::back_inserter(out), ts,
  40. FMT_STRING("rgb(255,20,30){}{}{}"), 1, 2, 3);
  41. }
  42. void test_range() {
  43. std::vector<char> hello = {'h', 'e', 'l', 'l', 'o'};
  44. (void)fmt::format(FMT_STRING("{}"), hello);
  45. }
  46. int main() {
  47. test_format_api();
  48. test_chrono();
  49. test_text_style();
  50. test_range();
  51. }