Cleanup test
This commit is contained in:
parent
6b07fff0d9
commit
18c43a214c
@ -499,20 +499,17 @@ TEST(format_test, arg_errors) {
|
|||||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{00}"), 42), format_error,
|
EXPECT_THROW_MSG((void)fmt::format(runtime("{00}"), 42), format_error,
|
||||||
"invalid format string");
|
"invalid format string");
|
||||||
|
|
||||||
char format_str[buffer_size];
|
auto int_max = std::to_string(INT_MAX);
|
||||||
safe_sprintf(format_str, "{%u", INT_MAX);
|
EXPECT_THROW_MSG((void)fmt::format(runtime("{" + int_max)), format_error,
|
||||||
EXPECT_THROW_MSG((void)fmt::format(runtime(format_str)), format_error,
|
|
||||||
"invalid format string");
|
"invalid format string");
|
||||||
safe_sprintf(format_str, "{%u}", INT_MAX);
|
EXPECT_THROW_MSG((void)fmt::format(runtime("{" + int_max + "}")),
|
||||||
EXPECT_THROW_MSG((void)fmt::format(runtime(format_str)), format_error,
|
format_error, "argument not found");
|
||||||
"argument not found");
|
|
||||||
|
|
||||||
safe_sprintf(format_str, "{%u", INT_MAX + 1u);
|
auto int_maxer = std::to_string(INT_MAX + 1u);
|
||||||
EXPECT_THROW_MSG((void)fmt::format(runtime(format_str)), format_error,
|
EXPECT_THROW_MSG((void)fmt::format(runtime("{" + int_maxer)), format_error,
|
||||||
"invalid format string");
|
"invalid format string");
|
||||||
safe_sprintf(format_str, "{%u}", INT_MAX + 1u);
|
EXPECT_THROW_MSG((void)fmt::format(runtime("{" + int_maxer + "}")),
|
||||||
EXPECT_THROW_MSG((void)fmt::format(runtime(format_str)), format_error,
|
format_error, "argument not found");
|
||||||
"argument not found");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <int N> struct test_format {
|
template <int N> struct test_format {
|
||||||
|
26
test/util.h
26
test/util.h
@ -29,9 +29,9 @@ void safe_sprintf(char (&buffer)[SIZE], const char* format, ...) {
|
|||||||
extern const char* const file_content;
|
extern const char* const file_content;
|
||||||
|
|
||||||
// Opens a buffered file for reading.
|
// Opens a buffered file for reading.
|
||||||
fmt::buffered_file open_buffered_file(FILE** fp = nullptr);
|
auto open_buffered_file(FILE** fp = nullptr) -> fmt::buffered_file;
|
||||||
|
|
||||||
inline FILE* safe_fopen(const char* filename, const char* mode) {
|
inline auto safe_fopen(const char* filename, const char* mode) -> FILE* {
|
||||||
#if defined(_WIN32) && !defined(__MINGW32__)
|
#if defined(_WIN32) && !defined(__MINGW32__)
|
||||||
// Fix MSVC warning about "unsafe" fopen.
|
// Fix MSVC warning about "unsafe" fopen.
|
||||||
FILE* f = nullptr;
|
FILE* f = nullptr;
|
||||||
@ -51,17 +51,17 @@ template <typename Char> class basic_test_string {
|
|||||||
public:
|
public:
|
||||||
explicit basic_test_string(const Char* value = empty) : value_(value) {}
|
explicit basic_test_string(const Char* value = empty) : value_(value) {}
|
||||||
|
|
||||||
const std::basic_string<Char>& value() const { return value_; }
|
auto value() const -> const std::basic_string<Char>& { return value_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Char> const Char basic_test_string<Char>::empty[] = {0};
|
template <typename Char> const Char basic_test_string<Char>::empty[] = {0};
|
||||||
|
|
||||||
typedef basic_test_string<char> test_string;
|
using test_string = basic_test_string<char>;
|
||||||
typedef basic_test_string<wchar_t> test_wstring;
|
using test_wstring = basic_test_string<wchar_t>;
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
std::basic_ostream<Char>& operator<<(std::basic_ostream<Char>& os,
|
auto operator<<(std::basic_ostream<Char>& os, const basic_test_string<Char>& s)
|
||||||
const basic_test_string<Char>& s) {
|
-> std::basic_ostream<Char>& {
|
||||||
os << s.value();
|
os << s.value();
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
@ -72,10 +72,12 @@ class date {
|
|||||||
public:
|
public:
|
||||||
date(int year, int month, int day) : year_(year), month_(month), day_(day) {}
|
date(int year, int month, int day) : year_(year), month_(month), day_(day) {}
|
||||||
|
|
||||||
int year() const { return year_; }
|
auto year() const -> int { return year_; }
|
||||||
int month() const { return month_; }
|
auto month() const -> int { return month_; }
|
||||||
int day() const { return day_; }
|
auto day() const -> int { return day_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns a locale with the given name if available or classic locale otherwise.
|
// Returns a locale with the given name if available or classic locale
|
||||||
std::locale get_locale(const char* name, const char* alt_name = nullptr);
|
// otherwise.
|
||||||
|
auto get_locale(const char* name, const char* alt_name = nullptr)
|
||||||
|
-> std::locale;
|
||||||
|
Loading…
Reference in New Issue
Block a user