mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-24 03:17:53 +00:00
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:
parent
491ba2dda5
commit
acad8cfab1
@ -28,8 +28,9 @@
|
||||
# endif
|
||||
# if (FMT_HAS_INCLUDE(<fcntl.h>) || defined(__APPLE__) || \
|
||||
defined(__linux__)) && \
|
||||
(!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP))
|
||||
# include <fcntl.h> // for O_RDONLY
|
||||
(!defined(WINAPI_FAMILY) || \
|
||||
(WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP))
|
||||
# include <fcntl.h> // for O_RDONLY
|
||||
# define FMT_USE_FCNTL 1
|
||||
# else
|
||||
# define FMT_USE_FCNTL 0
|
||||
@ -395,10 +396,10 @@ struct ostream_params {
|
||||
|
||||
// Intel has a bug that results in failure to deduce a constructor
|
||||
// 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(detail::buffer_size bs) : buffer_size(bs.value) {}
|
||||
#endif
|
||||
# endif
|
||||
};
|
||||
|
||||
FMT_END_DETAIL_NAMESPACE
|
||||
|
@ -79,7 +79,6 @@ export module fmt;
|
||||
#define FMT_END_DETAIL_NAMESPACE \
|
||||
} \
|
||||
export {
|
||||
|
||||
// all library-provided declarations and definitions
|
||||
// must be in the module purview to be exported
|
||||
#include "fmt/args.h"
|
||||
|
@ -453,9 +453,9 @@ TEST(chrono_test, format_default_fp) {
|
||||
}
|
||||
|
||||
TEST(chrono_test, format_precision) {
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{:.2}"), std::chrono::seconds(42)),
|
||||
fmt::format_error,
|
||||
"precision not allowed for this argument type");
|
||||
EXPECT_THROW_MSG(
|
||||
(void)fmt::format(runtime("{:.2}"), std::chrono::seconds(42)),
|
||||
fmt::format_error, "precision not allowed for this argument type");
|
||||
EXPECT_EQ("1ms", fmt::format("{:.0}", dms(1.234)));
|
||||
EXPECT_EQ("1.2ms", fmt::format("{:.1}", dms(1.234)));
|
||||
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) {
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{:.2%Q %q}"), std::chrono::seconds(42)),
|
||||
fmt::format_error,
|
||||
"precision not allowed for this argument type");
|
||||
EXPECT_THROW_MSG(
|
||||
(void)fmt::format(runtime("{:.2%Q %q}"), std::chrono::seconds(42)),
|
||||
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.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",
|
||||
fmt::format("{:%I %H %M %S %R %r}", std::chrono::duration<double>(nan)));
|
||||
(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)),
|
||||
"1Es");
|
||||
EXPECT_EQ(fmt::format("{}", std::chrono::duration<float, std::atto>(1)),
|
||||
|
@ -41,7 +41,8 @@ void test_chrono() {
|
||||
|
||||
void test_text_style() {
|
||||
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));
|
||||
std::string out;
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "fmt/format.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
for(int i = 0; i < argc; ++i)
|
||||
fmt::print("{}: {}\n", i, argv[i]);
|
||||
for (int i = 0; i < argc; ++i) fmt::print("{}: {}\n", i, argv[i]);
|
||||
}
|
||||
|
@ -471,9 +471,11 @@ TEST(format_test, auto_arg_index) {
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{}{0}"), 'a', 'b'), format_error,
|
||||
"cannot switch from automatic to manual argument indexing");
|
||||
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");
|
||||
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");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{}")), format_error,
|
||||
"argument not found");
|
||||
@ -578,8 +580,9 @@ TEST(format_test, plus_sign) {
|
||||
"invalid format specifier for char");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:+}"), "abc"), format_error,
|
||||
"format specifier requires numeric argument");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:+}"), reinterpret_cast<void*>(0x42)),
|
||||
format_error, "format specifier requires numeric argument");
|
||||
EXPECT_THROW_MSG(
|
||||
(void)fmt::format(runtime("{0:+}"), reinterpret_cast<void*>(0x42)),
|
||||
format_error, "format specifier requires numeric argument");
|
||||
}
|
||||
|
||||
TEST(format_test, minus_sign) {
|
||||
@ -602,8 +605,9 @@ TEST(format_test, minus_sign) {
|
||||
"invalid format specifier for char");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:-}"), "abc"), format_error,
|
||||
"format specifier requires numeric argument");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:-}"), reinterpret_cast<void*>(0x42)),
|
||||
format_error, "format specifier requires numeric argument");
|
||||
EXPECT_THROW_MSG(
|
||||
(void)fmt::format(runtime("{0:-}"), reinterpret_cast<void*>(0x42)),
|
||||
format_error, "format specifier requires numeric argument");
|
||||
}
|
||||
|
||||
TEST(format_test, space_sign) {
|
||||
@ -626,8 +630,9 @@ TEST(format_test, space_sign) {
|
||||
"invalid format specifier for char");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0: }"), "abc"), format_error,
|
||||
"format specifier requires numeric argument");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0: }"), reinterpret_cast<void*>(0x42)),
|
||||
format_error, "format specifier requires numeric argument");
|
||||
EXPECT_THROW_MSG(
|
||||
(void)fmt::format(runtime("{0: }"), reinterpret_cast<void*>(0x42)),
|
||||
format_error, "format specifier requires numeric argument");
|
||||
}
|
||||
|
||||
TEST(format_test, hash_flag) {
|
||||
@ -676,8 +681,9 @@ TEST(format_test, hash_flag) {
|
||||
"invalid format specifier for char");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:#}"), "abc"), format_error,
|
||||
"format specifier requires numeric argument");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:#}"), reinterpret_cast<void*>(0x42)),
|
||||
format_error, "format specifier requires numeric argument");
|
||||
EXPECT_THROW_MSG(
|
||||
(void)fmt::format(runtime("{0:#}"), reinterpret_cast<void*>(0x42)),
|
||||
format_error, "format specifier requires numeric argument");
|
||||
}
|
||||
|
||||
TEST(format_test, zero_flag) {
|
||||
@ -908,9 +914,9 @@ TEST(format_test, precision) {
|
||||
EXPECT_THROW_MSG(
|
||||
(void)fmt::format(runtime("{0:.2f}"), reinterpret_cast<void*>(0xcafe)),
|
||||
format_error, "precision not allowed for this argument type");
|
||||
EXPECT_THROW_MSG(
|
||||
(void)fmt::format(runtime("{:.{}e}"), 42.0, fmt::detail::max_value<int>()),
|
||||
format_error, "number is too big");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{:.{}e}"), 42.0,
|
||||
fmt::detail::max_value<int>()),
|
||||
format_error, "number is too big");
|
||||
|
||||
EXPECT_EQ("st", fmt::format("{0:.2}", "str"));
|
||||
}
|
||||
@ -970,35 +976,46 @@ TEST(format_test, runtime_precision) {
|
||||
"precision not allowed for this argument type");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}}"), 42u, 2), format_error,
|
||||
"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");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}}"), 42l, 2), format_error,
|
||||
"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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
EXPECT_EQ("1.2", fmt::format("{0:.{1}}", 1.2345, 2));
|
||||
EXPECT_EQ("1.2", fmt::format("{1:.{0}}", 2, 1.2345l));
|
||||
|
||||
EXPECT_THROW_MSG(
|
||||
(void)fmt::format(runtime("{0:.{1}}"), reinterpret_cast<void*>(0xcafe), 2),
|
||||
format_error, "precision not allowed for this argument type");
|
||||
EXPECT_THROW_MSG(
|
||||
(void)fmt::format(runtime("{0:.{1}f}"), reinterpret_cast<void*>(0xcafe), 2),
|
||||
format_error, "precision not allowed for this argument type");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}}"),
|
||||
reinterpret_cast<void*>(0xcafe), 2),
|
||||
format_error,
|
||||
"precision not allowed for this argument type");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:.{1}f}"),
|
||||
reinterpret_cast<void*>(0xcafe), 2),
|
||||
format_error,
|
||||
"precision not allowed for this argument type");
|
||||
|
||||
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;
|
||||
safe_sprintf(format_str, "{0:10%c}", c);
|
||||
const char* message = "invalid type specifier";
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime(format_str), value), format_error,
|
||||
message)
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime(format_str), value),
|
||||
format_error, 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));
|
||||
|
||||
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"),
|
||||
format_error, "invalid type specifier");
|
||||
EXPECT_THROW_MSG(
|
||||
(void)fmt::format(runtime("The answer is {:d}"), "forty-two"),
|
||||
format_error, "invalid type specifier");
|
||||
|
||||
EXPECT_WRITE(
|
||||
stdout, fmt::print("{}", std::numeric_limits<double>::infinity()), "inf");
|
||||
|
@ -15,8 +15,8 @@
|
||||
#ifdef FMT_MODULE_TEST
|
||||
import fmt;
|
||||
#else
|
||||
#include "fmt/os.h"
|
||||
#endif // FMG_MODULE_TEST
|
||||
# include "fmt/os.h"
|
||||
#endif // FMG_MODULE_TEST
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
|
@ -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_THROW_MSG((void)fmt::format(runtime("{0:+}"), test_string()), format_error,
|
||||
"format specifier requires numeric argument");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:-}"), test_string()), format_error,
|
||||
"format specifier requires numeric argument");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0: }"), test_string()), format_error,
|
||||
"format specifier requires numeric argument");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:#}"), test_string()), format_error,
|
||||
"format specifier requires numeric argument");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:05}"), test_string()), format_error,
|
||||
"format specifier requires numeric argument");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:+}"), test_string()),
|
||||
format_error, "format specifier requires numeric argument");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:-}"), test_string()),
|
||||
format_error, "format specifier requires numeric argument");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0: }"), test_string()),
|
||||
format_error, "format specifier requires numeric argument");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:#}"), test_string()),
|
||||
format_error, "format specifier requires numeric argument");
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{0:05}"), test_string()),
|
||||
format_error, "format specifier requires numeric argument");
|
||||
EXPECT_EQ("test ", fmt::format("{0:13}", test_string("test")));
|
||||
EXPECT_EQ("test ", fmt::format("{0:{1}}", test_string("test"), 13));
|
||||
EXPECT_EQ("te", fmt::format("{0:.2}", test_string("test")));
|
||||
|
@ -5,10 +5,9 @@
|
||||
//
|
||||
// For the license information refer to format.h.
|
||||
|
||||
#include "fmt/ranges.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "fmt/ranges.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// 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};
|
||||
EXPECT_EQ(fmt::format("{}", v), "[1, 2, 3, 5, 7, 11]");
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,8 @@
|
||||
#ifdef FMT_MODULE_TEST
|
||||
import fmt;
|
||||
#else
|
||||
#include "fmt/os.h"
|
||||
#endif // FMT_MODULE_TEST
|
||||
# include "fmt/os.h"
|
||||
#endif // FMT_MODULE_TEST
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define FMT_VSNPRINTF vsprintf_s
|
||||
|
Loading…
Reference in New Issue
Block a user