Reformat all source code; no functional changes

Before adding the format checker, the mainline should be clean, to
avoid false failures.
This commit is contained in:
Florin Iucha 2021-11-25 11:52:21 -05:00 committed by Victor Zverovich
parent 491ba2dda5
commit acad8cfab1
10 changed files with 80 additions and 64 deletions

View File

@ -28,8 +28,9 @@
# endif # endif
# if (FMT_HAS_INCLUDE(<fcntl.h>) || defined(__APPLE__) || \ # if (FMT_HAS_INCLUDE(<fcntl.h>) || defined(__APPLE__) || \
defined(__linux__)) && \ defined(__linux__)) && \
(!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) (!defined(WINAPI_FAMILY) || \
# include <fcntl.h> // for O_RDONLY (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP))
# include <fcntl.h> // for O_RDONLY
# define FMT_USE_FCNTL 1 # define FMT_USE_FCNTL 1
# else # else
# define FMT_USE_FCNTL 0 # define FMT_USE_FCNTL 0
@ -395,10 +396,10 @@ struct ostream_params {
// Intel has a bug that results in failure to deduce a constructor // Intel has a bug that results in failure to deduce a constructor
// for empty parameter packs. // for empty parameter packs.
#if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 2000 # if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 2000
ostream_params(int new_oflag) : oflag(new_oflag) {} ostream_params(int new_oflag) : oflag(new_oflag) {}
ostream_params(detail::buffer_size bs) : buffer_size(bs.value) {} ostream_params(detail::buffer_size bs) : buffer_size(bs.value) {}
#endif # endif
}; };
FMT_END_DETAIL_NAMESPACE FMT_END_DETAIL_NAMESPACE

View File

