Simplifying test case.
This commit is contained in:
parent
a504d3f6fc
commit
ba54c9f69a
@ -2474,36 +2474,27 @@ TEST(FormatTest, FormatUTF8Precision) {
|
|||||||
EXPECT_EQ(from_u8str(result), from_u8str(str.substr(0, 5)));
|
EXPECT_EQ(from_u8str(result), from_u8str(str.substr(0, 5)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cpp_decltype_auto
|
struct check_back_appender {};
|
||||||
struct lazy_optional {
|
|
||||||
bool engaged;
|
|
||||||
std::string value;
|
|
||||||
};
|
|
||||||
|
|
||||||
FMT_BEGIN_NAMESPACE
|
FMT_BEGIN_NAMESPACE
|
||||||
template <> struct formatter<lazy_optional> {
|
template <> struct formatter<check_back_appender> {
|
||||||
template <typename ParseContext>
|
template <typename ParseContext>
|
||||||
auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
||||||
return ctx.begin();
|
return ctx.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
auto format(const lazy_optional& opt, Context& ctx) {
|
auto format(check_back_appender, Context& ctx) -> decltype(ctx.out()) {
|
||||||
if (opt.engaged) {
|
// needs to satisfy weakly_incrementable
|
||||||
auto out = format_to(ctx.out(), "Some(");
|
auto out = ctx.out();
|
||||||
out = format_to(out, "{}", opt.value);
|
static_assert(std::is_same<decltype(++out), decltype(out)&>::value);
|
||||||
*out = ')';
|
*out = 'y';
|
||||||
return ++out;
|
return ++out;
|
||||||
} else {
|
|
||||||
return format_to(ctx.out(), "None()");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
FMT_END_NAMESPACE
|
FMT_END_NAMESPACE
|
||||||
|
|
||||||
TEST(FormatTest, BackInsertSlicing) {
|
TEST(FormatTest, BackInsertSlicing) {
|
||||||
EXPECT_EQ(fmt::format("{}", lazy_optional{false, ""}), "None()");
|
EXPECT_EQ(fmt::format("{}", check_back_appender{}), "y");
|
||||||
EXPECT_EQ(fmt::format("{}", lazy_optional{true, "X"}), "Some(X)");
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user