Remove deprecated functions
This commit is contained in:
@@ -6,16 +6,12 @@
|
||||
// For the license information refer to format.h.
|
||||
|
||||
#include "fmt/printf.h"
|
||||
// include <format> if possible for https://github.com/fmtlib/fmt/pull/4042
|
||||
#if FMT_HAS_INCLUDE(<format>) && FMT_CPLUSPLUS > 201703L
|
||||
# include <format>
|
||||
#endif
|
||||
|
||||
#include <cctype>
|
||||
#include <climits>
|
||||
#include <cstring>
|
||||
|
||||
#include "fmt/xchar.h"
|
||||
#include "fmt/xchar.h" // DEPRECATED!
|
||||
#include "gtest-extra.h"
|
||||
#include "util.h"
|
||||
|
||||
@@ -26,27 +22,21 @@ using fmt::detail::max_value;
|
||||
const unsigned big_num = INT_MAX + 1u;
|
||||
|
||||
// Makes format string argument positional.
|
||||
static std::string make_positional(fmt::string_view format) {
|
||||
static auto make_positional(fmt::string_view format) -> std::string {
|
||||
std::string s(format.data(), format.size());
|
||||
s.replace(s.find('%'), 1, "%1$");
|
||||
return s;
|
||||
}
|
||||
|
||||
static std::wstring make_positional(fmt::basic_string_view<wchar_t> format) {
|
||||
std::wstring s(format.data(), format.size());
|
||||
s.replace(s.find(L'%'), 1, L"%1$");
|
||||
return s;
|
||||
}
|
||||
|
||||
// A wrapper around fmt::sprintf to workaround bogus warnings about invalid
|
||||
// format strings in MSVC.
|
||||
template <typename... Args>
|
||||
std::string test_sprintf(fmt::string_view format, const Args&... args) {
|
||||
auto test_sprintf(fmt::string_view format, const Args&... args) -> std::string {
|
||||
return fmt::sprintf(format, args...);
|
||||
}
|
||||
template <typename... Args>
|
||||
std::wstring test_sprintf(fmt::basic_string_view<wchar_t> format,
|
||||
const Args&... args) {
|
||||
auto test_sprintf(fmt::basic_string_view<wchar_t> format, const Args&... args)
|
||||
-> std::wstring {
|
||||
return fmt::sprintf(format, args...);
|
||||
}
|
||||
|
||||
@@ -55,10 +45,7 @@ std::wstring test_sprintf(fmt::basic_string_view<wchar_t> format,
|
||||
<< "format: " << format; \
|
||||
EXPECT_EQ(expected_output, fmt::sprintf(make_positional(format), arg))
|
||||
|
||||
TEST(printf_test, no_args) {
|
||||
EXPECT_EQ("test", test_sprintf("test"));
|
||||
EXPECT_EQ(L"test", fmt::sprintf(L"test"));
|
||||
}
|
||||
TEST(printf_test, no_args) { EXPECT_EQ("test", test_sprintf("test")); }
|
||||
|
||||
TEST(printf_test, escape) {
|
||||
EXPECT_EQ("%", test_sprintf("%%"));
|
||||
@@ -66,11 +53,6 @@ TEST(printf_test, escape) {
|
||||
EXPECT_EQ("% after", test_sprintf("%% after"));
|
||||
EXPECT_EQ("before % after", test_sprintf("before %% after"));
|
||||
EXPECT_EQ("%s", test_sprintf("%%s"));
|
||||
EXPECT_EQ(L"%", fmt::sprintf(L"%%"));
|
||||
EXPECT_EQ(L"before %", fmt::sprintf(L"before %%"));
|
||||
EXPECT_EQ(L"% after", fmt::sprintf(L"%% after"));
|
||||
EXPECT_EQ(L"before % after", fmt::sprintf(L"before %% after"));
|
||||
EXPECT_EQ(L"%s", fmt::sprintf(L"%%s"));
|
||||
}
|
||||
|
||||
TEST(printf_test, positional_args) {
|
||||
@@ -467,9 +449,6 @@ TEST(printf_test, char) {
|
||||
EXPECT_PRINTF("x", "%c", 'x');
|
||||
int max = max_value<int>();
|
||||
EXPECT_PRINTF(fmt::format("{}", static_cast<char>(max)), "%c", max);
|
||||
// EXPECT_PRINTF("x", "%lc", L'x');
|
||||
EXPECT_PRINTF(L"x", L"%c", L'x');
|
||||
EXPECT_PRINTF(fmt::format(L"{}", static_cast<wchar_t>(max)), L"%c", max);
|
||||
}
|
||||
|
||||
TEST(printf_test, string) {
|
||||
@@ -477,10 +456,6 @@ TEST(printf_test, string) {
|
||||
const char* null_str = nullptr;
|
||||
EXPECT_PRINTF("(null)", "%s", null_str);
|
||||
EXPECT_PRINTF(" (null)", "%10s", null_str);
|
||||
EXPECT_PRINTF(L"abc", L"%s", L"abc");
|
||||
const wchar_t* null_wstr = nullptr;
|
||||
EXPECT_PRINTF(L"(null)", L"%s", null_wstr);
|
||||
EXPECT_PRINTF(L" (null)", L"%10s", null_wstr);
|
||||
}
|
||||
|
||||
TEST(printf_test, pointer) {
|
||||
@@ -494,16 +469,6 @@ TEST(printf_test, pointer) {
|
||||
EXPECT_PRINTF(fmt::format("{:p}", s), "%p", s);
|
||||
const char* null_str = nullptr;
|
||||
EXPECT_PRINTF("(nil)", "%p", null_str);
|
||||
|
||||
p = &n;
|
||||
EXPECT_PRINTF(fmt::format(L"{}", p), L"%p", p);
|
||||
p = nullptr;
|
||||
EXPECT_PRINTF(L"(nil)", L"%p", p);
|
||||
EXPECT_PRINTF(L" (nil)", L"%10p", p);
|
||||
const wchar_t* w = L"test";
|
||||
EXPECT_PRINTF(fmt::format(L"{:p}", w), L"%p", w);
|
||||
const wchar_t* null_wstr = nullptr;
|
||||
EXPECT_PRINTF(L"(nil)", L"%p", null_wstr);
|
||||
}
|
||||
|
||||
enum test_enum { answer = 42 };
|
||||
@@ -531,10 +496,6 @@ TEST(printf_test, printf_error) {
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(printf_test, wide_string) {
|
||||
EXPECT_EQ(L"abc", fmt::sprintf(L"%s", L"abc"));
|
||||
}
|
||||
|
||||
TEST(printf_test, vprintf) {
|
||||
int n = 42;
|
||||
auto store = fmt::make_format_args<fmt::printf_context>(n);
|
||||
|
||||
Reference in New Issue
Block a user