Remove redundant tests
This commit is contained in:
parent
a585571e90
commit
9660e5b956
@ -800,7 +800,8 @@ TEST(format_test, zero_flag) {
|
||||
}
|
||||
|
||||
TEST(format_test, zero_flag_and_align) {
|
||||
// If the 0 character and an align option both appear, the 0 character is ignored.
|
||||
// If the 0 character and an align option both appear, the 0 character is
|
||||
// ignored.
|
||||
EXPECT_EQ("42 ", fmt::format("{0:<05}", 42));
|
||||
EXPECT_EQ("-42 ", fmt::format("{0:<05}", -42));
|
||||
EXPECT_EQ(" 42 ", fmt::format("{0:^05}", 42));
|
||||
@ -2177,117 +2178,6 @@ TEST(format_test, format_to_n_output_iterator) {
|
||||
EXPECT_STREQ(buf, "42");
|
||||
}
|
||||
|
||||
#if FMT_USE_CONSTEXPR
|
||||
struct test_error_handler {
|
||||
const char*& error;
|
||||
|
||||
FMT_CONSTEXPR test_error_handler(const char*& err) : error(err) {}
|
||||
|
||||
FMT_CONSTEXPR test_error_handler(const test_error_handler& other)
|
||||
: error(other.error) {}
|
||||
|
||||
FMT_CONSTEXPR void on_error(const char* message) {
|
||||
if (!error) error = message;
|
||||
}
|
||||
};
|
||||
|
||||
FMT_CONSTEXPR size_t len(const char* s) {
|
||||
size_t len = 0;
|
||||
while (*s++) ++len;
|
||||
return len;
|
||||
}
|
||||
|
||||
FMT_CONSTEXPR bool equal(const char* s1, const char* s2) {
|
||||
if (!s1 || !s2) return s1 == s2;
|
||||
while (*s1 && *s1 == *s2) {
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
return *s1 == *s2;
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
FMT_CONSTEXPR bool test_error(const char* fmt, const char* expected_error) {
|
||||
const char* actual_error = nullptr;
|
||||
auto s = string_view(fmt, len(fmt));
|
||||
auto checker =
|
||||
fmt::detail::format_string_checker<char, test_error_handler, Args...>(
|
||||
s, test_error_handler(actual_error));
|
||||
fmt::detail::parse_format_string<true>(s, checker);
|
||||
return equal(actual_error, expected_error);
|
||||
}
|
||||
|
||||
# define EXPECT_ERROR_NOARGS(fmt, error) \
|
||||
// static_assert(test_error(fmt, error), "")
|
||||
# define EXPECT_ERROR(fmt, error, ...) \
|
||||
// static_assert(test_error<__VA_ARGS__>(fmt, error), "")
|
||||
|
||||
TEST(format_test, format_string_errors) {
|
||||
EXPECT_ERROR_NOARGS("foo", nullptr);
|
||||
EXPECT_ERROR_NOARGS("}", "unmatched '}' in format string");
|
||||
EXPECT_ERROR("{0:s", "unknown format specifier", date);
|
||||
# if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1916
|
||||
// This causes an detail compiler error in MSVC2017.
|
||||
EXPECT_ERROR("{:10000000000}", "number is too big", int);
|
||||
EXPECT_ERROR("{:.10000000000}", "number is too big", int);
|
||||
EXPECT_ERROR_NOARGS("{:x}", "argument not found");
|
||||
EXPECT_ERROR("{:+}", "format specifier requires numeric argument",
|
||||
const char*);
|
||||
EXPECT_ERROR("{:-}", "format specifier requires numeric argument",
|
||||
const char*);
|
||||
EXPECT_ERROR("{:#}", "format specifier requires numeric argument",
|
||||
const char*);
|
||||
EXPECT_ERROR("{: }", "format specifier requires numeric argument",
|
||||
const char*);
|
||||
EXPECT_ERROR("{:0}", "format specifier requires numeric argument",
|
||||
const char*);
|
||||
EXPECT_ERROR("{:+}", "format specifier requires signed argument", unsigned);
|
||||
EXPECT_ERROR("{:-}", "format specifier requires signed argument", unsigned);
|
||||
EXPECT_ERROR("{: }", "format specifier requires signed argument", unsigned);
|
||||
EXPECT_ERROR("{:{}}", "argument not found", int);
|
||||
EXPECT_ERROR("{:.{}}", "argument not found", double);
|
||||
# if defined(__cpp_lib_is_constant_evaluated) && !defined(__LCC__)
|
||||
EXPECT_ERROR("{:{}}", "width/precision is not integer", int, double);
|
||||
# endif
|
||||
EXPECT_ERROR("{:.2}", "precision not allowed for this argument type", int);
|
||||
EXPECT_ERROR("{:s}", "invalid type specifier", int);
|
||||
EXPECT_ERROR("{:s}", "invalid type specifier", char);
|
||||
EXPECT_ERROR("{:+}", "invalid format specifier for char", char);
|
||||
EXPECT_ERROR("{:s}", "invalid type specifier", double);
|
||||
EXPECT_ERROR("{:d}", "invalid type specifier", const char*);
|
||||
EXPECT_ERROR("{:d}", "invalid type specifier", std::string);
|
||||
EXPECT_ERROR("{:s}", "invalid type specifier", void*);
|
||||
# else
|
||||
fmt::print("warning: constexpr is broken in this version of MSVC\n");
|
||||
# endif
|
||||
# if FMT_USE_NONTYPE_TEMPLATE_ARGS
|
||||
using namespace fmt::literals;
|
||||
EXPECT_ERROR("{foo}", "named argument is not found", decltype("bar"_a = 42));
|
||||
EXPECT_ERROR("{foo}", "named argument is not found",
|
||||
decltype(fmt::arg("foo", 42)));
|
||||
# else
|
||||
EXPECT_ERROR("{foo}",
|
||||
"compile-time checks for named arguments require C++20 support",
|
||||
int);
|
||||
# endif
|
||||
EXPECT_ERROR_NOARGS("{10000000000}", "argument not found");
|
||||
EXPECT_ERROR_NOARGS("{0x}", "invalid format string");
|
||||
EXPECT_ERROR_NOARGS("{-}", "invalid format string");
|
||||
EXPECT_ERROR("{:{0x}}", "invalid format string", int);
|
||||
EXPECT_ERROR("{:{-}}", "invalid format string", int);
|
||||
EXPECT_ERROR("{:.{0x}}", "invalid format string", int);
|
||||
EXPECT_ERROR("{:.{-}}", "invalid format string", int);
|
||||
EXPECT_ERROR("{:.x}", "missing precision specifier", int);
|
||||
EXPECT_ERROR_NOARGS("{}", "argument not found");
|
||||
EXPECT_ERROR("{1}", "argument not found", int);
|
||||
EXPECT_ERROR("{1}{}",
|
||||
"cannot switch from manual to automatic argument indexing", int,
|
||||
int);
|
||||
EXPECT_ERROR("{}{1}",
|
||||
"cannot switch from automatic to manual argument indexing", int,
|
||||
int);
|
||||
}
|
||||
|
||||
TEST(format_test, vformat_to) {
|
||||
using context = fmt::format_context;
|
||||
fmt::basic_format_arg<context> arg = fmt::detail::make_arg<context>(42);
|
||||
@ -2300,8 +2190,6 @@ TEST(format_test, vformat_to) {
|
||||
EXPECT_EQ("42", s);
|
||||
}
|
||||
|
||||
#endif // FMT_USE_CONSTEXPR
|
||||
|
||||
TEST(format_test, char_traits_is_not_ambiguous) {
|
||||
// Test that we don't inject detail names into the std namespace.
|
||||
using namespace std;
|
||||
|
Loading…
Reference in New Issue
Block a user