66// For the license information refer to format.h.
77
88#include " fmt/printf.h"
9- // include <format> if possible for https://github.com/fmtlib/fmt/pull/4042
10- #if FMT_HAS_INCLUDE(<format>) && FMT_CPLUSPLUS > 201703L
11- # include < format>
12- #endif
139
1410#include < cctype>
1511#include < climits>
1612#include < cstring>
1713
18- #include " fmt/xchar.h"
14+ #include " fmt/xchar.h" // DEPRECATED!
1915#include " gtest-extra.h"
2016#include " util.h"
2117
@@ -26,27 +22,21 @@ using fmt::detail::max_value;
2622const unsigned big_num = INT_MAX + 1u ;
2723
2824// Makes format string argument positional.
29- static std::string make_positional (fmt::string_view format) {
25+ static auto make_positional (fmt::string_view format) -> std::string {
3026 std::string s (format.data (), format.size ());
3127 s.replace (s.find (' %' ), 1 , " %1$" );
3228 return s;
3329}
3430
35- static std::wstring make_positional (fmt::basic_string_view<wchar_t > format) {
36- std::wstring s (format.data (), format.size ());
37- s.replace (s.find (L' %' ), 1 , L" %1$" );
38- return s;
39- }
40-
4131// A wrapper around fmt::sprintf to workaround bogus warnings about invalid
4232// format strings in MSVC.
4333template <typename ... Args>
44- std::string test_sprintf (fmt::string_view format, const Args&... args) {
34+ auto test_sprintf (fmt::string_view format, const Args&... args) -> std::string {
4535 return fmt::sprintf (format, args...);
4636}
4737template <typename ... Args>
48- std::wstring test_sprintf (fmt::basic_string_view<wchar_t > format,
49- const Args&... args) {
38+ auto test_sprintf (fmt::basic_string_view<wchar_t > format, const Args&... args)
39+ -> std::wstring {
5040 return fmt::sprintf (format, args...);
5141}
5242
@@ -55,22 +45,14 @@ std::wstring test_sprintf(fmt::basic_string_view<wchar_t> format,
5545 << "format: " << format; \
5646 EXPECT_EQ (expected_output, fmt::sprintf(make_positional(format), arg))
5747
58- TEST(printf_test, no_args) {
59- EXPECT_EQ (" test" , test_sprintf (" test" ));
60- EXPECT_EQ (L" test" , fmt::sprintf (L" test" ));
61- }
48+ TEST(printf_test, no_args) { EXPECT_EQ (" test" , test_sprintf (" test" )); }
6249
6350TEST (printf_test, escape) {
6451 EXPECT_EQ (" %" , test_sprintf (" %%" ));
6552 EXPECT_EQ (" before %" , test_sprintf (" before %%" ));
6653 EXPECT_EQ (" % after" , test_sprintf (" %% after" ));
6754 EXPECT_EQ (" before % after" , test_sprintf (" before %% after" ));
6855 EXPECT_EQ (" %s" , test_sprintf (" %%s" ));
69- EXPECT_EQ (L" %" , fmt::sprintf (L" %%" ));
70- EXPECT_EQ (L" before %" , fmt::sprintf (L" before %%" ));
71- EXPECT_EQ (L" % after" , fmt::sprintf (L" %% after" ));
72- EXPECT_EQ (L" before % after" , fmt::sprintf (L" before %% after" ));
73- EXPECT_EQ (L" %s" , fmt::sprintf (L" %%s" ));
7456}
7557
7658TEST (printf_test, positional_args) {
@@ -467,20 +449,13 @@ TEST(printf_test, char) {
467449 EXPECT_PRINTF (" x" , " %c" , ' x' );
468450 int max = max_value<int >();
469451 EXPECT_PRINTF (fmt::format (" {}" , static_cast <char >(max)), " %c" , max);
470- // EXPECT_PRINTF("x", "%lc", L'x');
471- EXPECT_PRINTF (L" x" , L" %c" , L' x' );
472- EXPECT_PRINTF (fmt::format (L" {}" , static_cast <wchar_t >(max)), L" %c" , max);
473452}
474453
475454TEST (printf_test, string) {
476455 EXPECT_PRINTF (" abc" , " %s" , " abc" );
477456 const char * null_str = nullptr ;
478457 EXPECT_PRINTF (" (null)" , " %s" , null_str);
479458 EXPECT_PRINTF (" (null)" , " %10s" , null_str);
480- EXPECT_PRINTF (L" abc" , L" %s" , L" abc" );
481- const wchar_t * null_wstr = nullptr ;
482- EXPECT_PRINTF (L" (null)" , L" %s" , null_wstr);
483- EXPECT_PRINTF (L" (null)" , L" %10s" , null_wstr);
484459}
485460
486461TEST (printf_test, pointer) {
@@ -494,16 +469,6 @@ TEST(printf_test, pointer) {
494469 EXPECT_PRINTF (fmt::format (" {:p}" , s), " %p" , s);
495470 const char * null_str = nullptr ;
496471 EXPECT_PRINTF (" (nil)" , " %p" , null_str);
497-
498- p = &n;
499- EXPECT_PRINTF (fmt::format (L" {}" , p), L" %p" , p);
500- p = nullptr ;
501- EXPECT_PRINTF (L" (nil)" , L" %p" , p);
502- EXPECT_PRINTF (L" (nil)" , L" %10p" , p);
503- const wchar_t * w = L" test" ;
504- EXPECT_PRINTF (fmt::format (L" {:p}" , w), L" %p" , w);
505- const wchar_t * null_wstr = nullptr ;
506- EXPECT_PRINTF (L" (nil)" , L" %p" , null_wstr);
507472}
508473
509474enum test_enum { answer = 42 };
@@ -531,10 +496,6 @@ TEST(printf_test, printf_error) {
531496}
532497#endif
533498
534- TEST (printf_test, wide_string) {
535- EXPECT_EQ (L" abc" , fmt::sprintf (L" %s" , L" abc" ));
536- }
537-
538499TEST (printf_test, vprintf) {
539500 int n = 42 ;
540501 auto store = fmt::make_format_args<fmt::printf_context>(n);
0 commit comments