test_fmt_helper.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "includes.h"
  2. using spdlog::memory_buf_t;
  3. using spdlog::details::to_string_view;
  4. void test_pad2(int n, const char *expected) {
  5. memory_buf_t buf;
  6. spdlog::details::fmt_helper::pad2(n, buf);
  7. REQUIRE(to_string_view(buf) == expected);
  8. }
  9. void test_pad3(uint32_t n, const char *expected) {
  10. memory_buf_t buf;
  11. spdlog::details::fmt_helper::pad3(n, buf);
  12. REQUIRE(to_string_view(buf) == expected);
  13. }
  14. void test_pad6(std::size_t n, const char *expected) {
  15. memory_buf_t buf;
  16. spdlog::details::fmt_helper::pad6(n, buf);
  17. REQUIRE(to_string_view(buf) == expected);
  18. }
  19. void test_pad9(std::size_t n, const char *expected) {
  20. memory_buf_t buf;
  21. spdlog::details::fmt_helper::pad9(n, buf);
  22. REQUIRE(to_string_view(buf) == expected);
  23. }
  24. TEST_CASE("pad2", "[fmt_helper]") {
  25. test_pad2(0, "00");
  26. test_pad2(3, "03");
  27. test_pad2(10, "10");
  28. test_pad2(23, "23");
  29. test_pad2(99, "99");
  30. test_pad2(100, "100");
  31. test_pad2(123, "123");
  32. test_pad2(1234, "1234");
  33. test_pad2(-5, "-5");
  34. }
  35. TEST_CASE("pad3", "[fmt_helper]") {
  36. test_pad3(0, "000");
  37. test_pad3(3, "003");
  38. test_pad3(10, "010");
  39. test_pad3(23, "023");
  40. test_pad3(99, "099");
  41. test_pad3(100, "100");
  42. test_pad3(123, "123");
  43. test_pad3(999, "999");
  44. test_pad3(1000, "1000");
  45. test_pad3(1234, "1234");
  46. }
  47. TEST_CASE("pad6", "[fmt_helper]") {
  48. test_pad6(0, "000000");
  49. test_pad6(3, "000003");
  50. test_pad6(23, "000023");
  51. test_pad6(123, "000123");
  52. test_pad6(1234, "001234");
  53. test_pad6(12345, "012345");
  54. test_pad6(123456, "123456");
  55. }
  56. TEST_CASE("pad9", "[fmt_helper]") {
  57. test_pad9(0, "000000000");
  58. test_pad9(3, "000000003");
  59. test_pad9(23, "000000023");
  60. test_pad9(123, "000000123");
  61. test_pad9(1234, "000001234");
  62. test_pad9(12345, "000012345");
  63. test_pad9(123456, "000123456");
  64. test_pad9(1234567, "001234567");
  65. test_pad9(12345678, "012345678");
  66. test_pad9(123456789, "123456789");
  67. test_pad9(1234567891, "1234567891");
  68. }