@ -79,7 +79,6 @@ export module fmt;
#define FMT_END_DETAIL_NAMESPACE \ #define FMT_END_DETAIL_NAMESPACE \
} \ } \
export { export {
// all library-provided declarations and definitions // all library-provided declarations and definitions
// must be in the module purview to be exported // must be in the module purview to be exported
#include "fmt/args.h" #include "fmt/args.h"

View File

@ -453,9 +453,9 @@ TEST(chrono_test, format_default_fp) {
} }
TEST(chrono_test, format_precision) { TEST(chrono_test, format_precision) {
EXPECT_THROW_MSG((void)fmt::format(runtime("{:.2}"), std::chrono::seconds(42)), EXPECT_THROW_MSG(
fmt::format_error, (void)fmt::format(runtime("{:.2}"), std::chrono::seconds(42)),
"precision not allowed for this argument type"); fmt::format_error, "precision not allowed for this argument type");
EXPECT_EQ("1ms", fmt::format("{:.0}", dms(1.234))); EXPECT_EQ("1ms", fmt::format("{:.0}", dms(1.234)));
EXPECT_EQ("1.2ms", fmt::format("{:.1}", dms(1.234))); EXPECT_EQ("1.2ms", fmt::format("{:.1}", dms(1.234)));
EXPECT_EQ("1.23ms", fmt::format("{:.{}}", dms(1.234), 2)); EXPECT_EQ("1.23ms", fmt::format("{:.{}}", dms(1.234), 2));
@ -493,9 +493,9 @@ TEST(chrono_test, format_simple_q) {
} }
TEST(chrono_test, format_precision_q) { TEST(chrono_test, format_precision_q) {
EXPECT_THROW_MSG((void)fmt::format(runtime("{:.2%Q %q}"), std::chrono::seconds(42)), EXPECT_THROW_MSG(
fmt::format_error, (void)fmt::format(runtime("{:.2%Q %q}"), std::chrono::seconds(42)),
"precision not allowed for this argument type"); fmt::format_error, "precision not allowed for this argument type");
EXPECT_EQ("1.2 ms", fmt::format("{:.1%Q %q}", dms(1.234))); EXPECT_EQ("1.2 ms", fmt::format("{:.1%Q %q}", dms(1.234)));
EXPECT_EQ("1.23 ms", fmt::format("{:.{}%Q %q}", dms(1.234), 2)); EXPECT_EQ("1.23 ms", fmt::format("{:.{}%Q %q}", dms(1.234), 2));
} }
@ -551,7 +551,7 @@ TEST(chrono_test, special_durations) {
"nan nan nan nan nan:nan nan", "nan nan nan nan nan:nan nan",
fmt::format("{:%I %H %M %S %R %r}", std::chrono::duration<double>(nan))); fmt::format("{:%I %H %M %S %R %r}", std::chrono::duration<double>(nan)));
(void)fmt::format("{:%S}", (void)fmt::format("{:%S}",
std::chrono::duration<float, std::atto>(1.79400457e+31f)); std::chrono::duration<float, std::atto>(1.79400457e+31f));
EXPECT_EQ(fmt::format("{}", std::chrono::duration<float, std::exa>(1)), EXPECT_EQ(fmt::format("{}", std::chrono::duration<float, std::exa>(1)),
"1Es"); "1Es");
EXPECT_EQ(fmt::format("{}", std::chrono::duration<float, std::atto>(1)), EXPECT_EQ(fmt::format("{}", std::chrono::duration<float, std::atto>(1)),

View File

@ -41,7 +41,8 @@ void test_chrono() {
void test_text_style() { void test_text_style() {
fmt::print(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)"); fmt::print(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)");
(void)fmt::format(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)"); (void)fmt::format(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"),
"rgb(255,20,30)");
fmt::text_style ts = fg(fmt::rgb(255, 20, 30)); fmt::text_style ts = fg(fmt::rgb(255, 20, 30));
std::string out; std::string out;

View File

@ -1,6 +1,5 @@
#include "fmt/format.h" #include "fmt/format.h"
int main(int argc, char** argv) { int main(int argc, char** argv) {
for(int i = 0; i < argc; ++i) for (int i = 0; i < argc; ++i) fmt::print("{}: {}\n", i, argv[i]);
fmt::print("{}: {}\n", i, argv[i]);
} }

View File

@ -471,9 +471,11 @@ TEST(format_test, auto_arg_index) {
EXPECT_THROW_MSG((void)fmt::format(runtime("{}{0}"), 'a', 'b'), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{}{0}"), 'a', 'b'), format_error,
"cannot switch from automatic to manual argument indexing"); "cannot switch from automatic to manual argument indexing");
EXPECT_EQ("1.2", fmt::format("{:.{}}", 1.2345, 2)); EXPECT_EQ("1.2", fmt::format("{:.{}}", 1.2345, 2));
EXPECT_THROW_MSG((void)fmt::format(runtime("{0}:.{}"), 1.2345, 2), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0}:.{}"), 1.2345, 2),
format_error,
"cannot switch from manual to automatic argument indexing"); "cannot switch from manual to automatic argument indexing");
EXPECT_THROW_MSG((void)fmt::format(runtime("{:.{0}}"), 1.2345, 2), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{:.{0}}"), 1.2345, 2),
format_error,
"cannot switch from automatic to manual argument indexing"); "cannot switch from automatic to manual argument indexing");
EXPECT_THROW_MSG((void)fmt::format(runtime("{}")), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{}")), format_error,
"argument not found"); "argument not found");
@ -578,8 +580,9 @@ TEST(format_test, plus_sign) {
"invalid format specifier for char"); "invalid format specifier for char");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:+}"), "abc"), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:+}"), "abc"), format_error,
"format specifier requires numeric argument"); "format specifier requires numeric argument");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:+}"), reinterpret_cast<void*>(0x42)), EXPECT_THROW_MSG(
format_error, "format specifier requires numeric argument"); (void)fmt::format(runtime("{0:+}"), reinterpret_cast<void*>(0x42)),
format_error, "format specifier requires numeric argument");
} }
TEST(format_test, minus_sign) { TEST(format_test, minus_sign) {
@ -602,8 +605,9 @@ TEST(format_test, minus_sign) {
"invalid format specifier for char"); "invalid format specifier for char");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:-}"), "abc"), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:-}"), "abc"), format_error,
"format specifier requires numeric argument"); "format specifier requires numeric argument");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:-}"), reinterpret_cast<void*>(0x42)), EXPECT_THROW_MSG(
format_error, "format specifier requires numeric argument"); (void)fmt::format(runtime("{0:-}"), reinterpret_cast<void*>(0x42)),
format_error, "format specifier requires numeric argument");
} }
TEST(format_test, space_sign) { TEST(format_test, space_sign) {
@ -626,8 +630,9 @@ TEST(format_test, space_sign) {
"invalid format specifier for char"); "invalid format specifier for char");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0: }"), "abc"), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0: }"), "abc"), format_error,
"format specifier requires numeric argument"); "format specifier requires numeric argument");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0: }"), reinterpret_cast<void*>(0x42)), EXPECT_THROW_MSG(
format_error, "format specifier requires numeric argument"); (void)fmt::format(runtime("{0: }"), reinterpret_cast<void*>(0x42)),
format_error, "format specifier requires numeric argument");
} }
TEST(format_test, hash_flag) { TEST(format_test, hash_flag) {
@ -676,8 +681,9 @@ TEST(format_test, hash_flag) {
"invalid format specifier for char"); "invalid format specifier for char");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:#}"), "abc"), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:#}"), "abc"), format_error,
"format specifier requires numeric argument"); "format specifier requires numeric argument");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:#}"), reinterpret_cast<void*>(0x42)), EXPECT_THROW_MSG(
format_error, "format specifier requires numeric argument"); (void)fmt::format(runtime("{0:#}"), reinterpret_cast<void*>(0x42)),
format_error, "format specifier requires numeric argument");
} }
TEST(format_test, zero_flag) { TEST(format_test, zero_flag) {
@ -908,9 +914,9 @@ TEST(format_test, precision) {
EXPECT_THROW_MSG( EXPECT_THROW_MSG(
(void)fmt::format(runtime("{0:.2f}"), reinterpret_cast<void*>(0xcafe)), (void)fmt::format(runtime("{0:.2f}"), reinterpret_cast<void*>(0xcafe)),
format_error, "precision not allowed for this argument type"); format_error, "precision not allowed for this argument type");
EXPECT_THROW_MSG( EXPECT_THROW_MSG((void)fmt::format(runtime("{:.{}e}"), 42.0,
(void)fmt::format(runtime("{:.{}e}"), 42.0, fmt::detail::max_value<int>()), fmt::detail::max_value<int>()),
format_error, "number is too big"); format_error, "number is too big");
EXPECT_EQ("st", fmt::format("{0:.2}", "str")); EXPECT_EQ("st", fmt::format("{0:.2}", "str"));
} }
@ -970,35 +976,46 @@ TEST(format_test, runtime_precision) {
"precision not allowed for this argument type"); "precision not allowed for this argument type");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}}"), 42u, 2), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}}"), 42u, 2), format_error,
"precision not allowed for this argument type"); "precision not allowed for this argument type");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}f}"), 42u, 2), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}f}"), 42u, 2),
format_error,
"precision not allowed for this argument type"); "precision not allowed for this argument type");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}}"), 42l, 2), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}}"), 42l, 2), format_error,
"precision not allowed for this argument type"); "precision not allowed for this argument type");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}f}"), 42l, 2), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}f}"), 42l, 2),
format_error,
"precision not allowed for this argument type"); "precision not allowed for this argument type");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}}"), 42ul, 2), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}}"), 42ul, 2),
format_error,
"precision not allowed for this argument type"); "precision not allowed for this argument type");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}f}"), 42ul, 2), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}f}"), 42ul, 2),
format_error,
"precision not allowed for this argument type"); "precision not allowed for this argument type");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}}"), 42ll, 2), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}}"), 42ll, 2),
format_error,
"precision not allowed for this argument type"); "precision not allowed for this argument type");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}f}"), 42ll, 2), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}f}"), 42ll, 2),
format_error,
"precision not allowed for this argument type"); "precision not allowed for this argument type");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}}"), 42ull, 2), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}}"), 42ull, 2),
format_error,
"precision not allowed for this argument type"); "precision not allowed for this argument type");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}f}"), 42ull, 2), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}f}"), 42ull, 2),
format_error,
"precision not allowed for this argument type"); "precision not allowed for this argument type");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:3.{1}}"), 'x', 0), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:3.{1}}"), 'x', 0),
format_error,
"precision not allowed for this argument type"); "precision not allowed for this argument type");
EXPECT_EQ("1.2", fmt::format("{0:.{1}}", 1.2345, 2)); EXPECT_EQ("1.2", fmt::format("{0:.{1}}", 1.2345, 2));
EXPECT_EQ("1.2", fmt::format("{1:.{0}}", 2, 1.2345l)); EXPECT_EQ("1.2", fmt::format("{1:.{0}}", 2, 1.2345l));
EXPECT_THROW_MSG( EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}}"),
(void)fmt::format(runtime("{0:.{1}}"), reinterpret_cast<void*>(0xcafe), 2), reinterpret_cast<void*>(0xcafe), 2),
format_error, "precision not allowed for this argument type"); format_error,
EXPECT_THROW_MSG( "precision not allowed for this argument type");
(void)fmt::format(runtime("{0:.{1}f}"), reinterpret_cast<void*>(0xcafe), 2), EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}f}"),
format_error, "precision not allowed for this argument type"); reinterpret_cast<void*>(0xcafe), 2),
format_error,
"precision not allowed for this argument type");
EXPECT_EQ("st", fmt::format("{0:.{1}}", "str", 2)); EXPECT_EQ("st", fmt::format("{0:.{1}}", "str", 2));
} }
@ -1029,8 +1046,8 @@ void check_unknown_types(const T& value, const char* types, const char*) {
if (std::strchr(types, c) || std::strchr(special, c) || !c) continue; if (std::strchr(types, c) || std::strchr(special, c) || !c) continue;
safe_sprintf(format_str, "{0:10%c}", c); safe_sprintf(format_str, "{0:10%c}", c);
const char* message = "invalid type specifier"; const char* message = "invalid type specifier";
EXPECT_THROW_MSG((void)fmt::format(runtime(format_str), value), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime(format_str), value),
message) format_error, message)
<< format_str << " " << message; << format_str << " " << message;
} }
} }
@ -1558,8 +1575,9 @@ TEST(format_test, format_examples) {
fmt::format("int: {0:d}; hex: {0:#x}; oct: {0:#o}", 42)); fmt::format("int: {0:d}; hex: {0:#x}; oct: {0:#o}", 42));
EXPECT_EQ("The answer is 42", fmt::format("The answer is {}", 42)); EXPECT_EQ("The answer is 42", fmt::format("The answer is {}", 42));
EXPECT_THROW_MSG((void)fmt::format(runtime("The answer is {:d}"), "forty-two"), EXPECT_THROW_MSG(
format_error, "invalid type specifier"); (void)fmt::format(runtime("The answer is {:d}"), "forty-two"),
format_error, "invalid type specifier");
EXPECT_WRITE( EXPECT_WRITE(
stdout, fmt::print("{}", std::numeric_limits<double>::infinity()), "inf"); stdout, fmt::print("{}", std::numeric_limits<double>::infinity()), "inf");

