diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 4d541c87..fac475be 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -814,8 +814,7 @@ constexpr auto compile_format_string(S format_str) { } template ::value || - detail::is_compiled_string::value)> + FMT_ENABLE_IF(detail::is_compiled_string::value)> constexpr auto compile(S format_str) { constexpr basic_string_view str = format_str; if constexpr (str.size() == 0) { @@ -834,27 +833,11 @@ constexpr auto compile(S format_str) -> detail::compiled_format { return detail::compiled_format(to_string_view(format_str)); } #endif // __cpp_if_constexpr - -// Compiles the format string which must be a string literal. -template -auto compile(const Char (&format_str)[N]) - -> detail::compiled_format { - return detail::compiled_format( - basic_string_view(format_str, N - 1)); -} } // namespace detail -// DEPRECATED! use FMT_COMPILE instead. -template -FMT_DEPRECATED auto compile(const Args&... args) - -> decltype(detail::compile(args...)) { - return detail::compile(args...); -} - FMT_MODULE_EXPORT_BEGIN -#if FMT_USE_CONSTEXPR -# ifdef __cpp_if_constexpr +#ifdef __cpp_if_constexpr template ::value)> -std::basic_string format(const CompiledFormat& cf, const Args&... args) { - basic_memory_buffer buffer; - using context = buffer_context; - detail::cf::vformat_to(detail::buffer_appender(buffer), cf, - make_format_args(args...)); - return to_string(buffer); -} +#endif // __cpp_if_constexpr template ::value)> @@ -919,17 +889,6 @@ FMT_INLINE std::basic_string format(const S&, #endif } -template ::value)> -constexpr OutputIt format_to(OutputIt out, const CompiledFormat& cf, - const Args&... args) { - using char_type = typename CompiledFormat::char_type; - using context = format_context_t; - return detail::cf::vformat_to(out, cf, - make_format_args(args...)); -} - template ::value)> FMT_CONSTEXPR OutputIt format_to(OutputIt out, const S&, Args&&... args) { @@ -948,35 +907,19 @@ FMT_CONSTEXPR OutputIt format_to(OutputIt out, const S&, Args&&... args) { #endif } -template -auto format_to_n(OutputIt out, size_t n, const CompiledFormat& cf, - const Args&... args) -> - typename std::enable_if< - detail::is_output_iterator::value && - std::is_base_of::value, - format_to_n_result>::type { - auto it = - format_to(detail::truncating_iterator(out, n), cf, args...); - return {it.base(), it.count()}; -} - template ::value)> -format_to_n_result format_to_n(OutputIt out, size_t n, const S&, - Args&&... args) { - auto it = format_to(detail::truncating_iterator(out, n), S(), +format_to_n_result format_to_n(OutputIt out, size_t n, + const S& format_str, Args&&... args) { + auto it = format_to(detail::truncating_iterator(out, n), format_str, std::forward(args)...); return {it.base(), it.count()}; } -template ::value || - detail::is_compiled_string::value)> -size_t formatted_size(const CompiledFormat& cf, const Args&... args) { - return format_to(detail::counting_iterator(), cf, args...).count(); +template ::value)> +size_t formatted_size(const S& format_str, const Args&... args) { + return format_to(detail::counting_iterator(), format_str, args...).count(); } #if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS diff --git a/test/chrono-test.cc b/test/chrono-test.cc index c8cf1478..ee7b4c7a 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -5,77 +5,67 @@ // // For the license information refer to format.h. -#ifndef _CRT_SECURE_NO_WARNINGS -#define _CRT_SECURE_NO_WARNINGS -#endif - #include "fmt/chrono.h" -#include - #include "gtest-extra.h" -std::tm make_tm() { +auto make_tm() -> std::tm { auto time = std::tm(); time.tm_mday = 1; return time; } -std::tm make_hour(int h) { +auto make_hour(int h) -> std::tm { auto time = make_tm(); time.tm_hour = h; return time; } -std::tm make_minute(int m) { +auto make_minute(int m) -> std::tm { auto time = make_tm(); time.tm_min = m; return time; } -std::tm make_second(int s) { +auto make_second(int s) -> std::tm { auto time = make_tm(); time.tm_sec = s; return time; } -std::string format_tm(const std::tm& time, const char* spec, - const std::locale& loc) { - auto& facet = std::use_facet>(loc); - std::ostringstream os; - os.imbue(loc); - facet.put(os, os, ' ', &time, spec, spec + std::strlen(spec)); - return os.str(); -} - -TEST(time_test, Format) { - std::tm tm = std::tm(); +TEST(chrono_test, format_tm) { + auto tm = std::tm(); tm.tm_year = 116; tm.tm_mon = 3; tm.tm_mday = 25; - EXPECT_EQ("The date is 2016-04-25.", - fmt::format("The date is {:%Y-%m-%d}.", tm)); + tm.tm_hour = 11; + tm.tm_min = 22; + tm.tm_sec = 33; + EXPECT_EQ(fmt::format("The date is {:%Y-%m-%d %H:%M:%S}.", tm), + "The date is 2016-04-25 11:22:33."); + EXPECT_EQ(fmt::format(L"The date is {:%Y-%m-%d %H:%M:%S}.", tm), + L"The date is 2016-04-25 11:22:33."); } -TEST(time_test, GrowBuffer) { - std::string s = "{:"; +TEST(chrono_test, grow_buffer) { + auto s = std::string("{:"); for (int i = 0; i < 30; ++i) s += "%c"; s += "}\n"; - std::time_t t = std::time(nullptr); + auto t = std::time(nullptr); fmt::format(s, *std::localtime(&t)); } -TEST(time_test, FormatToEmptyContainer) { - std::string s; +TEST(chrono_test, format_to_empty_container) { auto time = std::tm(); time.tm_sec = 42; + auto s = std::string(); fmt::format_to(std::back_inserter(s), "{:%S}", time); EXPECT_EQ(s, "42"); } -TEST(time_test, EmptyResult) { EXPECT_EQ("", fmt::format("{}", std::tm())); } +TEST(chrono_test, empty_result) { EXPECT_EQ(fmt::format("{}", std::tm()), ""); } -static bool EqualTime(const std::tm& lhs, const std::tm& rhs) { +auto equal(const std::tm& lhs, const std::tm& rhs) -> bool { return lhs.tm_sec == rhs.tm_sec && lhs.tm_min == rhs.tm_min && lhs.tm_hour == rhs.tm_hour && lhs.tm_mday == rhs.tm_mday && lhs.tm_mon == rhs.tm_mon && lhs.tm_year == rhs.tm_year && @@ -83,41 +73,27 @@ static bool EqualTime(const std::tm& lhs, const std::tm& rhs) { lhs.tm_isdst == rhs.tm_isdst; } -TEST(time_test, LocalTime) { - std::time_t t = std::time(nullptr); - std::tm tm = *std::localtime(&t); - EXPECT_TRUE(EqualTime(tm, fmt::localtime(t))); +TEST(chrono_test, localtime) { + auto t = std::time(nullptr); + auto tm = *std::localtime(&t); + EXPECT_TRUE(equal(tm, fmt::localtime(t))); } -TEST(time_test, GMTime) { - std::time_t t = std::time(nullptr); - std::tm tm = *std::gmtime(&t); - EXPECT_TRUE(EqualTime(tm, fmt::gmtime(t))); +TEST(chrono_test, gmtime) { + auto t = std::time(nullptr); + auto tm = *std::gmtime(&t); + EXPECT_TRUE(equal(tm, fmt::gmtime(t))); } -TEST(time_test, FormatTM) { - auto point = std::chrono::system_clock::now(); - std::time_t t = std::chrono::system_clock::to_time_t(point); - std::tm tm = *std::localtime(&t); - char strftime_output[256]; - std::strftime(strftime_output, sizeof(strftime_output), "%Y-%m-%d %H:%M:%S", - &tm); - EXPECT_EQ(strftime_output, fmt::format("{:%Y-%m-%d %H:%M:%S}", tm)); - auto wstrftime_output = std::wstring(); - std::copy(strftime_output, strftime_output + strlen(strftime_output), - std::back_inserter(wstrftime_output)); - EXPECT_EQ(wstrftime_output, fmt::format(L"{:%Y-%m-%d %H:%M:%S}", tm)); -} - -template std::string strftime(TimePoint tp) { - std::time_t t = std::chrono::system_clock::to_time_t(tp); - std::tm tm = *std::localtime(&t); - char output[256]; +template auto strftime(TimePoint tp) -> std::string { + auto t = std::chrono::system_clock::to_time_t(tp); + auto tm = *std::localtime(&t); + char output[256] = {}; std::strftime(output, sizeof(output), "%Y-%m-%d %H:%M:%S", &tm); return output; } -TEST(time_test, TimePoint) { +TEST(chrono_test, time_point) { auto t1 = std::chrono::system_clock::now(); EXPECT_EQ(strftime(t1), fmt::format("{:%Y-%m-%d %H:%M:%S}", t1)); using time_point = @@ -126,16 +102,9 @@ TEST(time_test, TimePoint) { EXPECT_EQ(strftime(t2), fmt::format("{:%Y-%m-%d %H:%M:%S}", t2)); } -#define EXPECT_TIME(spec, time, duration) \ -{ \ - std::locale jp_loc("ja_JP.utf8"); \ - EXPECT_EQ(format_tm(time, spec, jp_loc), \ - fmt::format(loc, "{:" spec "}", duration)); \ -} - #ifndef FMT_STATIC_THOUSANDS_SEPARATOR -TEST(ChronoTest, FormatDefault) { +TEST(chrono_test, format_default) { EXPECT_EQ("42s", fmt::format("{}", std::chrono::seconds(42))); EXPECT_EQ("42as", fmt::format("{}", std::chrono::duration(42))); @@ -177,49 +146,11 @@ TEST(ChronoTest, FormatDefault) { fmt::format("{}", std::chrono::duration>(42))); } -TEST(ChronoTest, FormatWide) { +TEST(chrono_test, format_wide) { EXPECT_EQ(L"42s", fmt::format(L"{}", std::chrono::seconds(42))); - EXPECT_EQ(L"42as", - fmt::format(L"{}", std::chrono::duration(42))); - EXPECT_EQ(L"42fs", - fmt::format(L"{}", std::chrono::duration(42))); - EXPECT_EQ(L"42ps", - fmt::format(L"{}", std::chrono::duration(42))); - EXPECT_EQ(L"42ns", fmt::format(L"{}", std::chrono::nanoseconds(42))); - EXPECT_EQ(L"42\u00B5s", fmt::format(L"{}", std::chrono::microseconds(42))); - EXPECT_EQ(L"42ms", fmt::format(L"{}", std::chrono::milliseconds(42))); - EXPECT_EQ(L"42cs", - fmt::format(L"{}", std::chrono::duration(42))); - EXPECT_EQ(L"42ds", - fmt::format(L"{}", std::chrono::duration(42))); - EXPECT_EQ(L"42s", fmt::format(L"{}", std::chrono::seconds(42))); - EXPECT_EQ(L"42das", - fmt::format(L"{}", std::chrono::duration(42))); - EXPECT_EQ(L"42hs", - fmt::format(L"{}", std::chrono::duration(42))); - EXPECT_EQ(L"42ks", - fmt::format(L"{}", std::chrono::duration(42))); - EXPECT_EQ(L"42Ms", - fmt::format(L"{}", std::chrono::duration(42))); - EXPECT_EQ(L"42Gs", - fmt::format(L"{}", std::chrono::duration(42))); - EXPECT_EQ(L"42Ts", - fmt::format(L"{}", std::chrono::duration(42))); - EXPECT_EQ(L"42Ps", - fmt::format(L"{}", std::chrono::duration(42))); - EXPECT_EQ(L"42Es", - fmt::format(L"{}", std::chrono::duration(42))); - EXPECT_EQ(L"42m", fmt::format(L"{}", std::chrono::minutes(42))); - EXPECT_EQ(L"42h", fmt::format(L"{}", std::chrono::hours(42))); - EXPECT_EQ( - L"42[15]s", - fmt::format(L"{}", std::chrono::duration>(42))); - EXPECT_EQ( - L"42[15/4]s", - fmt::format(L"{}", std::chrono::duration>(42))); } -TEST(ChronoTest, Align) { +TEST(chrono_test, align) { auto s = std::chrono::seconds(42); EXPECT_EQ("42s ", fmt::format("{:5}", s)); EXPECT_EQ("42s ", fmt::format("{:{}}", s, 5)); @@ -235,7 +166,7 @@ TEST(ChronoTest, Align) { fmt::format("{:{}%H:%M:%S}", std::chrono::seconds(12345), 12)); } -TEST(ChronoTest, FormatSpecs) { +TEST(chrono_test, format_specs) { EXPECT_EQ("%", fmt::format("{:%%}", std::chrono::seconds(0))); EXPECT_EQ("\n", fmt::format("{:%n}", std::chrono::seconds(0))); EXPECT_EQ("\t", fmt::format("{:%t}", std::chrono::seconds(0))); @@ -264,7 +195,7 @@ TEST(ChronoTest, FormatSpecs) { EXPECT_EQ("s", fmt::format("{:%q}", std::chrono::seconds(12345))); } -TEST(ChronoTest, InvalidSpecs) { +TEST(chrono_test, invalid_specs) { auto sec = std::chrono::seconds(0); EXPECT_THROW_MSG(fmt::format(+"{:%a}", sec), fmt::format_error, "no date"); EXPECT_THROW_MSG(fmt::format(+"{:%A}", sec), fmt::format_error, "no date"); @@ -288,10 +219,26 @@ TEST(ChronoTest, InvalidSpecs) { "invalid format"); } -TEST(ChronoTest, Locale) { - const char* loc_name = "ja_JP.utf8"; +auto format_tm(const std::tm& time, fmt::string_view spec, + const std::locale& loc) -> std::string { + auto& facet = std::use_facet>(loc); + std::ostringstream os; + os.imbue(loc); + facet.put(os, os, ' ', &time, spec.begin(), spec.end()); + return os.str(); +} + +# define EXPECT_TIME(spec, time, duration) \ + { \ + auto jp_loc = std::locale("ja_JP.utf8"); \ + EXPECT_EQ(format_tm(time, spec, jp_loc), \ + fmt::format(loc, "{:" spec "}", duration)); \ + } + +TEST(chrono_test, locale) { + auto loc_name = "ja_JP.utf8"; bool has_locale = false; - std::locale loc; + auto loc = std::locale(); try { loc = std::locale(loc_name); has_locale = true; @@ -314,9 +261,9 @@ TEST(ChronoTest, Locale) { EXPECT_TIME("%p", time, sec); } -typedef std::chrono::duration dms; +using dms = std::chrono::duration; -TEST(ChronoTest, FormatDefaultFP) { +TEST(chrono_test, format_default_fp) { typedef std::chrono::duration fs; EXPECT_EQ("1.234s", fmt::format("{}", fs(1.234))); typedef std::chrono::duration fms; @@ -326,7 +273,7 @@ TEST(ChronoTest, FormatDefaultFP) { EXPECT_EQ("1.234ms", fmt::format("{}", dms(1.234))); } -TEST(ChronoTest, FormatPrecision) { +TEST(chrono_test, format_precision) { EXPECT_THROW_MSG(fmt::format(+"{:.2}", std::chrono::seconds(42)), fmt::format_error, "precision not allowed for this argument type"); @@ -334,7 +281,7 @@ TEST(ChronoTest, FormatPrecision) { EXPECT_EQ("1.23ms", fmt::format("{:.{}}", dms(1.234), 2)); } -TEST(ChronoTest, FormatFullSpecs) { +TEST(chrono_test, format_full_specs) { EXPECT_EQ("1.2ms ", fmt::format("{:6.1}", dms(1.234))); EXPECT_EQ(" 1.23ms", fmt::format("{:>8.{}}", dms(1.234), 2)); EXPECT_EQ(" 1.2ms ", fmt::format("{:^{}.{}}", dms(1.234), 7, 1)); @@ -343,7 +290,7 @@ TEST(ChronoTest, FormatFullSpecs) { EXPECT_EQ("*1.2340ms*", fmt::format("{:*^10.4}", dms(1.234))); } -TEST(ChronoTest, FormatSimpleQq) { +TEST(chrono_test, format_simple_q) { typedef std::chrono::duration fs; EXPECT_EQ("1.234 s", fmt::format("{:%Q %q}", fs(1.234))); typedef std::chrono::duration fms; @@ -353,7 +300,7 @@ TEST(ChronoTest, FormatSimpleQq) { EXPECT_EQ("1.234 ms", fmt::format("{:%Q %q}", dms(1.234))); } -TEST(ChronoTest, FormatPrecisionQq) { +TEST(chrono_test, format_precision_q) { EXPECT_THROW_MSG(fmt::format(+"{:.2%Q %q}", std::chrono::seconds(42)), fmt::format_error, "precision not allowed for this argument type"); @@ -361,7 +308,7 @@ TEST(ChronoTest, FormatPrecisionQq) { EXPECT_EQ("1.23 ms", fmt::format("{:.{}%Q %q}", dms(1.234), 2)); } -TEST(ChronoTest, FormatFullSpecsQq) { +TEST(chrono_test, format_full_specs_q) { EXPECT_EQ("1.2 ms ", fmt::format("{:7.1%Q %q}", dms(1.234))); EXPECT_EQ(" 1.23 ms", fmt::format("{:>8.{}%Q %q}", dms(1.234), 2)); EXPECT_EQ(" 1.2 ms ", fmt::format("{:^{}.{}%Q %q}", dms(1.234), 8, 1)); @@ -370,17 +317,17 @@ TEST(ChronoTest, FormatFullSpecsQq) { EXPECT_EQ("*1.2340 ms*", fmt::format("{:*^11.4%Q %q}", dms(1.234))); } -TEST(ChronoTest, InvalidWidthId) { +TEST(chrono_test, invalid_width_id) { EXPECT_THROW(fmt::format(+"{:{o}", std::chrono::seconds(0)), fmt::format_error); } -TEST(ChronoTest, InvalidColons) { +TEST(chrono_test, invalid_colons) { EXPECT_THROW(fmt::format(+"{0}=:{0::", std::chrono::seconds(0)), fmt::format_error); } -TEST(ChronoTest, NegativeDurations) { +TEST(chrono_test, negative_durations) { EXPECT_EQ("-12345", fmt::format("{:%Q}", std::chrono::seconds(-12345))); EXPECT_EQ("-03:25:45", fmt::format("{:%H:%M:%S}", std::chrono::seconds(-12345))); @@ -395,7 +342,7 @@ TEST(ChronoTest, NegativeDurations) { fmt::format("{:%Q}", std::chrono::duration(min))); } -TEST(ChronoTest, SpecialDurations) { +TEST(chrono_test, special_durations) { EXPECT_EQ( "40.", fmt::format("{:%S}", std::chrono::duration(1e20)).substr(0, 3)); @@ -415,7 +362,7 @@ TEST(ChronoTest, SpecialDurations) { "03:33:20"); } -TEST(ChronoTest, UnsignedDuration) { +TEST(chrono_test, unsigned_duration) { EXPECT_EQ("42s", fmt::format("{}", std::chrono::duration(42))); } diff --git a/test/color-test.cc b/test/color-test.cc index 30738085..ea213e0c 100644 --- a/test/color-test.cc +++ b/test/color-test.cc @@ -7,52 +7,11 @@ #include "fmt/color.h" -#include -#include -#include +#include // std::back_inserter #include "gtest-extra.h" -TEST(ColorsTest, ColorsPrint) { - EXPECT_WRITE(stdout, fmt::print(fg(fmt::rgb(255, 20, 30)), "rgb(255,20,30)"), - "\x1b[38;2;255;020;030mrgb(255,20,30)\x1b[0m"); - EXPECT_WRITE(stdout, fmt::print(fg(fmt::color::blue), "blue"), - "\x1b[38;2;000;000;255mblue\x1b[0m"); - EXPECT_WRITE( - stdout, - fmt::print(fg(fmt::color::blue) | bg(fmt::color::red), "two color"), - "\x1b[38;2;000;000;255m\x1b[48;2;255;000;000mtwo color\x1b[0m"); - EXPECT_WRITE(stdout, fmt::print(fmt::emphasis::bold, "bold"), - "\x1b[1mbold\x1b[0m"); - EXPECT_WRITE(stdout, fmt::print(fmt::emphasis::italic, "italic"), - "\x1b[3mitalic\x1b[0m"); - EXPECT_WRITE(stdout, fmt::print(fmt::emphasis::underline, "underline"), - "\x1b[4munderline\x1b[0m"); - EXPECT_WRITE(stdout, - fmt::print(fmt::emphasis::strikethrough, "strikethrough"), - "\x1b[9mstrikethrough\x1b[0m"); - EXPECT_WRITE( - stdout, - fmt::print(fg(fmt::color::blue) | fmt::emphasis::bold, "blue/bold"), - "\x1b[1m\x1b[38;2;000;000;255mblue/bold\x1b[0m"); - EXPECT_WRITE(stderr, fmt::print(stderr, fmt::emphasis::bold, "bold error"), - "\x1b[1mbold error\x1b[0m"); - EXPECT_WRITE(stderr, fmt::print(stderr, fg(fmt::color::blue), "blue log"), - "\x1b[38;2;000;000;255mblue log\x1b[0m"); - EXPECT_WRITE(stdout, fmt::print(fmt::text_style(), "hi"), "hi"); - EXPECT_WRITE(stdout, fmt::print(fg(fmt::terminal_color::red), "tred"), - "\x1b[31mtred\x1b[0m"); - EXPECT_WRITE(stdout, fmt::print(bg(fmt::terminal_color::cyan), "tcyan"), - "\x1b[46mtcyan\x1b[0m"); - EXPECT_WRITE(stdout, - fmt::print(fg(fmt::terminal_color::bright_green), "tbgreen"), - "\x1b[92mtbgreen\x1b[0m"); - EXPECT_WRITE(stdout, - fmt::print(bg(fmt::terminal_color::bright_magenta), "tbmagenta"), - "\x1b[105mtbmagenta\x1b[0m"); -} - -TEST(ColorsTest, Format) { +TEST(color_test, format) { EXPECT_EQ(fmt::format(fg(fmt::rgb(255, 20, 30)), "rgb(255,20,30)"), "\x1b[38;2;255;020;030mrgb(255,20,30)\x1b[0m"); EXPECT_EQ(fmt::format(fg(fmt::rgb(255, 20, 30)), L"rgb(255,20,30) wide"), @@ -89,11 +48,15 @@ TEST(ColorsTest, Format) { "\x1b[31mfoo\x1b[0m"); } -TEST(ColorsTest, FormatToOutAcceptsTextStyle) { - fmt::text_style ts = fg(fmt::rgb(255, 20, 30)); - std::string out; - fmt::format_to(std::back_inserter(out), ts, "rgb(255,20,30){}{}{}", 1, 2, 3); - +TEST(color_test, format_to) { + auto out = std::string(); + fmt::format_to(std::back_inserter(out), fg(fmt::rgb(255, 20, 30)), + "rgb(255,20,30){}{}{}", 1, 2, 3); EXPECT_EQ(fmt::to_string(out), "\x1b[38;2;255;020;030mrgb(255,20,30)123\x1b[0m"); } + +TEST(color_test, print) { + EXPECT_WRITE(stdout, fmt::print(fg(fmt::rgb(255, 20, 30)), "rgb(255,20,30)"), + "\x1b[38;2;255;020;030mrgb(255,20,30)\x1b[0m"); +} diff --git a/test/compile-test.cc b/test/compile-test.cc index ec8f3a5a..cbdc4613 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -86,54 +86,6 @@ TEST(CompileTest, CompileTimePreparedPartsTypeProvider) { } #endif -TEST(CompileTest, PassStringLiteralFormat) { - const auto prepared = fmt::detail::compile("test {}"); - EXPECT_EQ("test 42", fmt::format(prepared, 42)); - const auto wprepared = fmt::detail::compile(L"test {}"); - EXPECT_EQ(L"test 42", fmt::format(wprepared, 42)); -} - -TEST(CompileTest, FormatToArrayOfChars) { - char buffer[32] = {0}; - const auto prepared = fmt::detail::compile("4{}"); - fmt::format_to(fmt::detail::make_checked(buffer, 32), prepared, 2); - EXPECT_EQ(std::string("42"), buffer); - wchar_t wbuffer[32] = {0}; - const auto wprepared = fmt::detail::compile(L"4{}"); - fmt::format_to(fmt::detail::make_checked(wbuffer, 32), wprepared, 2); - EXPECT_EQ(std::wstring(L"42"), wbuffer); -} - -TEST(CompileTest, FormatToIterator) { - std::string s(2, ' '); - const auto prepared = fmt::detail::compile("4{}"); - fmt::format_to(s.begin(), prepared, 2); - EXPECT_EQ("42", s); - std::wstring ws(2, L' '); - const auto wprepared = fmt::detail::compile(L"4{}"); - fmt::format_to(ws.begin(), wprepared, 2); - EXPECT_EQ(L"42", ws); -} - -TEST(CompileTest, FormatToN) { - char buf[5]; - auto f = fmt::detail::compile("{:10}"); - auto result = fmt::format_to_n(buf, 5, f, 42); - EXPECT_EQ(result.size, 10); - EXPECT_EQ(result.out, buf + 5); - EXPECT_EQ(fmt::string_view(buf, 5), " "); -} - -TEST(CompileTest, FormattedSize) { - auto f = fmt::detail::compile("{:10}"); - EXPECT_EQ(fmt::formatted_size(f, 42), 10); -} - -TEST(CompileTest, MultipleTypes) { - auto f = fmt::detail::compile("{} {}"); - EXPECT_EQ(fmt::format(f, 42, 42), "42 42"); -} - struct test_formattable {}; FMT_BEGIN_NAMESPACE @@ -145,16 +97,6 @@ template <> struct formatter : formatter { }; FMT_END_NAMESPACE -TEST(CompileTest, FormatUserDefinedType) { - auto f = fmt::detail::compile("{}"); - EXPECT_EQ(fmt::format(f, test_formattable()), "foo"); -} - -TEST(CompileTest, EmptyFormatString) { - auto f = fmt::detail::compile<>(""); - EXPECT_EQ(fmt::format(f), ""); -} - TEST(CompileTest, CompileFallback) { // FMT_COMPILE should fallback on runtime formatting when `if constexpr` is // not available.