Fix handling of negative error codes in format_error_code

This commit is contained in:
vitaut
2016-03-02 07:01:21 -08:00
parent 6e820841d4
commit 9d577cae6f
2 changed files with 17 additions and 4 deletions

View File

@@ -101,13 +101,21 @@ TEST(FormatTest, FormatErrorCode) {
fmt::format_error_code(w, 42, prefix);
EXPECT_EQ(msg, w.str());
}
{
int codes[] = {42, -1};
for (std::size_t i = 0, n = sizeof(codes) / sizeof(*codes); i < n; ++i) {
// Test maximum buffer size.
msg = fmt::format("error {}", codes[i]);
fmt::MemoryWriter w;
std::string prefix(
fmt::internal::INLINE_BUFFER_SIZE - msg.size() - sep.size(), 'x');
fmt::format_error_code(w, 42, prefix);
fmt::format_error_code(w, codes[i], prefix);
EXPECT_EQ(prefix + sep + msg, w.str());
std::size_t size = fmt::internal::INLINE_BUFFER_SIZE;
EXPECT_EQ(size, w.size());
w.clear();
// Test with a message that doesn't fit into the buffer.
prefix += 'x';
fmt::format_error_code(w, codes[i], prefix);
EXPECT_EQ(msg, w.str());
}
}