View File

@ -15,8 +15,8 @@
#ifdef FMT_MODULE_TEST #ifdef FMT_MODULE_TEST
import fmt; import fmt;
#else #else
#include "fmt/os.h" # include "fmt/os.h"
#endif // FMG_MODULE_TEST #endif // FMG_MODULE_TEST
#include "gmock/gmock.h" #include "gmock/gmock.h"

View File

@ -70,16 +70,16 @@ TEST(ostream_test, format_specs) {
EXPECT_EQ(" def", fmt::format("{0:>5}", test_string("def"))); EXPECT_EQ(" def", fmt::format("{0:>5}", test_string("def")));
EXPECT_EQ(" def ", fmt::format("{0:^5}", test_string("def"))); EXPECT_EQ(" def ", fmt::format("{0:^5}", test_string("def")));
EXPECT_EQ("def**", fmt::format("{0:*<5}", test_string("def"))); EXPECT_EQ("def**", fmt::format("{0:*<5}", test_string("def")));
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:+}"), test_string()), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:+}"), test_string()),
"format specifier requires numeric argument"); format_error, "format specifier requires numeric argument");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:-}"), test_string()), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:-}"), test_string()),
"format specifier requires numeric argument"); format_error, "format specifier requires numeric argument");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0: }"), test_string()), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0: }"), test_string()),
"format specifier requires numeric argument"); format_error, "format specifier requires numeric argument");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:#}"), test_string()), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:#}"), test_string()),
"format specifier requires numeric argument"); format_error, "format specifier requires numeric argument");
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:05}"), test_string()), format_error, EXPECT_THROW_MSG((void)fmt::format(runtime("{0:05}"), test_string()),
"format specifier requires numeric argument"); format_error, "format specifier requires numeric argument");
EXPECT_EQ("test ", fmt::format("{0:13}", test_string("test"))); EXPECT_EQ("test ", fmt::format("{0:13}", test_string("test")));
EXPECT_EQ("test ", fmt::format("{0:{1}}", test_string("test"), 13)); EXPECT_EQ("test ", fmt::format("{0:{1}}", test_string("test"), 13));
EXPECT_EQ("te", fmt::format("{0:.2}", test_string("test"))); EXPECT_EQ("te", fmt::format("{0:.2}", test_string("test")));

View File

@ -5,10 +5,9 @@
// //
// For the license information refer to format.h. // For the license information refer to format.h.
#include "fmt/ranges.h"
#include <vector> #include <vector>
#include "fmt/ranges.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
// call fmt::format from another translation unit to test ODR // call fmt::format from another translation unit to test ODR
@ -16,4 +15,3 @@ TEST(ranges_odr_test, format_vector) {
auto v = std::vector<int>{1, 2, 3, 5, 7, 11}; auto v = std::vector<int>{1, 2, 3, 5, 7, 11};
EXPECT_EQ(fmt::format("{}", v), "[1, 2, 3, 5, 7, 11]"); EXPECT_EQ(fmt::format("{}", v), "[1, 2, 3, 5, 7, 11]");
} }

View File

@ -13,8 +13,8 @@
#ifdef FMT_MODULE_TEST #ifdef FMT_MODULE_TEST
import fmt; import fmt;
#else #else
#include "fmt/os.h" # include "fmt/os.h"
#endif // FMT_MODULE_TEST #endif // FMT_MODULE_TEST
#ifdef _MSC_VER #ifdef _MSC_VER
# define FMT_VSNPRINTF vsprintf_s # define FMT_VSNPRINTF vsprintf_s