From ba54c9f69a9c0d18e5c840ed51fe5dacc44ccc78 Mon Sep 17 00:00:00 2001 From: Barry Revzin Date: Tue, 18 Aug 2020 09:12:52 -0500 Subject: [PATCH] Simplifying test case. --- test/format-test.cc | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/test/format-test.cc b/test/format-test.cc index 274c3b9f..f7a1a9bd 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2474,36 +2474,27 @@ TEST(FormatTest, FormatUTF8Precision) { EXPECT_EQ(from_u8str(result), from_u8str(str.substr(0, 5))); } -#ifdef __cpp_decltype_auto -struct lazy_optional { - bool engaged; - std::string value; -}; +struct check_back_appender {}; FMT_BEGIN_NAMESPACE -template <> struct formatter { +template <> struct formatter { template auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { return ctx.begin(); } template - auto format(const lazy_optional& opt, Context& ctx) { - if (opt.engaged) { - auto out = format_to(ctx.out(), "Some("); - out = format_to(out, "{}", opt.value); - *out = ')'; - return ++out; - } else { - return format_to(ctx.out(), "None()"); - } + auto format(check_back_appender, Context& ctx) -> decltype(ctx.out()) { + // needs to satisfy weakly_incrementable + auto out = ctx.out(); + static_assert(std::is_same::value); + *out = 'y'; + return ++out; } }; FMT_END_NAMESPACE TEST(FormatTest, BackInsertSlicing) { - EXPECT_EQ(fmt::format("{}", lazy_optional{false, ""}), "None()"); - EXPECT_EQ(fmt::format("{}", lazy_optional{true, "X"}), "Some(X)"); + EXPECT_EQ(fmt::format("{}", check_back_appender{}), "y"); } -#endif