mirror of
https://github.com/fmtlib/fmt.git
synced 2025-11-02 23:21:45 +01:00
FMT_EXPLICIT -> explicit, FMT_NULL -> nullptr
This commit is contained in:
@@ -60,7 +60,7 @@ TEST(TimeTest, GrowBuffer) {
|
||||
std::string s = "{:";
|
||||
for (int i = 0; i < 30; ++i) s += "%c";
|
||||
s += "}\n";
|
||||
std::time_t t = std::time(FMT_NULL);
|
||||
std::time_t t = std::time(nullptr);
|
||||
fmt::format(s, *std::localtime(&t));
|
||||
}
|
||||
|
||||
@@ -83,13 +83,13 @@ static bool EqualTime(const std::tm& lhs, const std::tm& rhs) {
|
||||
}
|
||||
|
||||
TEST(TimeTest, LocalTime) {
|
||||
std::time_t t = std::time(FMT_NULL);
|
||||
std::time_t t = std::time(nullptr);
|
||||
std::tm tm = *std::localtime(&t);
|
||||
EXPECT_TRUE(EqualTime(tm, fmt::localtime(t)));
|
||||
}
|
||||
|
||||
TEST(TimeTest, GMTime) {
|
||||
std::time_t t = std::time(FMT_NULL);
|
||||
std::time_t t = std::time(nullptr);
|
||||
std::tm tm = *std::gmtime(&t);
|
||||
EXPECT_TRUE(EqualTime(tm, fmt::gmtime(t)));
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ TEST(BufferTest, Nonmoveable) {
|
||||
|
||||
// A test buffer with a dummy grow method.
|
||||
template <typename T> struct test_buffer : buffer<T> {
|
||||
void grow(std::size_t capacity) { this->set(FMT_NULL, capacity); }
|
||||
void grow(std::size_t capacity) { this->set(nullptr, capacity); }
|
||||
};
|
||||
|
||||
template <typename T> struct mock_buffer : buffer<T> {
|
||||
@@ -103,7 +103,7 @@ template <typename T> struct mock_buffer : buffer<T> {
|
||||
TEST(BufferTest, Ctor) {
|
||||
{
|
||||
mock_buffer<int> buffer;
|
||||
EXPECT_EQ(FMT_NULL, &buffer[0]);
|
||||
EXPECT_EQ(nullptr, &buffer[0]);
|
||||
EXPECT_EQ(static_cast<size_t>(0), buffer.size());
|
||||
EXPECT_EQ(static_cast<size_t>(0), buffer.capacity());
|
||||
}
|
||||
@@ -217,7 +217,7 @@ struct custom_context {
|
||||
|
||||
const char* format(const T&, custom_context& ctx) {
|
||||
ctx.called = true;
|
||||
return FMT_NULL;
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -361,8 +361,8 @@ TEST(ArgTest, WStringArg) {
|
||||
}
|
||||
|
||||
TEST(ArgTest, PointerArg) {
|
||||
void* p = FMT_NULL;
|
||||
const void* cp = FMT_NULL;
|
||||
void* p = nullptr;
|
||||
const void* cp = nullptr;
|
||||
CHECK_ARG_(char, cp, p);
|
||||
CHECK_ARG_(wchar_t, cp, p);
|
||||
CHECK_ARG(cp, );
|
||||
@@ -571,7 +571,7 @@ TEST(FormatterTest, FormatImplicitlyConvertibleToStringView) {
|
||||
}
|
||||
|
||||
// std::is_constructible is broken in MSVC until version 2015.
|
||||
#if FMT_USE_EXPLICIT && (!FMT_MSC_VER || FMT_MSC_VER >= 1900)
|
||||
#if !FMT_MSC_VER || FMT_MSC_VER >= 1900
|
||||
struct explicitly_convertible_to_string_view {
|
||||
explicit operator fmt::string_view() const { return "foo"; }
|
||||
};
|
||||
@@ -593,7 +593,7 @@ struct explicitly_convertible_to_string_like {
|
||||
template <typename String,
|
||||
typename = typename std::enable_if<std::is_constructible<
|
||||
String, const char*, std::size_t>::value>::type>
|
||||
FMT_EXPLICIT operator String() const {
|
||||
explicit operator String() const {
|
||||
return String("foo", 3u);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// For the license information refer to format.h.
|
||||
|
||||
#ifndef _CRT_SECURE_NO_WARNINGS
|
||||
# define _CRT_SECURE_NO_WARNINGS
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include "fmt/format.h"
|
||||
@@ -26,7 +26,7 @@ class custom_arg_formatter
|
||||
|
||||
custom_arg_formatter(fmt::format_context& ctx,
|
||||
fmt::format_parse_context* parse_ctx,
|
||||
fmt::format_specs* s = FMT_NULL)
|
||||
fmt::format_specs* s = nullptr)
|
||||
: base(ctx, parse_ctx, s) {}
|
||||
|
||||
using base::operator();
|
||||
|
||||
@@ -513,7 +513,7 @@ class arg_formatter
|
||||
*spec* contains format specifier information for standard argument types.
|
||||
\endrst
|
||||
*/
|
||||
arg_formatter(format_context& ctx, parse_context* parse_ctx = FMT_NULL, fmt::format_specs* spec = FMT_NULL)
|
||||
arg_formatter(format_context& ctx, parse_context* parse_ctx = nullptr, fmt::format_specs* spec = nullptr)
|
||||
: base(Range(ctx.out()), spec, {}), parse_ctx_(parse_ctx), ctx_(ctx) {}
|
||||
|
||||
using base::operator();
|
||||
@@ -693,13 +693,13 @@ struct formatter {
|
||||
template <typename FormatContext>
|
||||
auto format(const T& val, FormatContext& ctx) -> decltype(ctx.out()) {
|
||||
fmt::internal::handle_dynamic_spec<fmt::internal::width_checker>(
|
||||
specs_.width_, specs_.width_ref, ctx, FMT_NULL);
|
||||
specs_.width_, specs_.width_ref, ctx, nullptr);
|
||||
fmt::internal::handle_dynamic_spec<fmt::internal::precision_checker>(
|
||||
specs_.precision, specs_.precision_ref, ctx, FMT_NULL);
|
||||
specs_.precision, specs_.precision_ref, ctx, nullptr);
|
||||
typedef fmt::output_range<typename FormatContext::iterator,
|
||||
typename FormatContext::char_type>
|
||||
range_type;
|
||||
return visit_format_arg(arg_formatter<range_type>(ctx, FMT_NULL, &specs_),
|
||||
return visit_format_arg(arg_formatter<range_type>(ctx, nullptr, &specs_),
|
||||
basic_format_arg<FormatContext>(val));
|
||||
}
|
||||
|
||||
|
||||
@@ -169,9 +169,9 @@ TEST(FormatTest, FormatNegativeNaN) {
|
||||
}
|
||||
|
||||
TEST(FormatTest, StrError) {
|
||||
char* message = FMT_NULL;
|
||||
char* message = nullptr;
|
||||
char buffer[BUFFER_SIZE];
|
||||
EXPECT_ASSERT(fmt::safe_strerror(EDOM, message = FMT_NULL, 0),
|
||||
EXPECT_ASSERT(fmt::safe_strerror(EDOM, message = nullptr, 0),
|
||||
"invalid buffer");
|
||||
EXPECT_ASSERT(fmt::safe_strerror(EDOM, message = buffer, 0),
|
||||
"invalid buffer");
|
||||
@@ -259,6 +259,6 @@ TEST(UtilTest, WriteUIntPtr) {
|
||||
fmt::writer writer(buf);
|
||||
writer.write_pointer(fmt::internal::bit_cast<fmt::internal::uintptr_t>(
|
||||
reinterpret_cast<void*>(0xface)),
|
||||
FMT_NULL);
|
||||
nullptr);
|
||||
EXPECT_EQ("0xface", to_string(buf));
|
||||
}
|
||||
|
||||
@@ -63,16 +63,12 @@ TEST(FormatterTest, TestFormattersEnabled) {
|
||||
unsigned short, int, unsigned, long, unsigned long,
|
||||
long long, unsigned long long, float, double,
|
||||
long double, void*, const void*, char*, const char*,
|
||||
std::string>();
|
||||
std::string, std::nullptr_t>();
|
||||
check_enabled_formatters<wchar_t, bool, wchar_t, signed char, unsigned char,
|
||||
short, unsigned short, int, unsigned, long,
|
||||
unsigned long, long long, unsigned long long, float,
|
||||
double, long double, void*, const void*, wchar_t*,
|
||||
const wchar_t*, std::wstring>();
|
||||
# if FMT_USE_NULLPTR
|
||||
check_enabled_formatters<char, std::nullptr_t>();
|
||||
check_enabled_formatters<wchar_t, std::nullptr_t>();
|
||||
# endif
|
||||
const wchar_t*, std::wstring, std::nullptr_t>();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -192,7 +188,7 @@ TEST(IteratorTest, CountingIterator) {
|
||||
}
|
||||
|
||||
TEST(IteratorTest, TruncatingIterator) {
|
||||
char* p = FMT_NULL;
|
||||
char* p = nullptr;
|
||||
fmt::internal::truncating_iterator<char*> it(p, 3);
|
||||
auto prev = it++;
|
||||
EXPECT_EQ(prev.base(), p);
|
||||
@@ -254,7 +250,7 @@ TEST(AllocatorTest, allocator_ref) {
|
||||
test_allocator_ref ref2(ref);
|
||||
check_forwarding(alloc, ref2);
|
||||
test_allocator_ref ref3;
|
||||
EXPECT_EQ(FMT_NULL, ref3.get());
|
||||
EXPECT_EQ(nullptr, ref3.get());
|
||||
ref3 = ref;
|
||||
check_forwarding(alloc, ref3);
|
||||
}
|
||||
@@ -270,7 +266,7 @@ static void check_move_buffer(
|
||||
EXPECT_EQ(str, std::string(&buffer2[0], buffer2.size()));
|
||||
EXPECT_EQ(5u, buffer2.capacity());
|
||||
// Move should transfer allocator.
|
||||
EXPECT_EQ(FMT_NULL, buffer.get_allocator().get());
|
||||
EXPECT_EQ(nullptr, buffer.get_allocator().get());
|
||||
EXPECT_EQ(alloc, buffer2.get_allocator().get());
|
||||
}
|
||||
|
||||
@@ -353,7 +349,7 @@ TEST(MemoryBufferTest, Grow) {
|
||||
TEST(MemoryBufferTest, Allocator) {
|
||||
typedef allocator_ref<mock_allocator<char>> TestAllocator;
|
||||
basic_memory_buffer<char, 10, TestAllocator> buffer;
|
||||
EXPECT_EQ(FMT_NULL, buffer.get_allocator().get());
|
||||
EXPECT_EQ(nullptr, buffer.get_allocator().get());
|
||||
StrictMock<mock_allocator<char>> alloc;
|
||||
char mem;
|
||||
{
|
||||
@@ -493,7 +489,7 @@ TEST(UtilTest, FormatSystemError) {
|
||||
fmt::print("warning: std::allocator allocates {} chars", max_size);
|
||||
return;
|
||||
}
|
||||
fmt::format_system_error(message, EDOM, fmt::string_view(FMT_NULL, max_size));
|
||||
fmt::format_system_error(message, EDOM, fmt::string_view(nullptr, max_size));
|
||||
EXPECT_EQ(fmt::format("error {}", EDOM), to_string(message));
|
||||
}
|
||||
|
||||
@@ -1548,7 +1544,7 @@ TEST(FormatterTest, FormatCString) {
|
||||
EXPECT_EQ("test", format("{0:s}", "test"));
|
||||
char nonconst[] = "nonconst";
|
||||
EXPECT_EQ("nonconst", format("{0}", nonconst));
|
||||
EXPECT_THROW_MSG(format("{0}", static_cast<const char*>(FMT_NULL)),
|
||||
EXPECT_THROW_MSG(format("{0}", static_cast<const char*>(nullptr)),
|
||||
format_error, "string pointer is null");
|
||||
}
|
||||
|
||||
@@ -1570,7 +1566,7 @@ TEST(FormatterTest, FormatUCharString) {
|
||||
|
||||
TEST(FormatterTest, FormatPointer) {
|
||||
check_unknown_types(reinterpret_cast<void*>(0x1234), "p", "pointer");
|
||||
EXPECT_EQ("0x0", format("{0}", static_cast<void*>(FMT_NULL)));
|
||||
EXPECT_EQ("0x0", format("{0}", static_cast<void*>(nullptr)));
|
||||
EXPECT_EQ("0x1234", format("{0}", reinterpret_cast<void*>(0x1234)));
|
||||
EXPECT_EQ("0x1234", format("{0:p}", reinterpret_cast<void*>(0x1234)));
|
||||
EXPECT_EQ("0x" + std::string(sizeof(void*) * CHAR_BIT / 4, 'f'),
|
||||
@@ -1581,7 +1577,7 @@ TEST(FormatterTest, FormatPointer) {
|
||||
std::shared_ptr<int> sp(new int(1));
|
||||
EXPECT_EQ(format("{}", fmt::ptr(sp.get())), format("{}", fmt::ptr(sp)));
|
||||
#if FMT_USE_NULLPTR
|
||||
EXPECT_EQ("0x0", format("{}", FMT_NULL));
|
||||
EXPECT_EQ("0x0", format("{}", nullptr));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1674,7 +1670,7 @@ TEST(FormatterTest, FormatExamples) {
|
||||
FILE* ftest = safe_fopen(filename, "r");
|
||||
if (ftest) fclose(ftest);
|
||||
int error_code = errno;
|
||||
EXPECT_TRUE(ftest == FMT_NULL);
|
||||
EXPECT_TRUE(ftest == nullptr);
|
||||
EXPECT_SYSTEM_ERROR(
|
||||
{
|
||||
FILE* f = safe_fopen(filename, "r");
|
||||
@@ -1905,7 +1901,7 @@ class mock_arg_formatter
|
||||
typedef buffer_range range;
|
||||
|
||||
mock_arg_formatter(fmt::format_context& ctx, fmt::format_parse_context*,
|
||||
fmt::format_specs* s = FMT_NULL)
|
||||
fmt::format_specs* s = nullptr)
|
||||
: base(fmt::internal::get_container(ctx.out()), s, ctx.locale()) {
|
||||
EXPECT_CALL(*this, call(42));
|
||||
}
|
||||
@@ -2170,8 +2166,8 @@ struct test_parse_context {
|
||||
FMT_CONSTEXPR unsigned next_arg_id() { return 11; }
|
||||
template <typename Id> FMT_CONSTEXPR void check_arg_id(Id) {}
|
||||
|
||||
FMT_CONSTEXPR const char* begin() { return FMT_NULL; }
|
||||
FMT_CONSTEXPR const char* end() { return FMT_NULL; }
|
||||
FMT_CONSTEXPR const char* begin() { return nullptr; }
|
||||
FMT_CONSTEXPR const char* end() { return nullptr; }
|
||||
|
||||
void on_error(const char*) {}
|
||||
};
|
||||
@@ -2337,7 +2333,7 @@ FMT_CONSTEXPR bool equal(const char* s1, const char* s2) {
|
||||
|
||||
template <typename... Args>
|
||||
FMT_CONSTEXPR bool test_error(const char* fmt, const char* expected_error) {
|
||||
const char* actual_error = FMT_NULL;
|
||||
const char* actual_error = nullptr;
|
||||
fmt::internal::do_check_format_string<char, test_error_handler, Args...>(
|
||||
string_view(fmt, len(fmt)), test_error_handler(actual_error));
|
||||
return equal(actual_error, expected_error);
|
||||
@@ -2349,7 +2345,7 @@ FMT_CONSTEXPR bool test_error(const char* fmt, const char* expected_error) {
|
||||
static_assert(test_error<__VA_ARGS__>(fmt, error), "")
|
||||
|
||||
TEST(FormatTest, FormatStringErrors) {
|
||||
EXPECT_ERROR_NOARGS("foo", FMT_NULL);
|
||||
EXPECT_ERROR_NOARGS("foo", nullptr);
|
||||
EXPECT_ERROR_NOARGS("}", "unmatched '}' in format string");
|
||||
EXPECT_ERROR("{0:s", "unknown format specifier", Date);
|
||||
# if FMT_MSC_VER >= 1916
|
||||
|
||||
@@ -53,6 +53,4 @@ TEST(GrisuTest, Prettify) {
|
||||
EXPECT_EQ("0.001234", fmt::format("{}", 1234e-6));
|
||||
}
|
||||
|
||||
TEST(GrisuTest, ZeroPrecision) {
|
||||
EXPECT_EQ("1", fmt::format("{:.0}", 1.0));
|
||||
}
|
||||
TEST(GrisuTest, ZeroPrecision) { EXPECT_EQ("1", fmt::format("{:.0}", 1.0)); }
|
||||
|
||||
@@ -54,7 +54,9 @@ void do_nothing() {}
|
||||
|
||||
FMT_NORETURN void throw_exception() { throw std::runtime_error("test"); }
|
||||
|
||||
FMT_NORETURN void throw_system_error() { throw fmt::system_error(EDOM, "test"); }
|
||||
FMT_NORETURN void throw_system_error() {
|
||||
throw fmt::system_error(EDOM, "test");
|
||||
}
|
||||
|
||||
// Tests that when EXPECT_THROW_MSG fails, it evaluates its message argument
|
||||
// exactly once.
|
||||
@@ -355,10 +357,10 @@ TEST(OutputRedirectTest, FlushErrorInCtor) {
|
||||
// Put a character in a file buffer.
|
||||
EXPECT_EQ('x', fputc('x', f.get()));
|
||||
FMT_POSIX(close(write_fd));
|
||||
std::unique_ptr<OutputRedirect> redir{FMT_NULL};
|
||||
std::unique_ptr<OutputRedirect> redir{nullptr};
|
||||
EXPECT_SYSTEM_ERROR_NOASSERT(redir.reset(new OutputRedirect(f.get())), EBADF,
|
||||
"cannot flush stream");
|
||||
redir.reset(FMT_NULL);
|
||||
redir.reset(nullptr);
|
||||
write_copy.dup2(write_fd); // "undo" close or dtor will fail
|
||||
}
|
||||
|
||||
@@ -367,7 +369,7 @@ TEST(OutputRedirectTest, DupErrorInCtor) {
|
||||
int fd = (f.fileno)();
|
||||
file copy = file::dup(fd);
|
||||
FMT_POSIX(close(fd));
|
||||
std::unique_ptr<OutputRedirect> redir{FMT_NULL};
|
||||
std::unique_ptr<OutputRedirect> redir{nullptr};
|
||||
EXPECT_SYSTEM_ERROR_NOASSERT(
|
||||
redir.reset(new OutputRedirect(f.get())), EBADF,
|
||||
fmt::format("cannot duplicate file descriptor {}", fd));
|
||||
@@ -420,7 +422,7 @@ TEST(OutputRedirectTest, ErrorInDtor) {
|
||||
// redirecting the output in EXPECT_STDERR and the second close
|
||||
// will break output redirection.
|
||||
FMT_POSIX(close(write_fd));
|
||||
SUPPRESS_ASSERT(redir.reset(FMT_NULL));
|
||||
SUPPRESS_ASSERT(redir.reset(nullptr));
|
||||
},
|
||||
format_system_error(EBADF, "cannot flush stream"));
|
||||
write_copy.dup2(write_fd); // "undo" close or dtor of buffered_file will fail
|
||||
|
||||
@@ -155,7 +155,7 @@ std::string read(fmt::file& f, std::size_t count);
|
||||
|
||||
template <typename Mock> struct ScopedMock : testing::StrictMock<Mock> {
|
||||
ScopedMock() { Mock::instance = this; }
|
||||
~ScopedMock() { Mock::instance = FMT_NULL; }
|
||||
~ScopedMock() { Mock::instance = nullptr; }
|
||||
};
|
||||
|
||||
#endif // FMT_GTEST_EXTRA_H_
|
||||
|
||||
@@ -26,13 +26,13 @@ template <typename Allocator> class allocator_ref {
|
||||
|
||||
void move(allocator_ref& other) {
|
||||
alloc_ = other.alloc_;
|
||||
other.alloc_ = FMT_NULL;
|
||||
other.alloc_ = nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
typedef typename Allocator::value_type value_type;
|
||||
|
||||
explicit allocator_ref(Allocator* alloc = FMT_NULL) : alloc_(alloc) {}
|
||||
explicit allocator_ref(Allocator* alloc = nullptr) : alloc_(alloc) {}
|
||||
|
||||
allocator_ref(const allocator_ref& other) : alloc_(other.alloc_) {}
|
||||
allocator_ref(allocator_ref&& other) { move(other); }
|
||||
|
||||
@@ -167,7 +167,7 @@ TEST(OStreamTest, WriteToOStreamMaxSize) {
|
||||
} os(streambuf);
|
||||
|
||||
testing::InSequence sequence;
|
||||
const char* data = FMT_NULL;
|
||||
const char* data = nullptr;
|
||||
typedef std::make_unsigned<std::streamsize>::type ustreamsize;
|
||||
ustreamsize size = max_size;
|
||||
do {
|
||||
|
||||
@@ -131,7 +131,7 @@ int test::dup2(int fildes, int fildes2) {
|
||||
}
|
||||
|
||||
FILE* test::fdopen(int fildes, const char* mode) {
|
||||
EMULATE_EINTR(fdopen, FMT_NULL);
|
||||
EMULATE_EINTR(fdopen, nullptr);
|
||||
return ::FMT_POSIX(fdopen(fildes, mode));
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ int test::pipe(int* pfds, unsigned psize, int textmode) {
|
||||
#endif
|
||||
|
||||
FILE* test::fopen(const char* filename, const char* mode) {
|
||||
EMULATE_EINTR(fopen, FMT_NULL);
|
||||
EMULATE_EINTR(fopen, nullptr);
|
||||
return ::fopen(filename, mode);
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ TEST(UtilTest, GetPageSize) {
|
||||
|
||||
TEST(FileTest, OpenRetry) {
|
||||
write_file("test", "there must be something here");
|
||||
std::unique_ptr<file> f{FMT_NULL};
|
||||
std::unique_ptr<file> f{nullptr};
|
||||
EXPECT_RETRY(f.reset(new file("test", file::RDONLY)), open,
|
||||
"cannot open file test");
|
||||
#ifndef _WIN32
|
||||
@@ -231,7 +231,7 @@ TEST(FileTest, CloseNoRetryInDtor) {
|
||||
EXPECT_WRITE(stderr,
|
||||
{
|
||||
close_count = 1;
|
||||
f.reset(FMT_NULL);
|
||||
f.reset(nullptr);
|
||||
saved_close_count = close_count;
|
||||
close_count = 0;
|
||||
},
|
||||
@@ -384,7 +384,7 @@ TEST(FileTest, FdopenNoRetry) {
|
||||
|
||||
TEST(BufferedFileTest, OpenRetry) {
|
||||
write_file("test", "there must be something here");
|
||||
std::unique_ptr<buffered_file> f{FMT_NULL};
|
||||
std::unique_ptr<buffered_file> f{nullptr};
|
||||
EXPECT_RETRY(f.reset(new buffered_file("test", "r")), fopen,
|
||||
"cannot open file test");
|
||||
#ifndef _WIN32
|
||||
@@ -402,7 +402,7 @@ TEST(BufferedFileTest, CloseNoRetryInDtor) {
|
||||
EXPECT_WRITE(stderr,
|
||||
{
|
||||
fclose_count = 1;
|
||||
f.reset(FMT_NULL);
|
||||
f.reset(nullptr);
|
||||
saved_fclose_count = fclose_count;
|
||||
fclose_count = 0;
|
||||
},
|
||||
@@ -441,7 +441,7 @@ TEST(ScopedMock, Scope) {
|
||||
TestMock& copy = mock;
|
||||
static_cast<void>(copy);
|
||||
}
|
||||
EXPECT_EQ(FMT_NULL, TestMock::instance);
|
||||
EXPECT_EQ(nullptr, TestMock::instance);
|
||||
}
|
||||
|
||||
#ifdef FMT_LOCALE
|
||||
@@ -526,7 +526,7 @@ TEST(LocaleTest, Locale) {
|
||||
# endif
|
||||
ScopedMock<LocaleMock> mock;
|
||||
LocaleType impl = reinterpret_cast<LocaleType>(42);
|
||||
EXPECT_CALL(mock, newlocale(LC_NUMERIC_MASK, StrEq("C"), FMT_NULL))
|
||||
EXPECT_CALL(mock, newlocale(LC_NUMERIC_MASK, StrEq("C"), nullptr))
|
||||
.WillOnce(Return(impl));
|
||||
EXPECT_CALL(mock, freelocale(impl));
|
||||
fmt::Locale locale;
|
||||
|
||||
@@ -58,26 +58,26 @@ static void write(file& f, fmt::string_view s) {
|
||||
|
||||
TEST(BufferedFileTest, DefaultCtor) {
|
||||
buffered_file f;
|
||||
EXPECT_TRUE(f.get() == FMT_NULL);
|
||||
EXPECT_TRUE(f.get() == nullptr);
|
||||
}
|
||||
|
||||
TEST(BufferedFileTest, MoveCtor) {
|
||||
buffered_file bf = open_buffered_file();
|
||||
FILE* fp = bf.get();
|
||||
EXPECT_TRUE(fp != FMT_NULL);
|
||||
EXPECT_TRUE(fp != nullptr);
|
||||
buffered_file bf2(std::move(bf));
|
||||
EXPECT_EQ(fp, bf2.get());
|
||||
EXPECT_TRUE(bf.get() == FMT_NULL);
|
||||
EXPECT_TRUE(bf.get() == nullptr);
|
||||
}
|
||||
|
||||
TEST(BufferedFileTest, MoveAssignment) {
|
||||
buffered_file bf = open_buffered_file();
|
||||
FILE* fp = bf.get();
|
||||
EXPECT_TRUE(fp != FMT_NULL);
|
||||
EXPECT_TRUE(fp != nullptr);
|
||||
buffered_file bf2;
|
||||
bf2 = std::move(bf);
|
||||
EXPECT_EQ(fp, bf2.get());
|
||||
EXPECT_TRUE(bf.get() == FMT_NULL);
|
||||
EXPECT_TRUE(bf.get() == nullptr);
|
||||
}
|
||||
|
||||
TEST(BufferedFileTest, MoveAssignmentClosesFile) {
|
||||
@@ -89,13 +89,13 @@ TEST(BufferedFileTest, MoveAssignmentClosesFile) {
|
||||
}
|
||||
|
||||
TEST(BufferedFileTest, MoveFromTemporaryInCtor) {
|
||||
FILE* fp = FMT_NULL;
|
||||
FILE* fp = nullptr;
|
||||
buffered_file f(open_buffered_file(&fp));
|
||||
EXPECT_EQ(fp, f.get());
|
||||
}
|
||||
|
||||
TEST(BufferedFileTest, MoveFromTemporaryInAssignment) {
|
||||
FILE* fp = FMT_NULL;
|
||||
FILE* fp = nullptr;
|
||||
buffered_file f;
|
||||
f = open_buffered_file(&fp);
|
||||
EXPECT_EQ(fp, f.get());
|
||||
@@ -126,7 +126,7 @@ TEST(BufferedFileTest, CloseErrorInDtor) {
|
||||
// redirecting the output in EXPECT_STDERR and the second close
|
||||
// will break output redirection.
|
||||
FMT_POSIX(close(f->fileno()));
|
||||
SUPPRESS_ASSERT(f.reset(FMT_NULL));
|
||||
SUPPRESS_ASSERT(f.reset(nullptr));
|
||||
},
|
||||
format_system_error(EBADF, "cannot close file") + "\n");
|
||||
}
|
||||
@@ -135,7 +135,7 @@ TEST(BufferedFileTest, Close) {
|
||||
buffered_file f = open_buffered_file();
|
||||
int fd = f.fileno();
|
||||
f.close();
|
||||
EXPECT_TRUE(f.get() == FMT_NULL);
|
||||
EXPECT_TRUE(f.get() == nullptr);
|
||||
EXPECT_TRUE(isclosed(fd));
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ TEST(BufferedFileTest, CloseError) {
|
||||
buffered_file f = open_buffered_file();
|
||||
FMT_POSIX(close(f.fileno()));
|
||||
EXPECT_SYSTEM_ERROR_NOASSERT(f.close(), EBADF, "cannot close file");
|
||||
EXPECT_TRUE(f.get() == FMT_NULL);
|
||||
EXPECT_TRUE(f.get() == nullptr);
|
||||
}
|
||||
|
||||
TEST(BufferedFileTest, Fileno) {
|
||||
@@ -257,7 +257,7 @@ TEST(FileTest, CloseErrorInDtor) {
|
||||
// redirecting the output in EXPECT_STDERR and the second close
|
||||
// will break output redirection.
|
||||
FMT_POSIX(close(f->descriptor()));
|
||||
SUPPRESS_ASSERT(f.reset(FMT_NULL));
|
||||
SUPPRESS_ASSERT(f.reset(nullptr));
|
||||
},
|
||||
format_system_error(EBADF, "cannot close file") + "\n");
|
||||
}
|
||||
|
||||
@@ -620,7 +620,7 @@ template <typename T> struct user_allocator {
|
||||
|
||||
pointer allocate(
|
||||
size_type cnt,
|
||||
typename std::allocator<fmt::monostate>::const_pointer = FMT_NULL) {
|
||||
typename std::allocator<fmt::monostate>::const_pointer = nullptr) {
|
||||
return new value_type[cnt];
|
||||
}
|
||||
|
||||
|
||||
@@ -434,11 +434,11 @@ TEST(PrintfTest, Char) {
|
||||
|
||||
TEST(PrintfTest, String) {
|
||||
EXPECT_PRINTF("abc", "%s", "abc");
|
||||
const char* null_str = FMT_NULL;
|
||||
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 = FMT_NULL;
|
||||
const wchar_t* null_wstr = nullptr;
|
||||
EXPECT_PRINTF(L"(null)", L"%s", null_wstr);
|
||||
EXPECT_PRINTF(L" (null)", L"%10s", null_wstr);
|
||||
}
|
||||
@@ -447,22 +447,22 @@ TEST(PrintfTest, Pointer) {
|
||||
int n;
|
||||
void* p = &n;
|
||||
EXPECT_PRINTF(fmt::format("{}", p), "%p", p);
|
||||
p = FMT_NULL;
|
||||
p = nullptr;
|
||||
EXPECT_PRINTF("(nil)", "%p", p);
|
||||
EXPECT_PRINTF(" (nil)", "%10p", p);
|
||||
const char* s = "test";
|
||||
EXPECT_PRINTF(fmt::format("{:p}", s), "%p", s);
|
||||
const char* null_str = FMT_NULL;
|
||||
const char* null_str = nullptr;
|
||||
EXPECT_PRINTF("(nil)", "%p", null_str);
|
||||
|
||||
p = &n;
|
||||
EXPECT_PRINTF(fmt::format(L"{}", p), L"%p", p);
|
||||
p = FMT_NULL;
|
||||
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 = FMT_NULL;
|
||||
const wchar_t* null_wstr = nullptr;
|
||||
EXPECT_PRINTF(L"(nil)", L"%p", null_wstr);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,36 +3,36 @@
|
||||
|
||||
TEST(StdFormatTest, Escaping) {
|
||||
using namespace std;
|
||||
string s = format("{0}-{{", 8); // s == "8-{"
|
||||
string s = format("{0}-{{", 8); // s == "8-{"
|
||||
EXPECT_EQ(s, "8-{");
|
||||
}
|
||||
|
||||
TEST(StdFormatTest, Indexing) {
|
||||
using namespace std;
|
||||
string s0 = format("{} to {}", "a", "b"); // OK: automatic indexing
|
||||
string s1 = format("{1} to {0}", "a", "b"); // OK: manual indexing
|
||||
string s0 = format("{} to {}", "a", "b"); // OK: automatic indexing
|
||||
string s1 = format("{1} to {0}", "a", "b"); // OK: manual indexing
|
||||
EXPECT_EQ(s0, "a to b");
|
||||
EXPECT_EQ(s1, "b to a");
|
||||
// Error: mixing automatic and manual indexing
|
||||
EXPECT_THROW(string s2 = format("{0} to {}", "a", "b"), std::format_error);
|
||||
// Error: mixing automatic and manual indexing
|
||||
EXPECT_THROW(string s3 = format("{} to {1}", "a", "b"), std::format_error);
|
||||
// Error: mixing automatic and manual indexing
|
||||
EXPECT_THROW(string s2 = format("{0} to {}", "a", "b"), std::format_error);
|
||||
// Error: mixing automatic and manual indexing
|
||||
EXPECT_THROW(string s3 = format("{} to {1}", "a", "b"), std::format_error);
|
||||
}
|
||||
|
||||
TEST(StdFormatTest, Alignment) {
|
||||
using namespace std;
|
||||
char c = 120;
|
||||
string s0 = format("{:6}", 42); // s0 == " 42"
|
||||
string s1 = format("{:6}", 'x'); // s1 == "x "
|
||||
string s2 = format("{:*<6}", 'x'); // s2 == "x*****"
|
||||
string s3 = format("{:*>6}", 'x'); // s3 == "*****x"
|
||||
string s4 = format("{:*^6}", 'x'); // s4 == "**x***"
|
||||
string s0 = format("{:6}", 42); // s0 == " 42"
|
||||
string s1 = format("{:6}", 'x'); // s1 == "x "
|
||||
string s2 = format("{:*<6}", 'x'); // s2 == "x*****"
|
||||
string s3 = format("{:*>6}", 'x'); // s3 == "*****x"
|
||||
string s4 = format("{:*^6}", 'x'); // s4 == "**x***"
|
||||
// Error: '=' with charT and no integer presentation type
|
||||
EXPECT_THROW(string s5 = format("{:=6}", 'x'), std::format_error);
|
||||
string s6 = format("{:6d}", c); // s6 == " 120"
|
||||
string s7 = format("{:=+06d}", c); // s7 == "+00120"
|
||||
string s8 = format("{:0=#6x}", 0xa); // s8 == "0x000a"
|
||||
string s9 = format("{:6}", true); // s9 == "true "
|
||||
string s6 = format("{:6d}", c); // s6 == " 120"
|
||||
string s7 = format("{:=+06d}", c); // s7 == "+00120"
|
||||
string s8 = format("{:0=#6x}", 0xa); // s8 == "0x000a"
|
||||
string s9 = format("{:6}", true); // s9 == "true "
|
||||
EXPECT_EQ(s0, " 42");
|
||||
EXPECT_EQ(s1, "x ");
|
||||
EXPECT_EQ(s2, "x*****");
|
||||
@@ -50,8 +50,10 @@ TEST(StdFormatTest, Float) {
|
||||
double nan = numeric_limits<double>::quiet_NaN();
|
||||
string s0 = format("{0:} {0:+} {0:-} {0: }", 1); // s0 == "1 +1 1 1"
|
||||
string s1 = format("{0:} {0:+} {0:-} {0: }", -1); // s1 == "-1 -1 -1 -1"
|
||||
string s2 = format("{0:} {0:+} {0:-} {0: }", inf); // s2 == "inf +inf inf inf"
|
||||
string s3 = format("{0:} {0:+} {0:-} {0: }", nan); // s3 == "nan +nan nan nan"
|
||||
string s2 =
|
||||
format("{0:} {0:+} {0:-} {0: }", inf); // s2 == "inf +inf inf inf"
|
||||
string s3 =
|
||||
format("{0:} {0:+} {0:-} {0: }", nan); // s3 == "nan +nan nan nan"
|
||||
EXPECT_EQ(s0, "1 +1 1 1");
|
||||
EXPECT_EQ(s1, "-1 -1 -1 -1");
|
||||
EXPECT_EQ(s2, "inf +inf inf inf");
|
||||
@@ -60,10 +62,10 @@ TEST(StdFormatTest, Float) {
|
||||
|
||||
TEST(StdFormatTest, Int) {
|
||||
using namespace std;
|
||||
string s0 = format("{}", 42); // s0 == "42"
|
||||
string s1 = format("{0:b} {0:d} {0:o} {0:x}", 42); // s1 == "101010 42 52 2a"
|
||||
string s2 = format("{0:#x} {0:#X}", 42); // s2 == "0x2a 0X2A"
|
||||
string s3 = format("{:n}", 1234); // s3 == "1,234" (depends on the locale)
|
||||
string s0 = format("{}", 42); // s0 == "42"
|
||||
string s1 = format("{0:b} {0:d} {0:o} {0:x}", 42); // s1 == "101010 42 52 2a"
|
||||
string s2 = format("{0:#x} {0:#X}", 42); // s2 == "0x2a 0X2A"
|
||||
string s3 = format("{:n}", 1234); // s3 == "1,234" (depends on the locale)
|
||||
EXPECT_EQ(s0, "42");
|
||||
EXPECT_EQ(s1, "101010 42 52 2a");
|
||||
EXPECT_EQ(s2, "0x2a 0X2A");
|
||||
@@ -74,9 +76,9 @@ TEST(StdFormatTest, Int) {
|
||||
|
||||
enum color { red, green, blue };
|
||||
|
||||
const char* color_names[] = { "red", "green", "blue" };
|
||||
const char* color_names[] = {"red", "green", "blue"};
|
||||
|
||||
template<> struct std::formatter<color> : std::formatter<const char*> {
|
||||
template <> struct std::formatter<color> : std::formatter<const char*> {
|
||||
auto format(color c, format_context& ctx) {
|
||||
return formatter<const char*>::format(color_names[c], ctx);
|
||||
}
|
||||
@@ -85,10 +87,12 @@ template<> struct std::formatter<color> : std::formatter<const char*> {
|
||||
struct err {};
|
||||
|
||||
TEST(StdFormatTest, Formatter) {
|
||||
std::string s0 = std::format("{}", 42); // OK: library-provided formatter
|
||||
//std::string s1 = std::format("{}", L"foo"); // Ill-formed: disabled formatter
|
||||
std::string s2 = std::format("{}", red); // OK: user-provided formatter
|
||||
//std::string s3 = std::format("{}", err{}); // Ill-formed: disabled formatter
|
||||
std::string s0 = std::format("{}", 42); // OK: library-provided formatter
|
||||
// std::string s1 = std::format("{}", L"foo"); // Ill-formed: disabled
|
||||
// formatter
|
||||
std::string s2 = std::format("{}", red); // OK: user-provided formatter
|
||||
// std::string s3 = std::format("{}", err{}); // Ill-formed: disabled
|
||||
// formatter
|
||||
EXPECT_EQ(s0, "42");
|
||||
EXPECT_EQ(s2, "red");
|
||||
}
|
||||
@@ -97,15 +101,14 @@ struct S {
|
||||
int value;
|
||||
};
|
||||
|
||||
template<> struct std::formatter<S> {
|
||||
template <> struct std::formatter<S> {
|
||||
size_t width_arg_id = 0;
|
||||
|
||||
// Parses a width argument id in the format { <digit> }.
|
||||
constexpr auto parse(format_parse_context& ctx) {
|
||||
auto iter = ctx.begin();
|
||||
auto get_char = [&]() { return iter != ctx.end() ? *iter : 0; };
|
||||
if (get_char() != '{')
|
||||
return iter;
|
||||
if (get_char() != '{') return iter;
|
||||
++iter;
|
||||
char c = get_char();
|
||||
if (!isdigit(c) || (++iter, get_char()) != '}')
|
||||
@@ -117,20 +120,22 @@ template<> struct std::formatter<S> {
|
||||
|
||||
// Formats S with width given by the argument width_arg_id.
|
||||
auto format(S s, format_context& ctx) {
|
||||
int width = visit_format_arg([](auto value) -> int {
|
||||
if constexpr (!is_integral_v<decltype(value)>)
|
||||
throw format_error("width is not integral");
|
||||
else if (value < 0 || value > numeric_limits<int>::max())
|
||||
throw format_error("invalid width");
|
||||
else
|
||||
return value;
|
||||
}, ctx.arg(width_arg_id));
|
||||
int width = visit_format_arg(
|
||||
[](auto value) -> int {
|
||||
if constexpr (!is_integral_v<decltype(value)>)
|
||||
throw format_error("width is not integral");
|
||||
else if (value < 0 || value > numeric_limits<int>::max())
|
||||
throw format_error("invalid width");
|
||||
else
|
||||
return value;
|
||||
},
|
||||
ctx.arg(width_arg_id));
|
||||
return format_to(ctx.out(), "{0:{1}}", s.value, width);
|
||||
}
|
||||
};
|
||||
|
||||
TEST(StdFormatTest, Parsing) {
|
||||
std::string s = std::format("{0:{1}}", S{42}, 10); // s == " 42"
|
||||
std::string s = std::format("{0:{1}}", S{42}, 10); // s == " 42"
|
||||
EXPECT_EQ(s, " 42");
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ std::string get_system_error(int error_code);
|
||||
extern const char* const FILE_CONTENT;
|
||||
|
||||
// Opens a buffered file for reading.
|
||||
fmt::buffered_file open_buffered_file(FILE** fp = FMT_NULL);
|
||||
fmt::buffered_file open_buffered_file(FILE** fp = nullptr);
|
||||
|
||||
inline FILE* safe_fopen(const char* filename, const char* mode) {
|
||||
#if defined(_WIN32) && !defined(__MINGW32__)
|
||||
|
||||
Reference in New Issue
Block a user